blob: 32a084534f3e08898259d0360a9002acf121e8b1 [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 Smart92494142011-02-16 12:39:44 -05004 * Copyright (C) 2004-2011 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050021/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_transport_fc.h>
31
James Smartda0436e2009-05-22 14:51:39 -040032#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050033#include "lpfc_hw.h"
34#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040036#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_disc.h"
38#include "lpfc_scsi.h"
39#include "lpfc.h"
40#include "lpfc_logmsg.h"
41#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050042#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050043#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050044
45static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
46 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050047static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
48 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010049static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
50static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
51 struct lpfc_nodelist *ndlp, uint8_t retry);
52static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
53 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050054
dea31012005-04-17 16:05:31 -050055static int lpfc_max_els_tries = 3;
56
James Smarte59058c2008-08-24 21:49:00 -040057/**
James Smart3621a712009-04-06 18:47:14 -040058 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040059 * @vport: pointer to a host virtual N_Port data structure.
60 *
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
68 * had happened.
69 *
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
74 *
75 * Return codes
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
78 **/
James Smart858c9f62007-06-17 19:56:39 -050079int
James Smart2e0fef82007-06-17 19:56:36 -050080lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050081{
James Smart2e0fef82007-06-17 19:56:36 -050082 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
83 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050084 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050085
James Smart2e0fef82007-06-17 19:56:36 -050086 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040087 phba->link_state == LPFC_LINK_DOWN ||
88 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050089 return 0;
90
91 /* Read the HBA Host Attention Register */
James Smart9940b972011-03-11 16:06:12 -050092 if (lpfc_readl(phba->HAregaddr, &ha_copy))
93 return 1;
dea31012005-04-17 16:05:31 -050094
95 if (!(ha_copy & HA_LATT))
96 return 0;
97
98 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040099 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
100 "0237 Pending Link Event during "
101 "Discovery: State x%x\n",
102 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500103
104 /* CLEAR_LA should re-enable link attention events and
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300105 * we should then immediately take a LATT event. The
dea31012005-04-17 16:05:31 -0500106 * LATT processing should call lpfc_linkdown() which
107 * will cleanup any left over in-progress discovery
108 * events.
109 */
James Smart2e0fef82007-06-17 19:56:36 -0500110 spin_lock_irq(shost->host_lock);
111 vport->fc_flag |= FC_ABORT_DISCOVERY;
112 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500113
James Smart92d7f7b2007-06-17 19:56:38 -0500114 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500115 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500116
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500117 return 1;
dea31012005-04-17 16:05:31 -0500118}
119
James Smarte59058c2008-08-24 21:49:00 -0400120/**
James Smart3621a712009-04-06 18:47:14 -0400121 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400122 * @vport: pointer to a host virtual N_Port data structure.
123 * @expectRsp: flag indicating whether response is expected.
124 * @cmdSize: size of the ELS command.
125 * @retry: number of retries to the command IOCB when it fails.
126 * @ndlp: pointer to a node-list data structure.
127 * @did: destination identifier.
128 * @elscmd: the ELS command code.
129 *
130 * This routine is used for allocating a lpfc-IOCB data structure from
131 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
132 * passed into the routine for discovery state machine to issue an Extended
133 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
134 * and preparation routine that is used by all the discovery state machine
135 * routines and the ELS command-specific fields will be later set up by
136 * the individual discovery machine routines after calling this routine
137 * allocating and preparing a generic IOCB data structure. It fills in the
138 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
139 * payload and response payload (if expected). The reference count on the
140 * ndlp is incremented by 1 and the reference to the ndlp is put into
141 * context1 of the IOCB data structure for this IOCB to hold the ndlp
142 * reference for the command's callback function to access later.
143 *
144 * Return code
145 * Pointer to the newly allocated/prepared els iocb data structure
146 * NULL - when els iocb data structure allocation/preparation failed
147 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400148struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500149lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
150 uint16_t cmdSize, uint8_t retry,
151 struct lpfc_nodelist *ndlp, uint32_t did,
152 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500153{
James Smart2e0fef82007-06-17 19:56:36 -0500154 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400155 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500156 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
157 struct ulp_bde64 *bpl;
158 IOCB_t *icmd;
159
dea31012005-04-17 16:05:31 -0500160
James Smart2e0fef82007-06-17 19:56:36 -0500161 if (!lpfc_is_link_up(phba))
162 return NULL;
dea31012005-04-17 16:05:31 -0500163
dea31012005-04-17 16:05:31 -0500164 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400165 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500166
167 if (elsiocb == NULL)
168 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500169
James Smart0c287582009-06-10 17:22:56 -0400170 /*
171 * If this command is for fabric controller and HBA running
172 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
173 */
174 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400175 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400176 ((elscmd == ELS_CMD_FLOGI) ||
177 (elscmd == ELS_CMD_FDISC) ||
178 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500179 switch (elscmd) {
180 case ELS_CMD_FLOGI:
James Smartf0d9bcc2010-10-22 11:07:09 -0400181 elsiocb->iocb_flag |=
182 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500183 & LPFC_FIP_ELS_ID_MASK);
184 break;
185 case ELS_CMD_FDISC:
James Smartf0d9bcc2010-10-22 11:07:09 -0400186 elsiocb->iocb_flag |=
187 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500188 & LPFC_FIP_ELS_ID_MASK);
189 break;
190 case ELS_CMD_LOGO:
James Smartf0d9bcc2010-10-22 11:07:09 -0400191 elsiocb->iocb_flag |=
192 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500193 & LPFC_FIP_ELS_ID_MASK);
194 break;
195 }
James Smart0c287582009-06-10 17:22:56 -0400196 else
James Smartc8685952009-11-18 15:39:16 -0500197 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400198
dea31012005-04-17 16:05:31 -0500199 icmd = &elsiocb->iocb;
200
201 /* fill in BDEs for command */
202 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400203 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
204 if (pcmd)
205 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500206 if (!pcmd || !pcmd->virt)
207 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500208
209 INIT_LIST_HEAD(&pcmd->list);
210
211 /* Allocate buffer for response payload */
212 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500213 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500214 if (prsp)
215 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
216 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500217 if (!prsp || !prsp->virt)
218 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500219 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500220 } else
dea31012005-04-17 16:05:31 -0500221 prsp = NULL;
dea31012005-04-17 16:05:31 -0500222
223 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500224 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500225 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500226 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
227 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500228 if (!pbuflist || !pbuflist->virt)
229 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500230
231 INIT_LIST_HEAD(&pbuflist->list);
232
233 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
234 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400235 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart2e0fef82007-06-17 19:56:36 -0500236 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500237 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500238 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500239 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400240 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500241 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500242 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500243 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
244 }
dea31012005-04-17 16:05:31 -0500245 icmd->ulpBdeCount = 1;
246 icmd->ulpLe = 1;
247 icmd->ulpClass = CLASS3;
248
James Smart92d7f7b2007-06-17 19:56:38 -0500249 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
250 icmd->un.elsreq64.myID = vport->fc_myDID;
251
252 /* For ELS_REQUEST64_CR, use the VPI by default */
James Smart6d368e52011-05-24 11:44:12 -0400253 icmd->ulpContext = phba->vpi_ids[vport->vpi];
James Smart92d7f7b2007-06-17 19:56:38 -0500254 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500255 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
256 if (elscmd == ELS_CMD_ECHO)
257 icmd->ulpCt_l = 0; /* context = invalid RPI */
258 else
259 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500260 }
261
dea31012005-04-17 16:05:31 -0500262 bpl = (struct ulp_bde64 *) pbuflist->virt;
263 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
264 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
265 bpl->tus.f.bdeSize = cmdSize;
266 bpl->tus.f.bdeFlags = 0;
267 bpl->tus.w = le32_to_cpu(bpl->tus.w);
268
269 if (expectRsp) {
270 bpl++;
271 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
272 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
273 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400274 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500275 bpl->tus.w = le32_to_cpu(bpl->tus.w);
276 }
277
James Smartfa4066b2008-01-11 01:53:27 -0500278 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400279 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500280 if (!elsiocb->context1)
281 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400282 elsiocb->context2 = pcmd;
283 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500284 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500285 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500286 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
287
288 if (prsp) {
289 list_add(&prsp->list, &pcmd->list);
290 }
dea31012005-04-17 16:05:31 -0500291 if (expectRsp) {
292 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400293 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
294 "0116 Xmit ELS command x%x to remote "
295 "NPORT x%x I/O tag: x%x, port state: x%x\n",
296 elscmd, did, elsiocb->iotag,
297 vport->port_state);
dea31012005-04-17 16:05:31 -0500298 } else {
299 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400300 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
301 "0117 Xmit ELS response x%x to remote "
302 "NPORT x%x I/O tag: x%x, size: x%x\n",
303 elscmd, ndlp->nlp_DID, elsiocb->iotag,
304 cmdSize);
dea31012005-04-17 16:05:31 -0500305 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500306 return elsiocb;
dea31012005-04-17 16:05:31 -0500307
James Smartfa4066b2008-01-11 01:53:27 -0500308els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500309 if (expectRsp)
310 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500311 kfree(pbuflist);
312
313els_iocb_free_prsp_exit:
314 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
315 kfree(prsp);
316
317els_iocb_free_pcmb_exit:
318 kfree(pcmd);
319 lpfc_sli_release_iocbq(phba, elsiocb);
320 return NULL;
321}
dea31012005-04-17 16:05:31 -0500322
James Smarte59058c2008-08-24 21:49:00 -0400323/**
James Smart3621a712009-04-06 18:47:14 -0400324 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400325 * @vport: pointer to a host virtual N_Port data structure.
326 *
327 * This routine issues a fabric registration login for a @vport. An
328 * active ndlp node with Fabric_DID must already exist for this @vport.
329 * The routine invokes two mailbox commands to carry out fabric registration
330 * login through the HBA firmware: the first mailbox command requests the
331 * HBA to perform link configuration for the @vport; and the second mailbox
332 * command requests the HBA to perform the actual fabric registration login
333 * with the @vport.
334 *
335 * Return code
336 * 0 - successfully issued fabric registration login for @vport
337 * -ENXIO -- failed to issue fabric registration login for @vport
338 **/
James Smart3772a992009-05-22 14:50:54 -0400339int
James Smart92d7f7b2007-06-17 19:56:38 -0500340lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
341{
342 struct lpfc_hba *phba = vport->phba;
343 LPFC_MBOXQ_t *mbox;
344 struct lpfc_dmabuf *mp;
345 struct lpfc_nodelist *ndlp;
346 struct serv_parm *sp;
347 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400348 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500349
350 sp = &phba->fc_fabparam;
351 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500352 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400353 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500354 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400355 }
James Smart92d7f7b2007-06-17 19:56:38 -0500356
357 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400358 if (!mbox) {
359 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500360 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400361 }
James Smart92d7f7b2007-06-17 19:56:38 -0500362
363 vport->port_state = LPFC_FABRIC_CFG_LINK;
364 lpfc_config_link(phba, mbox);
365 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
366 mbox->vport = vport;
367
James Smart0b727fe2007-10-27 13:37:25 -0400368 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400369 if (rc == MBX_NOT_FINISHED) {
370 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500371 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400372 }
James Smart92d7f7b2007-06-17 19:56:38 -0500373
374 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400375 if (!mbox) {
376 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500377 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400378 }
James Smart40426292010-12-15 17:58:10 -0500379 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
380 ndlp->nlp_rpi);
James Smart98c9ea52007-10-27 13:37:33 -0400381 if (rc) {
382 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500383 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400384 }
James Smart92d7f7b2007-06-17 19:56:38 -0500385
386 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
387 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500388 /* increment the reference count on ndlp to hold reference
389 * for the callback routine.
390 */
James Smart92d7f7b2007-06-17 19:56:38 -0500391 mbox->context2 = lpfc_nlp_get(ndlp);
392
James Smart0b727fe2007-10-27 13:37:25 -0400393 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400394 if (rc == MBX_NOT_FINISHED) {
395 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500396 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400397 }
James Smart92d7f7b2007-06-17 19:56:38 -0500398
399 return 0;
400
401fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500402 /* decrement the reference count on ndlp just incremented
403 * for the failed mbox command.
404 */
James Smart92d7f7b2007-06-17 19:56:38 -0500405 lpfc_nlp_put(ndlp);
406 mp = (struct lpfc_dmabuf *) mbox->context1;
407 lpfc_mbuf_free(phba, mp->virt, mp->phys);
408 kfree(mp);
409fail_free_mbox:
410 mempool_free(mbox, phba->mbox_mem_pool);
411
412fail:
413 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400414 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400415 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500416 return -ENXIO;
417}
418
James Smarte59058c2008-08-24 21:49:00 -0400419/**
James Smart6fb120a2009-05-22 14:52:59 -0400420 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
421 * @vport: pointer to a host virtual N_Port data structure.
422 *
423 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
424 * the @vport. This mailbox command is necessary for FCoE only.
425 *
426 * Return code
427 * 0 - successfully issued REG_VFI for @vport
428 * A failure code otherwise.
429 **/
430static int
431lpfc_issue_reg_vfi(struct lpfc_vport *vport)
432{
433 struct lpfc_hba *phba = vport->phba;
434 LPFC_MBOXQ_t *mboxq;
435 struct lpfc_nodelist *ndlp;
436 struct serv_parm *sp;
437 struct lpfc_dmabuf *dmabuf;
438 int rc = 0;
439
440 sp = &phba->fc_fabparam;
441 ndlp = lpfc_findnode_did(vport, Fabric_DID);
442 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
443 rc = -ENODEV;
444 goto fail;
445 }
446
447 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
448 if (!dmabuf) {
449 rc = -ENOMEM;
450 goto fail;
451 }
452 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
453 if (!dmabuf->virt) {
454 rc = -ENOMEM;
455 goto fail_free_dmabuf;
456 }
James Smart6d368e52011-05-24 11:44:12 -0400457
James Smart6fb120a2009-05-22 14:52:59 -0400458 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
459 if (!mboxq) {
460 rc = -ENOMEM;
461 goto fail_free_coherent;
462 }
463 vport->port_state = LPFC_FABRIC_CFG_LINK;
464 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
465 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
466 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
467 mboxq->vport = vport;
468 mboxq->context1 = dmabuf;
469 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
470 if (rc == MBX_NOT_FINISHED) {
471 rc = -ENXIO;
472 goto fail_free_mbox;
473 }
474 return 0;
475
476fail_free_mbox:
477 mempool_free(mboxq, phba->mbox_mem_pool);
478fail_free_coherent:
479 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
480fail_free_dmabuf:
481 kfree(dmabuf);
482fail:
483 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
484 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
485 "0289 Issue Register VFI failed: Err %d\n", rc);
486 return rc;
487}
488
489/**
James Smart92494142011-02-16 12:39:44 -0500490 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
491 * @vport: pointer to a host virtual N_Port data structure.
492 * @sp: pointer to service parameter data structure.
493 *
494 * This routine is called from FLOGI/FDISC completion handler functions.
495 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
496 * node nodename is changed in the completion service parameter else return
497 * 0. This function also set flag in the vport data structure to delay
498 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
499 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
500 * node nodename is changed in the completion service parameter.
501 *
502 * Return code
503 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
504 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
505 *
506 **/
507static uint8_t
508lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
509 struct serv_parm *sp)
510{
511 uint8_t fabric_param_changed = 0;
512 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
513
514 if ((vport->fc_prevDID != vport->fc_myDID) ||
515 memcmp(&vport->fabric_portname, &sp->portName,
516 sizeof(struct lpfc_name)) ||
517 memcmp(&vport->fabric_nodename, &sp->nodeName,
518 sizeof(struct lpfc_name)))
519 fabric_param_changed = 1;
520
521 /*
522 * Word 1 Bit 31 in common service parameter is overloaded.
523 * Word 1 Bit 31 in FLOGI request is multiple NPort request
524 * Word 1 Bit 31 in FLOGI response is clean address bit
525 *
526 * If fabric parameter is changed and clean address bit is
527 * cleared delay nport discovery if
528 * - vport->fc_prevDID != 0 (not initial discovery) OR
529 * - lpfc_delay_discovery module parameter is set.
530 */
531 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
532 (vport->fc_prevDID || lpfc_delay_discovery)) {
533 spin_lock_irq(shost->host_lock);
534 vport->fc_flag |= FC_DISC_DELAYED;
535 spin_unlock_irq(shost->host_lock);
536 }
537
538 return fabric_param_changed;
539}
540
541
542/**
James Smart3621a712009-04-06 18:47:14 -0400543 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400544 * @vport: pointer to a host virtual N_Port data structure.
545 * @ndlp: pointer to a node-list data structure.
546 * @sp: pointer to service parameter data structure.
547 * @irsp: pointer to the IOCB within the lpfc response IOCB.
548 *
549 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
550 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
551 * port in a fabric topology. It properly sets up the parameters to the @ndlp
552 * from the IOCB response. It also check the newly assigned N_Port ID to the
553 * @vport against the previously assigned N_Port ID. If it is different from
554 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
555 * is invoked on all the remaining nodes with the @vport to unregister the
556 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
557 * is invoked to register login to the fabric.
558 *
559 * Return code
560 * 0 - Success (currently, always return 0)
561 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500562static int
James Smart2e0fef82007-06-17 19:56:36 -0500563lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
564 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500565{
James Smart2e0fef82007-06-17 19:56:36 -0500566 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
567 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500568 struct lpfc_nodelist *np;
569 struct lpfc_nodelist *next_np;
James Smart92494142011-02-16 12:39:44 -0500570 uint8_t fabric_param_changed;
dea31012005-04-17 16:05:31 -0500571
James Smart2e0fef82007-06-17 19:56:36 -0500572 spin_lock_irq(shost->host_lock);
573 vport->fc_flag |= FC_FABRIC;
574 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500575
576 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
577 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
578 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
579
James Smart12265f62010-10-22 11:05:53 -0400580 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500581 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
582
James Smart76a95d72010-11-20 23:11:48 -0500583 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500584 spin_lock_irq(shost->host_lock);
585 vport->fc_flag |= FC_PUBLIC_LOOP;
586 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500587 }
588
James Smart2e0fef82007-06-17 19:56:36 -0500589 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500590 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500591 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500592 ndlp->nlp_class_sup = 0;
593 if (sp->cls1.classValid)
594 ndlp->nlp_class_sup |= FC_COS_CLASS1;
595 if (sp->cls2.classValid)
596 ndlp->nlp_class_sup |= FC_COS_CLASS2;
597 if (sp->cls3.classValid)
598 ndlp->nlp_class_sup |= FC_COS_CLASS3;
599 if (sp->cls4.classValid)
600 ndlp->nlp_class_sup |= FC_COS_CLASS4;
601 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
602 sp->cmn.bbRcvSizeLsb;
James Smart92494142011-02-16 12:39:44 -0500603
604 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
605 memcpy(&vport->fabric_portname, &sp->portName,
606 sizeof(struct lpfc_name));
607 memcpy(&vport->fabric_nodename, &sp->nodeName,
608 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500609 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
610
James Smart92d7f7b2007-06-17 19:56:38 -0500611 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
612 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400613 lpfc_printf_vlog(vport, KERN_WARNING,
614 LOG_ELS | LOG_VPORT,
615 "1816 FLOGI NPIV supported, "
616 "response data 0x%x\n",
617 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500618 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500619 } else {
620 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400621 to call reg_vnpid atleast for the physcial host */
622 lpfc_printf_vlog(vport, KERN_WARNING,
623 LOG_ELS | LOG_VPORT,
624 "1817 Fabric does not support NPIV "
625 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500626 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
627 }
628 }
629
James Smart92494142011-02-16 12:39:44 -0500630 if (fabric_param_changed &&
James Smart92d7f7b2007-06-17 19:56:38 -0500631 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
632
633 /* If our NportID changed, we need to ensure all
634 * remaining NPORTs get unreg_login'ed.
635 */
636 list_for_each_entry_safe(np, next_np,
637 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400638 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500639 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500640 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
641 !(np->nlp_flag & NLP_NPR_ADISC))
642 continue;
643 spin_lock_irq(shost->host_lock);
644 np->nlp_flag &= ~NLP_NPR_ADISC;
645 spin_unlock_irq(shost->host_lock);
646 lpfc_unreg_rpi(vport, np);
647 }
James Smart78730cf2010-04-06 15:06:30 -0400648 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400649
650 if (phba->sli_rev == LPFC_SLI_REV4)
651 lpfc_sli4_unreg_all_rpis(vport);
652
James Smart92d7f7b2007-06-17 19:56:38 -0500653 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
654 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500655 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500656 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500657 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500658 }
James Smartecfd03c2010-02-12 14:41:27 -0500659 /*
660 * If VPI is unreged, driver need to do INIT_VPI
661 * before re-registering
662 */
663 if (phba->sli_rev == LPFC_SLI_REV4) {
664 spin_lock_irq(shost->host_lock);
665 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
666 spin_unlock_irq(shost->host_lock);
667 }
James Smart38b92ef2010-08-04 16:11:39 -0400668 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
669 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
670 /*
671 * Driver needs to re-reg VPI in order for f/w
672 * to update the MAC address.
673 */
James Smart9589b062011-04-16 11:03:17 -0400674 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400675 lpfc_register_new_vport(phba, vport, ndlp);
676 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500677 }
678
James Smart6fb120a2009-05-22 14:52:59 -0400679 if (phba->sli_rev < LPFC_SLI_REV4) {
680 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
681 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
682 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
683 lpfc_register_new_vport(phba, vport, ndlp);
684 else
685 lpfc_issue_fabric_reglogin(vport);
686 } else {
687 ndlp->nlp_type |= NLP_FABRIC;
688 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500689 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
690 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400691 lpfc_start_fdiscs(phba);
692 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500693 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500694 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500695 else
James Smart6fb120a2009-05-22 14:52:59 -0400696 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500697 }
dea31012005-04-17 16:05:31 -0500698 return 0;
dea31012005-04-17 16:05:31 -0500699}
James Smarte59058c2008-08-24 21:49:00 -0400700/**
James Smart3621a712009-04-06 18:47:14 -0400701 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400702 * @vport: pointer to a host virtual N_Port data structure.
703 * @ndlp: pointer to a node-list data structure.
704 * @sp: pointer to service parameter data structure.
705 *
706 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
707 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
708 * in a point-to-point topology. First, the @vport's N_Port Name is compared
709 * with the received N_Port Name: if the @vport's N_Port Name is greater than
710 * the received N_Port Name lexicographically, this node shall assign local
711 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
712 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
713 * this node shall just wait for the remote node to issue PLOGI and assign
714 * N_Port IDs.
715 *
716 * Return code
717 * 0 - Success
718 * -ENXIO - Fail
719 **/
dea31012005-04-17 16:05:31 -0500720static int
James Smart2e0fef82007-06-17 19:56:36 -0500721lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
722 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500723{
James Smart2e0fef82007-06-17 19:56:36 -0500724 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
725 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500726 LPFC_MBOXQ_t *mbox;
727 int rc;
728
James Smart2e0fef82007-06-17 19:56:36 -0500729 spin_lock_irq(shost->host_lock);
730 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
731 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500732
733 phba->fc_edtov = FF_DEF_EDTOV;
734 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500735 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500736 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500737 if (rc >= 0) {
738 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500739 spin_lock_irq(shost->host_lock);
740 vport->fc_flag |= FC_PT2PT_PLOGI;
741 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500742
743 /*
744 * N_Port ID cannot be 0, set our to LocalID the other
745 * side will be RemoteID.
746 */
747
748 /* not equal */
749 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500750 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500751
752 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
753 if (!mbox)
754 goto fail;
755
756 lpfc_config_link(phba, mbox);
757
758 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500759 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400760 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500761 if (rc == MBX_NOT_FINISHED) {
762 mempool_free(mbox, phba->mbox_mem_pool);
763 goto fail;
764 }
James Smarte47c9092008-02-08 18:49:26 -0500765 /* Decrement ndlp reference count indicating that ndlp can be
766 * safely released when other references to it are done.
767 */
James Smart329f9bc2007-04-25 09:53:01 -0400768 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500769
James Smart2e0fef82007-06-17 19:56:36 -0500770 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500771 if (!ndlp) {
772 /*
773 * Cannot find existing Fabric ndlp, so allocate a
774 * new one
775 */
776 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
777 if (!ndlp)
778 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500779 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500780 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
781 ndlp = lpfc_enable_node(vport, ndlp,
782 NLP_STE_UNUSED_NODE);
783 if(!ndlp)
784 goto fail;
dea31012005-04-17 16:05:31 -0500785 }
786
787 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500788 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500789 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500790 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500791 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500792 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
793 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500794 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500795 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500796 } else
797 /* This side will wait for the PLOGI, decrement ndlp reference
798 * count indicating that ndlp can be released when other
799 * references to it are done.
800 */
James Smart329f9bc2007-04-25 09:53:01 -0400801 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500802
James Smart09372822008-01-11 01:52:54 -0500803 /* If we are pt2pt with another NPort, force NPIV off! */
804 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
805
James Smart2e0fef82007-06-17 19:56:36 -0500806 spin_lock_irq(shost->host_lock);
807 vport->fc_flag |= FC_PT2PT;
808 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500809
810 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500811 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500812 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500813fail:
dea31012005-04-17 16:05:31 -0500814 return -ENXIO;
815}
816
James Smarte59058c2008-08-24 21:49:00 -0400817/**
James Smart3621a712009-04-06 18:47:14 -0400818 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400819 * @phba: pointer to lpfc hba data structure.
820 * @cmdiocb: pointer to lpfc command iocb data structure.
821 * @rspiocb: pointer to lpfc response iocb data structure.
822 *
823 * This routine is the top-level completion callback function for issuing
824 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
825 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
826 * retry has been made (either immediately or delayed with lpfc_els_retry()
827 * returning 1), the command IOCB will be released and function returned.
828 * If the retry attempt has been given up (possibly reach the maximum
829 * number of retries), one additional decrement of ndlp reference shall be
830 * invoked before going out after releasing the command IOCB. This will
831 * actually release the remote node (Note, lpfc_els_free_iocb() will also
832 * invoke one decrement of ndlp reference count). If no error reported in
833 * the IOCB status, the command Port ID field is used to determine whether
834 * this is a point-to-point topology or a fabric topology: if the Port ID
835 * field is assigned, it is a fabric topology; otherwise, it is a
836 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
837 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
838 * specific topology completion conditions.
839 **/
dea31012005-04-17 16:05:31 -0500840static void
James Smart329f9bc2007-04-25 09:53:01 -0400841lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
842 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500843{
James Smart2e0fef82007-06-17 19:56:36 -0500844 struct lpfc_vport *vport = cmdiocb->vport;
845 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500846 IOCB_t *irsp = &rspiocb->iocb;
847 struct lpfc_nodelist *ndlp = cmdiocb->context1;
848 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
849 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500850 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500851 int rc;
852
853 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500854 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500855 /* One additional decrement on node reference count to
856 * trigger the release of the node
857 */
James Smart329f9bc2007-04-25 09:53:01 -0400858 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500859 goto out;
860 }
861
James Smart858c9f62007-06-17 19:56:39 -0500862 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
863 "FLOGI cmpl: status:x%x/x%x state:x%x",
864 irsp->ulpStatus, irsp->un.ulpWord[4],
865 vport->port_state);
866
dea31012005-04-17 16:05:31 -0500867 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500868 /*
James Smarta93ff372010-10-22 11:06:08 -0400869 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500870 * due to new FCF discovery
871 */
872 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smartdbb6b3a2010-06-08 18:31:37 -0400873 (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
James Smart9589b062011-04-16 11:03:17 -0400874 !((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
875 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500876 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400877 "2611 FLOGI failed on FCF (x%x), "
878 "status:x%x/x%x, tmo:x%x, perform "
879 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -0400880 phba->fcf.current_rec.fcf_indx,
881 irsp->ulpStatus, irsp->un.ulpWord[4],
882 irsp->ulpTimeout);
James Smart0c9ab6f2010-02-26 14:15:57 -0500883 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -0400884 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
885 if (rc)
886 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500887 }
888
James Smart38b92ef2010-08-04 16:11:39 -0400889 /* FLOGI failure */
890 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
891 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
892 irsp->ulpStatus, irsp->un.ulpWord[4],
893 irsp->ulpTimeout);
894
dea31012005-04-17 16:05:31 -0500895 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500896 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500897 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500898
James Smart76a95d72010-11-20 23:11:48 -0500899 /* FLOGI failure */
900 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
901 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
902 irsp->ulpStatus, irsp->un.ulpWord[4],
903 irsp->ulpTimeout);
904
dea31012005-04-17 16:05:31 -0500905 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500906 spin_lock_irq(shost->host_lock);
907 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
908 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500909
James Smart329f9bc2007-04-25 09:53:01 -0400910 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500911 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
912 * alpa map would take too long otherwise.
913 */
914 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400915 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smart76a95d72010-11-20 23:11:48 -0500916 if ((phba->sli_rev == LPFC_SLI_REV4) &&
917 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
918 (vport->fc_prevDID != vport->fc_myDID))) {
919 if (vport->fc_flag & FC_VFI_REGISTERED)
920 lpfc_sli4_unreg_all_rpis(vport);
921 lpfc_issue_reg_vfi(vport);
922 lpfc_nlp_put(ndlp);
923 goto out;
924 }
dea31012005-04-17 16:05:31 -0500925 }
dea31012005-04-17 16:05:31 -0500926 goto flogifail;
927 }
James Smart695a8142010-01-26 23:08:03 -0500928 spin_lock_irq(shost->host_lock);
929 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400930 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500931 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500932
933 /*
934 * The FLogI succeeded. Sync the data for the CPU before
935 * accessing it.
936 */
937 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
938
939 sp = prsp->virt + sizeof(uint32_t);
940
941 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400942 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200943 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400944 "Data: x%x x%x x%x x%x\n",
945 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
946 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500947
James Smart2e0fef82007-06-17 19:56:36 -0500948 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500949 /*
950 * If Common Service Parameters indicate Nport
951 * we are point to point, if Fport we are Fabric.
952 */
953 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500954 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -0500955 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -0500956 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400957 else {
958 lpfc_printf_vlog(vport, KERN_ERR,
959 LOG_FIP | LOG_ELS,
960 "2831 FLOGI response with cleared Fabric "
961 "bit fcf_index 0x%x "
962 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
963 "Fabric Name "
964 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
965 phba->fcf.current_rec.fcf_indx,
966 phba->fcf.current_rec.switch_name[0],
967 phba->fcf.current_rec.switch_name[1],
968 phba->fcf.current_rec.switch_name[2],
969 phba->fcf.current_rec.switch_name[3],
970 phba->fcf.current_rec.switch_name[4],
971 phba->fcf.current_rec.switch_name[5],
972 phba->fcf.current_rec.switch_name[6],
973 phba->fcf.current_rec.switch_name[7],
974 phba->fcf.current_rec.fabric_name[0],
975 phba->fcf.current_rec.fabric_name[1],
976 phba->fcf.current_rec.fabric_name[2],
977 phba->fcf.current_rec.fabric_name[3],
978 phba->fcf.current_rec.fabric_name[4],
979 phba->fcf.current_rec.fabric_name[5],
980 phba->fcf.current_rec.fabric_name[6],
981 phba->fcf.current_rec.fabric_name[7]);
982 lpfc_nlp_put(ndlp);
983 spin_lock_irq(&phba->hbalock);
984 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400985 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -0400986 spin_unlock_irq(&phba->hbalock);
987 goto out;
988 }
James Smart0c9ab6f2010-02-26 14:15:57 -0500989 if (!rc) {
990 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400991 if (phba->hba_flag & HBA_FIP_SUPPORT)
992 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
993 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400994 "2769 FLOGI to FCF (x%x) "
995 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -0400996 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500997 spin_lock_irq(&phba->hbalock);
998 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400999 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -05001000 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001001 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001002 }
dea31012005-04-17 16:05:31 -05001003 }
1004
1005flogifail:
James Smart329f9bc2007-04-25 09:53:01 -04001006 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001007
James Smart858c9f62007-06-17 19:56:39 -05001008 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001009 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001010 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001011
1012 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001013 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001014 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1015 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
1016 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
1017 (phba->link_state != LPFC_CLEAR_LA)) {
1018 /* If FLOGI failed enable link interrupt. */
1019 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001020 }
dea31012005-04-17 16:05:31 -05001021out:
1022 lpfc_els_free_iocb(phba, cmdiocb);
1023}
1024
James Smarte59058c2008-08-24 21:49:00 -04001025/**
James Smart3621a712009-04-06 18:47:14 -04001026 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001027 * @vport: pointer to a host virtual N_Port data structure.
1028 * @ndlp: pointer to a node-list data structure.
1029 * @retry: number of retries to the command IOCB.
1030 *
1031 * This routine issues a Fabric Login (FLOGI) Request ELS command
1032 * for a @vport. The initiator service parameters are put into the payload
1033 * of the FLOGI Request IOCB and the top-level callback function pointer
1034 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1035 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1036 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1037 *
1038 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1039 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1040 * will be stored into the context1 field of the IOCB for the completion
1041 * callback function to the FLOGI ELS command.
1042 *
1043 * Return code
1044 * 0 - successfully issued flogi iocb for @vport
1045 * 1 - failed to issue flogi iocb for @vport
1046 **/
dea31012005-04-17 16:05:31 -05001047static int
James Smart2e0fef82007-06-17 19:56:36 -05001048lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001049 uint8_t retry)
1050{
James Smart2e0fef82007-06-17 19:56:36 -05001051 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001052 struct serv_parm *sp;
1053 IOCB_t *icmd;
1054 struct lpfc_iocbq *elsiocb;
1055 struct lpfc_sli_ring *pring;
1056 uint8_t *pcmd;
1057 uint16_t cmdsize;
1058 uint32_t tmo;
1059 int rc;
1060
1061 pring = &phba->sli.ring[LPFC_ELS_RING];
1062
James Smart92d7f7b2007-06-17 19:56:38 -05001063 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001064 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1065 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001066
James Smart488d1462006-03-07 15:02:37 -05001067 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001068 return 1;
dea31012005-04-17 16:05:31 -05001069
1070 icmd = &elsiocb->iocb;
1071 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1072
1073 /* For FLOGI request, remainder of payload is service parameters */
1074 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001075 pcmd += sizeof(uint32_t);
1076 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001077 sp = (struct serv_parm *) pcmd;
1078
1079 /* Setup CSPs accordingly for Fabric */
1080 sp->cmn.e_d_tov = 0;
1081 sp->cmn.w2.r_a_tov = 0;
1082 sp->cls1.classValid = 0;
1083 sp->cls2.seqDelivery = 1;
1084 sp->cls3.seqDelivery = 1;
1085 if (sp->cmn.fcphLow < FC_PH3)
1086 sp->cmn.fcphLow = FC_PH3;
1087 if (sp->cmn.fcphHigh < FC_PH3)
1088 sp->cmn.fcphHigh = FC_PH3;
1089
James Smartc31098c2011-04-16 11:03:33 -04001090 if (phba->sli_rev == LPFC_SLI_REV4) {
1091 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1092 LPFC_SLI_INTF_IF_TYPE_0) {
1093 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1094 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1095 /* FLOGI needs to be 3 for WQE FCFI */
1096 /* Set the fcfi to the fcfi we registered with */
1097 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1098 }
James Smart6fb120a2009-05-22 14:52:59 -04001099 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001100 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001101 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1102 icmd->ulpCt_h = 1;
1103 icmd->ulpCt_l = 0;
1104 }
1105
James Smart76a95d72010-11-20 23:11:48 -05001106 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001107 icmd->un.elsreq64.myID = 0;
1108 icmd->un.elsreq64.fl = 1;
1109 }
1110
dea31012005-04-17 16:05:31 -05001111 tmo = phba->fc_ratov;
1112 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001113 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001114 phba->fc_ratov = tmo;
1115
1116 phba->fc_stat.elsXmitFLOGI++;
1117 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001118
1119 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1120 "Issue FLOGI: opt:x%x",
1121 phba->sli3_options, 0, 0);
1122
James Smart92d7f7b2007-06-17 19:56:38 -05001123 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001124 if (rc == IOCB_ERROR) {
1125 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001126 return 1;
dea31012005-04-17 16:05:31 -05001127 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001128 return 0;
dea31012005-04-17 16:05:31 -05001129}
1130
James Smarte59058c2008-08-24 21:49:00 -04001131/**
James Smart3621a712009-04-06 18:47:14 -04001132 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001133 * @phba: pointer to lpfc hba data structure.
1134 *
1135 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1136 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1137 * list and issues an abort IOCB commond on each outstanding IOCB that
1138 * contains a active Fabric_DID ndlp. Note that this function is to issue
1139 * the abort IOCB command on all the outstanding IOCBs, thus when this
1140 * function returns, it does not guarantee all the IOCBs are actually aborted.
1141 *
1142 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001143 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001144 **/
dea31012005-04-17 16:05:31 -05001145int
James Smart2e0fef82007-06-17 19:56:36 -05001146lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001147{
1148 struct lpfc_sli_ring *pring;
1149 struct lpfc_iocbq *iocb, *next_iocb;
1150 struct lpfc_nodelist *ndlp;
1151 IOCB_t *icmd;
1152
1153 /* Abort outstanding I/O on NPort <nlp_DID> */
1154 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001155 "0201 Abort outstanding I/O on NPort x%x\n",
1156 Fabric_DID);
dea31012005-04-17 16:05:31 -05001157
1158 pring = &phba->sli.ring[LPFC_ELS_RING];
1159
1160 /*
1161 * Check the txcmplq for an iocb that matches the nport the driver is
1162 * searching for.
1163 */
James Smart2e0fef82007-06-17 19:56:36 -05001164 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001165 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1166 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001167 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1168 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001169 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001170 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1171 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001172 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001173 }
1174 }
James Smart2e0fef82007-06-17 19:56:36 -05001175 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001176
1177 return 0;
1178}
1179
James Smarte59058c2008-08-24 21:49:00 -04001180/**
James Smart3621a712009-04-06 18:47:14 -04001181 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001182 * @vport: pointer to a host virtual N_Port data structure.
1183 *
1184 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1185 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1186 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1187 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1188 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1189 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1190 * @vport.
1191 *
1192 * Return code
1193 * 0 - failed to issue initial flogi for @vport
1194 * 1 - successfully issued initial flogi for @vport
1195 **/
dea31012005-04-17 16:05:31 -05001196int
James Smart2e0fef82007-06-17 19:56:36 -05001197lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001198{
James Smart2e0fef82007-06-17 19:56:36 -05001199 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001200 struct lpfc_nodelist *ndlp;
1201
James Smart98c9ea52007-10-27 13:37:33 -04001202 vport->port_state = LPFC_FLOGI;
1203 lpfc_set_disctmo(vport);
1204
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001205 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001206 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001207 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001208 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001209 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1210 if (!ndlp)
1211 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001212 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001213 /* Set the node type */
1214 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001215 /* Put ndlp onto node list */
1216 lpfc_enqueue_node(vport, ndlp);
1217 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1218 /* re-setup ndlp without removing from node list */
1219 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1220 if (!ndlp)
1221 return 0;
dea31012005-04-17 16:05:31 -05001222 }
James Smart87af33f2007-10-27 13:37:43 -04001223
James Smart5ac6b302010-10-22 11:05:36 -04001224 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001225 /* This decrement of reference count to node shall kick off
1226 * the release of the node.
1227 */
James Smart329f9bc2007-04-25 09:53:01 -04001228 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001229 return 0;
1230 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001231 return 1;
dea31012005-04-17 16:05:31 -05001232}
1233
James Smarte59058c2008-08-24 21:49:00 -04001234/**
James Smart3621a712009-04-06 18:47:14 -04001235 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001236 * @vport: pointer to a host virtual N_Port data structure.
1237 *
1238 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1239 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1240 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1241 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1242 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1243 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1244 * @vport.
1245 *
1246 * Return code
1247 * 0 - failed to issue initial fdisc for @vport
1248 * 1 - successfully issued initial fdisc for @vport
1249 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001250int
1251lpfc_initial_fdisc(struct lpfc_vport *vport)
1252{
1253 struct lpfc_hba *phba = vport->phba;
1254 struct lpfc_nodelist *ndlp;
1255
1256 /* First look for the Fabric ndlp */
1257 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1258 if (!ndlp) {
1259 /* Cannot find existing Fabric ndlp, so allocate a new one */
1260 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1261 if (!ndlp)
1262 return 0;
1263 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001264 /* Put ndlp onto node list */
1265 lpfc_enqueue_node(vport, ndlp);
1266 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1267 /* re-setup ndlp without removing from node list */
1268 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1269 if (!ndlp)
1270 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001271 }
James Smarte47c9092008-02-08 18:49:26 -05001272
James Smart92d7f7b2007-06-17 19:56:38 -05001273 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001274 /* decrement node reference count to trigger the release of
1275 * the node.
1276 */
James Smart92d7f7b2007-06-17 19:56:38 -05001277 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001278 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001279 }
1280 return 1;
1281}
James Smart87af33f2007-10-27 13:37:43 -04001282
James Smarte59058c2008-08-24 21:49:00 -04001283/**
James Smart3621a712009-04-06 18:47:14 -04001284 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001285 * @vport: pointer to a host virtual N_Port data structure.
1286 *
1287 * This routine checks whether there are more remaining Port Logins
1288 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1289 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1290 * to issue ELS PLOGIs up to the configured discover threads with the
1291 * @vport (@vport->cfg_discovery_threads). The function also decrement
1292 * the @vport's num_disc_node by 1 if it is not already 0.
1293 **/
James Smart87af33f2007-10-27 13:37:43 -04001294void
James Smart2e0fef82007-06-17 19:56:36 -05001295lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001296{
1297 int sentplogi;
1298
James Smart2e0fef82007-06-17 19:56:36 -05001299 if (vport->num_disc_nodes)
1300 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001301
1302 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001303 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1304 "0232 Continue discovery with %d PLOGIs to go "
1305 "Data: x%x x%x x%x\n",
1306 vport->num_disc_nodes, vport->fc_plogi_cnt,
1307 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001308 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001309 if (vport->fc_flag & FC_NLP_MORE)
1310 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1311 sentplogi = lpfc_els_disc_plogi(vport);
1312
dea31012005-04-17 16:05:31 -05001313 return;
1314}
1315
James Smarte59058c2008-08-24 21:49:00 -04001316/**
James Smart3621a712009-04-06 18:47:14 -04001317 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001318 * @phba: pointer to lpfc hba data structure.
1319 * @prsp: pointer to response IOCB payload.
1320 * @ndlp: pointer to a node-list data structure.
1321 *
1322 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1323 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1324 * The following cases are considered N_Port confirmed:
1325 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1326 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1327 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1328 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1329 * 1) if there is a node on vport list other than the @ndlp with the same
1330 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1331 * on that node to release the RPI associated with the node; 2) if there is
1332 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1333 * into, a new node shall be allocated (or activated). In either case, the
1334 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1335 * be released and the new_ndlp shall be put on to the vport node list and
1336 * its pointer returned as the confirmed node.
1337 *
1338 * Note that before the @ndlp got "released", the keepDID from not-matching
1339 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1340 * of the @ndlp. This is because the release of @ndlp is actually to put it
1341 * into an inactive state on the vport node list and the vport node list
1342 * management algorithm does not allow two node with a same DID.
1343 *
1344 * Return code
1345 * pointer to the PLOGI N_Port @ndlp
1346 **/
James Smart488d1462006-03-07 15:02:37 -05001347static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001348lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001349 struct lpfc_nodelist *ndlp)
1350{
James Smart2e0fef82007-06-17 19:56:36 -05001351 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001352 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001353 struct lpfc_rport_data *rdata;
1354 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001355 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001356 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001357 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001358 int put_node;
1359 int put_rport;
James Smart19ca7602010-11-20 23:11:55 -05001360 struct lpfc_node_rrqs rrq;
James Smart488d1462006-03-07 15:02:37 -05001361
James Smart2fb9bd82006-12-02 13:33:57 -05001362 /* Fabric nodes can have the same WWPN so we don't bother searching
1363 * by WWPN. Just return the ndlp that was given to us.
1364 */
1365 if (ndlp->nlp_type & NLP_FABRIC)
1366 return ndlp;
1367
James Smart92d7f7b2007-06-17 19:56:38 -05001368 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001369 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001370
James Smart685f0bf2007-04-25 09:53:08 -04001371 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001372 * we have for that ndlp. If not, we have some work to do.
1373 */
James Smart2e0fef82007-06-17 19:56:36 -05001374 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001375
James Smarte47c9092008-02-08 18:49:26 -05001376 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001377 return ndlp;
James Smart19ca7602010-11-20 23:11:55 -05001378 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
James Smart488d1462006-03-07 15:02:37 -05001379
1380 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001381 rc = memcmp(&ndlp->nlp_portname, name,
1382 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001383 if (!rc)
1384 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001385 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1386 if (!new_ndlp)
1387 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001388 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001389 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001390 rc = memcmp(&ndlp->nlp_portname, name,
1391 sizeof(struct lpfc_name));
1392 if (!rc)
1393 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001394 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1395 NLP_STE_UNUSED_NODE);
1396 if (!new_ndlp)
1397 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001398 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001399 if (phba->sli_rev == LPFC_SLI_REV4)
1400 memcpy(&rrq.xri_bitmap,
1401 &new_ndlp->active_rrqs.xri_bitmap,
1402 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1403 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001404 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001405 if (phba->sli_rev == LPFC_SLI_REV4)
1406 memcpy(&rrq.xri_bitmap,
1407 &new_ndlp->active_rrqs.xri_bitmap,
1408 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1409 }
James Smart488d1462006-03-07 15:02:37 -05001410
James Smart2e0fef82007-06-17 19:56:36 -05001411 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001412 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001413 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001414 if (phba->sli_rev == LPFC_SLI_REV4)
1415 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1416 &ndlp->active_rrqs.xri_bitmap,
1417 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart0ff10d42008-01-11 01:52:36 -05001418
1419 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1420 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1421 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1422
James Smarte47c9092008-02-08 18:49:26 -05001423 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001424 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001425
James Smart2e0fef82007-06-17 19:56:36 -05001426 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001427 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1428 /* The new_ndlp is replacing ndlp totally, so we need
1429 * to put ndlp on UNUSED list and try to free it.
1430 */
James Smart0ff10d42008-01-11 01:52:36 -05001431
1432 /* Fix up the rport accordingly */
1433 rport = ndlp->rport;
1434 if (rport) {
1435 rdata = rport->dd_data;
1436 if (rdata->pnode == ndlp) {
1437 lpfc_nlp_put(ndlp);
1438 ndlp->rport = NULL;
1439 rdata->pnode = lpfc_nlp_get(new_ndlp);
1440 new_ndlp->rport = rport;
1441 }
1442 new_ndlp->nlp_type = ndlp->nlp_type;
1443 }
James Smart58da1ff2008-04-07 10:15:56 -04001444 /* We shall actually free the ndlp with both nlp_DID and
1445 * nlp_portname fields equals 0 to avoid any ndlp on the
1446 * nodelist never to be used.
1447 */
1448 if (ndlp->nlp_DID == 0) {
1449 spin_lock_irq(&phba->ndlp_lock);
1450 NLP_SET_FREE_REQ(ndlp);
1451 spin_unlock_irq(&phba->ndlp_lock);
1452 }
James Smart0ff10d42008-01-11 01:52:36 -05001453
James Smart58da1ff2008-04-07 10:15:56 -04001454 /* Two ndlps cannot have the same did on the nodelist */
1455 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001456 if (phba->sli_rev == LPFC_SLI_REV4)
1457 memcpy(&ndlp->active_rrqs.xri_bitmap,
1458 &rrq.xri_bitmap,
1459 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001460 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001461 }
James Smart92795652006-07-06 15:50:02 -04001462 else {
James Smart2e0fef82007-06-17 19:56:36 -05001463 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001464 /* Two ndlps cannot have the same did */
1465 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001466 if (phba->sli_rev == LPFC_SLI_REV4)
1467 memcpy(&ndlp->active_rrqs.xri_bitmap,
1468 &rrq.xri_bitmap,
1469 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001470 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart38b92ef2010-08-04 16:11:39 -04001471 /* Since we are swapping the ndlp passed in with the new one
1472 * and the did has already been swapped, copy over the
1473 * state and names.
1474 */
1475 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1476 sizeof(struct lpfc_name));
1477 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1478 sizeof(struct lpfc_name));
1479 new_ndlp->nlp_state = ndlp->nlp_state;
1480 /* Fix up the rport accordingly */
1481 rport = ndlp->rport;
1482 if (rport) {
1483 rdata = rport->dd_data;
1484 put_node = rdata->pnode != NULL;
1485 put_rport = ndlp->rport != NULL;
1486 rdata->pnode = NULL;
1487 ndlp->rport = NULL;
1488 if (put_node)
1489 lpfc_nlp_put(ndlp);
1490 if (put_rport)
1491 put_device(&rport->dev);
1492 }
James Smart92795652006-07-06 15:50:02 -04001493 }
James Smart488d1462006-03-07 15:02:37 -05001494 return new_ndlp;
1495}
1496
James Smarte59058c2008-08-24 21:49:00 -04001497/**
James Smart3621a712009-04-06 18:47:14 -04001498 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001499 * @vport: pointer to a host virtual N_Port data structure.
1500 *
1501 * This routine checks whether more Registration State Change
1502 * Notifications (RSCNs) came in while the discovery state machine was in
1503 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1504 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1505 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1506 * handling the RSCNs.
1507 **/
James Smart87af33f2007-10-27 13:37:43 -04001508void
1509lpfc_end_rscn(struct lpfc_vport *vport)
1510{
1511 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1512
1513 if (vport->fc_flag & FC_RSCN_MODE) {
1514 /*
1515 * Check to see if more RSCNs came in while we were
1516 * processing this one.
1517 */
1518 if (vport->fc_rscn_id_cnt ||
1519 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1520 lpfc_els_handle_rscn(vport);
1521 else {
1522 spin_lock_irq(shost->host_lock);
1523 vport->fc_flag &= ~FC_RSCN_MODE;
1524 spin_unlock_irq(shost->host_lock);
1525 }
1526 }
1527}
1528
James Smarte59058c2008-08-24 21:49:00 -04001529/**
James Smart19ca7602010-11-20 23:11:55 -05001530 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1531 * @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 will call the clear rrq function to free the rrq and
1536 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1537 * exist then the clear_rrq is still called because the rrq needs to
1538 * be freed.
1539 **/
1540
1541static void
1542lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1543 struct lpfc_iocbq *rspiocb)
1544{
1545 struct lpfc_vport *vport = cmdiocb->vport;
1546 IOCB_t *irsp;
1547 struct lpfc_nodelist *ndlp;
1548 struct lpfc_node_rrq *rrq;
1549
1550 /* we pass cmdiocb to state machine which needs rspiocb as well */
1551 rrq = cmdiocb->context_un.rrq;
1552 cmdiocb->context_un.rsp_iocb = rspiocb;
1553
1554 irsp = &rspiocb->iocb;
1555 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1556 "RRQ cmpl: status:x%x/x%x did:x%x",
1557 irsp->ulpStatus, irsp->un.ulpWord[4],
1558 irsp->un.elsreq64.remoteID);
1559
1560 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1561 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1562 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1563 "2882 RRQ completes to NPort x%x "
1564 "with no ndlp. Data: x%x x%x x%x\n",
1565 irsp->un.elsreq64.remoteID,
1566 irsp->ulpStatus, irsp->un.ulpWord[4],
1567 irsp->ulpIoTag);
1568 goto out;
1569 }
1570
1571 /* rrq completes to NPort <nlp_DID> */
1572 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1573 "2880 RRQ completes to NPort x%x "
1574 "Data: x%x x%x x%x x%x x%x\n",
1575 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1576 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1577
1578 if (irsp->ulpStatus) {
1579 /* Check for retry */
1580 /* RRQ failed Don't print the vport to vport rjts */
1581 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1582 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1583 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1584 (phba)->pport->cfg_log_verbose & LOG_ELS)
1585 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1586 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1587 ndlp->nlp_DID, irsp->ulpStatus,
1588 irsp->un.ulpWord[4]);
1589 }
1590out:
1591 if (rrq)
1592 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1593 lpfc_els_free_iocb(phba, cmdiocb);
1594 return;
1595}
1596/**
James Smart3621a712009-04-06 18:47:14 -04001597 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001598 * @phba: pointer to lpfc hba data structure.
1599 * @cmdiocb: pointer to lpfc command iocb data structure.
1600 * @rspiocb: pointer to lpfc response iocb data structure.
1601 *
1602 * This routine is the completion callback function for issuing the Port
1603 * Login (PLOGI) command. For PLOGI completion, there must be an active
1604 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001605 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001606 * ignored and command IOCB released. The PLOGI response IOCB status is
1607 * checked for error conditons. If there is error status reported, PLOGI
1608 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1609 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1610 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1611 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1612 * there are additional N_Port nodes with the vport that need to perform
1613 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1614 * PLOGIs.
1615 **/
dea31012005-04-17 16:05:31 -05001616static void
James Smart2e0fef82007-06-17 19:56:36 -05001617lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1618 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001619{
James Smart2e0fef82007-06-17 19:56:36 -05001620 struct lpfc_vport *vport = cmdiocb->vport;
1621 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001622 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001623 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001624 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001625 int disc, rc, did, type;
1626
dea31012005-04-17 16:05:31 -05001627 /* we pass cmdiocb to state machine which needs rspiocb as well */
1628 cmdiocb->context_un.rsp_iocb = rspiocb;
1629
1630 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001631 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1632 "PLOGI cmpl: status:x%x/x%x did:x%x",
1633 irsp->ulpStatus, irsp->un.ulpWord[4],
1634 irsp->un.elsreq64.remoteID);
1635
James Smart2e0fef82007-06-17 19:56:36 -05001636 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001637 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001638 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1639 "0136 PLOGI completes to NPort x%x "
1640 "with no ndlp. Data: x%x x%x x%x\n",
1641 irsp->un.elsreq64.remoteID,
1642 irsp->ulpStatus, irsp->un.ulpWord[4],
1643 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001644 goto out;
James Smarted957682007-06-17 19:56:37 -05001645 }
dea31012005-04-17 16:05:31 -05001646
1647 /* Since ndlp can be freed in the disc state machine, note if this node
1648 * is being used during discovery.
1649 */
James Smart2e0fef82007-06-17 19:56:36 -05001650 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001651 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001652 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001653 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001654 rc = 0;
1655
1656 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001657 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1658 "0102 PLOGI completes to NPort x%x "
1659 "Data: x%x x%x x%x x%x x%x\n",
1660 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1661 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001662 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001663 if (lpfc_els_chk_latt(vport)) {
1664 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001665 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001666 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001667 goto out;
1668 }
1669
1670 /* ndlp could be freed in DSM, save these values now */
1671 type = ndlp->nlp_type;
1672 did = ndlp->nlp_DID;
1673
1674 if (irsp->ulpStatus) {
1675 /* Check for retry */
1676 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1677 /* ELS command is being retried */
1678 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001679 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001680 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001681 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001682 }
1683 goto out;
1684 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001685 /* PLOGI failed Don't print the vport to vport rjts */
1686 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1687 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1688 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1689 (phba)->pport->cfg_log_verbose & LOG_ELS)
1690 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001691 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1692 ndlp->nlp_DID, irsp->ulpStatus,
1693 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001694 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001695 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001696 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001697 else
James Smart2e0fef82007-06-17 19:56:36 -05001698 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001699 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001700 } else {
1701 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001702 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001703 cmdiocb->context2)->list.next,
1704 struct lpfc_dmabuf, list);
1705 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001706 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001707 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001708 }
1709
James Smart2e0fef82007-06-17 19:56:36 -05001710 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001711 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001712 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001713
James Smart2e0fef82007-06-17 19:56:36 -05001714 if (vport->num_disc_nodes == 0) {
1715 spin_lock_irq(shost->host_lock);
1716 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1717 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001718
James Smart2e0fef82007-06-17 19:56:36 -05001719 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001720 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001721 }
1722 }
1723
1724out:
1725 lpfc_els_free_iocb(phba, cmdiocb);
1726 return;
1727}
1728
James Smarte59058c2008-08-24 21:49:00 -04001729/**
James Smart3621a712009-04-06 18:47:14 -04001730 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001731 * @vport: pointer to a host virtual N_Port data structure.
1732 * @did: destination port identifier.
1733 * @retry: number of retries to the command IOCB.
1734 *
1735 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1736 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1737 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1738 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1739 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1740 *
1741 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1742 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1743 * will be stored into the context1 field of the IOCB for the completion
1744 * callback function to the PLOGI ELS command.
1745 *
1746 * Return code
1747 * 0 - Successfully issued a plogi for @vport
1748 * 1 - failed to issue a plogi for @vport
1749 **/
dea31012005-04-17 16:05:31 -05001750int
James Smart2e0fef82007-06-17 19:56:36 -05001751lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001752{
James Smart2e0fef82007-06-17 19:56:36 -05001753 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001754 struct serv_parm *sp;
1755 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001756 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001757 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001758 struct lpfc_sli *psli;
1759 uint8_t *pcmd;
1760 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001761 int ret;
dea31012005-04-17 16:05:31 -05001762
1763 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001764
James Smart98c9ea52007-10-27 13:37:33 -04001765 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001766 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1767 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001768
James Smarte47c9092008-02-08 18:49:26 -05001769 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001770 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001771 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001772 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001773 if (!elsiocb)
1774 return 1;
dea31012005-04-17 16:05:31 -05001775
1776 icmd = &elsiocb->iocb;
1777 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1778
1779 /* For PLOGI request, remainder of payload is service parameters */
1780 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001781 pcmd += sizeof(uint32_t);
1782 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001783 sp = (struct serv_parm *) pcmd;
1784
James Smart5ac6b302010-10-22 11:05:36 -04001785 /*
1786 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1787 * to device on remote loops work.
1788 */
1789 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1790 sp->cmn.altBbCredit = 1;
1791
dea31012005-04-17 16:05:31 -05001792 if (sp->cmn.fcphLow < FC_PH_4_3)
1793 sp->cmn.fcphLow = FC_PH_4_3;
1794
1795 if (sp->cmn.fcphHigh < FC_PH3)
1796 sp->cmn.fcphHigh = FC_PH3;
1797
James Smart858c9f62007-06-17 19:56:39 -05001798 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1799 "Issue PLOGI: did:x%x",
1800 did, 0, 0);
1801
dea31012005-04-17 16:05:31 -05001802 phba->fc_stat.elsXmitPLOGI++;
1803 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001804 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001805
1806 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001807 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001808 return 1;
dea31012005-04-17 16:05:31 -05001809 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001810 return 0;
dea31012005-04-17 16:05:31 -05001811}
1812
James Smarte59058c2008-08-24 21:49:00 -04001813/**
James Smart3621a712009-04-06 18:47:14 -04001814 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001815 * @phba: pointer to lpfc hba data structure.
1816 * @cmdiocb: pointer to lpfc command iocb data structure.
1817 * @rspiocb: pointer to lpfc response iocb data structure.
1818 *
1819 * This routine is the completion callback function for a Process Login
1820 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1821 * status. If there is error status reported, PRLI retry shall be attempted
1822 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1823 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1824 * ndlp to mark the PRLI completion.
1825 **/
dea31012005-04-17 16:05:31 -05001826static void
James Smart2e0fef82007-06-17 19:56:36 -05001827lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1828 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001829{
James Smart2e0fef82007-06-17 19:56:36 -05001830 struct lpfc_vport *vport = cmdiocb->vport;
1831 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001832 IOCB_t *irsp;
1833 struct lpfc_sli *psli;
1834 struct lpfc_nodelist *ndlp;
1835
1836 psli = &phba->sli;
1837 /* we pass cmdiocb to state machine which needs rspiocb as well */
1838 cmdiocb->context_un.rsp_iocb = rspiocb;
1839
1840 irsp = &(rspiocb->iocb);
1841 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001842 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001843 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001844 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001845
James Smart858c9f62007-06-17 19:56:39 -05001846 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1847 "PRLI cmpl: status:x%x/x%x did:x%x",
1848 irsp->ulpStatus, irsp->un.ulpWord[4],
1849 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001850 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001851 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1852 "0103 PRLI completes to NPort x%x "
1853 "Data: x%x x%x x%x x%x\n",
1854 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1855 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001856
James Smart2e0fef82007-06-17 19:56:36 -05001857 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001858 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001859 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001860 goto out;
1861
1862 if (irsp->ulpStatus) {
1863 /* Check for retry */
1864 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1865 /* ELS command is being retried */
1866 goto out;
1867 }
1868 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001869 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1870 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1871 ndlp->nlp_DID, irsp->ulpStatus,
1872 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001873 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001874 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001875 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001876 else
James Smart2e0fef82007-06-17 19:56:36 -05001877 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001878 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001879 } else
dea31012005-04-17 16:05:31 -05001880 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001881 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001882 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001883out:
1884 lpfc_els_free_iocb(phba, cmdiocb);
1885 return;
1886}
1887
James Smarte59058c2008-08-24 21:49:00 -04001888/**
James Smart3621a712009-04-06 18:47:14 -04001889 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001890 * @vport: pointer to a host virtual N_Port data structure.
1891 * @ndlp: pointer to a node-list data structure.
1892 * @retry: number of retries to the command IOCB.
1893 *
1894 * This routine issues a Process Login (PRLI) ELS command for the
1895 * @vport. The PRLI service parameters are set up in the payload of the
1896 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1897 * is put to the IOCB completion callback func field before invoking the
1898 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1899 *
1900 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1901 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1902 * will be stored into the context1 field of the IOCB for the completion
1903 * callback function to the PRLI ELS command.
1904 *
1905 * Return code
1906 * 0 - successfully issued prli iocb command for @vport
1907 * 1 - failed to issue prli iocb command for @vport
1908 **/
dea31012005-04-17 16:05:31 -05001909int
James Smart2e0fef82007-06-17 19:56:36 -05001910lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001911 uint8_t retry)
1912{
James Smart2e0fef82007-06-17 19:56:36 -05001913 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1914 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001915 PRLI *npr;
1916 IOCB_t *icmd;
1917 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001918 uint8_t *pcmd;
1919 uint16_t cmdsize;
1920
James Smart92d7f7b2007-06-17 19:56:38 -05001921 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001922 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1923 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001924 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001925 return 1;
dea31012005-04-17 16:05:31 -05001926
1927 icmd = &elsiocb->iocb;
1928 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1929
1930 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001931 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001932 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001933 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001934
1935 /* For PRLI, remainder of payload is PRLI parameter page */
1936 npr = (PRLI *) pcmd;
1937 /*
1938 * If our firmware version is 3.20 or later,
1939 * set the following bits for FC-TAPE support.
1940 */
1941 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1942 npr->ConfmComplAllowed = 1;
1943 npr->Retry = 1;
1944 npr->TaskRetryIdReq = 1;
1945 }
1946 npr->estabImagePair = 1;
1947 npr->readXferRdyDis = 1;
1948
1949 /* For FCP support */
1950 npr->prliType = PRLI_FCP_TYPE;
1951 npr->initiatorFunc = 1;
1952
James Smart858c9f62007-06-17 19:56:39 -05001953 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1954 "Issue PRLI: did:x%x",
1955 ndlp->nlp_DID, 0, 0);
1956
dea31012005-04-17 16:05:31 -05001957 phba->fc_stat.elsXmitPRLI++;
1958 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001959 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001960 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001961 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001962 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1963 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001964 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001965 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001966 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001967 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001968 return 1;
dea31012005-04-17 16:05:31 -05001969 }
James Smart2e0fef82007-06-17 19:56:36 -05001970 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001971 return 0;
dea31012005-04-17 16:05:31 -05001972}
1973
James Smarte59058c2008-08-24 21:49:00 -04001974/**
James Smart3621a712009-04-06 18:47:14 -04001975 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001976 * @vport: pointer to a host virtual N_Port data structure.
1977 *
1978 * This routine performs Registration State Change Notification (RSCN)
1979 * discovery for a @vport. If the @vport's node port recovery count is not
1980 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1981 * the nodes that need recovery. If none of the PLOGI were needed through
1982 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1983 * invoked to check and handle possible more RSCN came in during the period
1984 * of processing the current ones.
1985 **/
1986static void
1987lpfc_rscn_disc(struct lpfc_vport *vport)
1988{
1989 lpfc_can_disctmo(vport);
1990
1991 /* RSCN discovery */
1992 /* go thru NPR nodes and issue ELS PLOGIs */
1993 if (vport->fc_npr_cnt)
1994 if (lpfc_els_disc_plogi(vport))
1995 return;
1996
1997 lpfc_end_rscn(vport);
1998}
1999
2000/**
James Smart3621a712009-04-06 18:47:14 -04002001 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002002 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2003 *
2004 * This function is called when the final ADISC is completed during discovery.
2005 * This function handles clearing link attention or issuing reg_vpi depending
2006 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2007 * discovery.
2008 * This function is called with no locks held.
2009 **/
2010static void
2011lpfc_adisc_done(struct lpfc_vport *vport)
2012{
2013 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2014 struct lpfc_hba *phba = vport->phba;
2015
2016 /*
2017 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2018 * and continue discovery.
2019 */
2020 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002021 !(vport->fc_flag & FC_RSCN_MODE) &&
2022 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04002023 lpfc_issue_reg_vpi(phba, vport);
2024 return;
2025 }
2026 /*
2027 * For SLI2, we need to set port_state to READY
2028 * and continue discovery.
2029 */
2030 if (vport->port_state < LPFC_VPORT_READY) {
2031 /* If we get here, there is nothing to ADISC */
2032 if (vport->port_type == LPFC_PHYSICAL_PORT)
2033 lpfc_issue_clear_la(phba, vport);
2034 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2035 vport->num_disc_nodes = 0;
2036 /* go thru NPR list, issue ELS PLOGIs */
2037 if (vport->fc_npr_cnt)
2038 lpfc_els_disc_plogi(vport);
2039 if (!vport->num_disc_nodes) {
2040 spin_lock_irq(shost->host_lock);
2041 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2042 spin_unlock_irq(shost->host_lock);
2043 lpfc_can_disctmo(vport);
2044 lpfc_end_rscn(vport);
2045 }
2046 }
2047 vport->port_state = LPFC_VPORT_READY;
2048 } else
2049 lpfc_rscn_disc(vport);
2050}
2051
2052/**
James Smart3621a712009-04-06 18:47:14 -04002053 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002054 * @vport: pointer to a host virtual N_Port data structure.
2055 *
2056 * This routine determines whether there are more ndlps on a @vport
2057 * node list need to have Address Discover (ADISC) issued. If so, it will
2058 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2059 * remaining nodes which need to have ADISC sent.
2060 **/
James Smart0ff10d42008-01-11 01:52:36 -05002061void
James Smart2e0fef82007-06-17 19:56:36 -05002062lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002063{
2064 int sentadisc;
2065
James Smart2e0fef82007-06-17 19:56:36 -05002066 if (vport->num_disc_nodes)
2067 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002068 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002069 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2070 "0210 Continue discovery with %d ADISCs to go "
2071 "Data: x%x x%x x%x\n",
2072 vport->num_disc_nodes, vport->fc_adisc_cnt,
2073 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002074 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002075 if (vport->fc_flag & FC_NLP_MORE) {
2076 lpfc_set_disctmo(vport);
2077 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2078 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002079 }
James Smart90160e02008-08-24 21:49:45 -04002080 if (!vport->num_disc_nodes)
2081 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002082 return;
2083}
2084
James Smarte59058c2008-08-24 21:49:00 -04002085/**
James Smart3621a712009-04-06 18:47:14 -04002086 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002087 * @phba: pointer to lpfc hba data structure.
2088 * @cmdiocb: pointer to lpfc command iocb data structure.
2089 * @rspiocb: pointer to lpfc response iocb data structure.
2090 *
2091 * This routine is the completion function for issuing the Address Discover
2092 * (ADISC) command. It first checks to see whether link went down during
2093 * the discovery process. If so, the node will be marked as node port
2094 * recovery for issuing discover IOCB by the link attention handler and
2095 * exit. Otherwise, the response status is checked. If error was reported
2096 * in the response status, the ADISC command shall be retried by invoking
2097 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2098 * the response status, the state machine is invoked to set transition
2099 * with respect to NLP_EVT_CMPL_ADISC event.
2100 **/
dea31012005-04-17 16:05:31 -05002101static void
James Smart2e0fef82007-06-17 19:56:36 -05002102lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2103 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002104{
James Smart2e0fef82007-06-17 19:56:36 -05002105 struct lpfc_vport *vport = cmdiocb->vport;
2106 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002107 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002108 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002109 int disc;
dea31012005-04-17 16:05:31 -05002110
2111 /* we pass cmdiocb to state machine which needs rspiocb as well */
2112 cmdiocb->context_un.rsp_iocb = rspiocb;
2113
2114 irsp = &(rspiocb->iocb);
2115 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002116
James Smart858c9f62007-06-17 19:56:39 -05002117 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2118 "ADISC cmpl: status:x%x/x%x did:x%x",
2119 irsp->ulpStatus, irsp->un.ulpWord[4],
2120 ndlp->nlp_DID);
2121
dea31012005-04-17 16:05:31 -05002122 /* Since ndlp can be freed in the disc state machine, note if this node
2123 * is being used during discovery.
2124 */
James Smart2e0fef82007-06-17 19:56:36 -05002125 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002126 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002127 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002128 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002129 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002130 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2131 "0104 ADISC completes to NPort x%x "
2132 "Data: x%x x%x x%x x%x x%x\n",
2133 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2134 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002135 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002136 if (lpfc_els_chk_latt(vport)) {
2137 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002138 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002139 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002140 goto out;
2141 }
2142
2143 if (irsp->ulpStatus) {
2144 /* Check for retry */
2145 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2146 /* ELS command is being retried */
2147 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002148 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002149 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002150 spin_unlock_irq(shost->host_lock);
2151 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002152 }
2153 goto out;
2154 }
2155 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002156 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2157 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2158 ndlp->nlp_DID, irsp->ulpStatus,
2159 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002160 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002161 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002162 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002163 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002164 } else
dea31012005-04-17 16:05:31 -05002165 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002166 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002167 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002168
James Smart90160e02008-08-24 21:49:45 -04002169 /* Check to see if there are more ADISCs to be sent */
2170 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002171 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002172out:
2173 lpfc_els_free_iocb(phba, cmdiocb);
2174 return;
2175}
2176
James Smarte59058c2008-08-24 21:49:00 -04002177/**
James Smart3621a712009-04-06 18:47:14 -04002178 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002179 * @vport: pointer to a virtual N_Port data structure.
2180 * @ndlp: pointer to a node-list data structure.
2181 * @retry: number of retries to the command IOCB.
2182 *
2183 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2184 * @vport. It prepares the payload of the ADISC ELS command, updates the
2185 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2186 * to issue the ADISC ELS command.
2187 *
2188 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2189 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2190 * will be stored into the context1 field of the IOCB for the completion
2191 * callback function to the ADISC ELS command.
2192 *
2193 * Return code
2194 * 0 - successfully issued adisc
2195 * 1 - failed to issue adisc
2196 **/
dea31012005-04-17 16:05:31 -05002197int
James Smart2e0fef82007-06-17 19:56:36 -05002198lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002199 uint8_t retry)
2200{
James Smart2e0fef82007-06-17 19:56:36 -05002201 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2202 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002203 ADISC *ap;
2204 IOCB_t *icmd;
2205 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002206 uint8_t *pcmd;
2207 uint16_t cmdsize;
2208
James Smart92d7f7b2007-06-17 19:56:38 -05002209 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002210 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2211 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002212 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002213 return 1;
dea31012005-04-17 16:05:31 -05002214
2215 icmd = &elsiocb->iocb;
2216 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2217
2218 /* For ADISC request, remainder of payload is service parameters */
2219 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002220 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002221
2222 /* Fill in ADISC payload */
2223 ap = (ADISC *) pcmd;
2224 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002225 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2226 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002227 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002228
James Smart858c9f62007-06-17 19:56:39 -05002229 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2230 "Issue ADISC: did:x%x",
2231 ndlp->nlp_DID, 0, 0);
2232
dea31012005-04-17 16:05:31 -05002233 phba->fc_stat.elsXmitADISC++;
2234 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002235 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002236 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002237 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002238 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2239 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002240 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002241 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002242 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002243 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002244 return 1;
dea31012005-04-17 16:05:31 -05002245 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002246 return 0;
dea31012005-04-17 16:05:31 -05002247}
2248
James Smarte59058c2008-08-24 21:49:00 -04002249/**
James Smart3621a712009-04-06 18:47:14 -04002250 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002251 * @phba: pointer to lpfc hba data structure.
2252 * @cmdiocb: pointer to lpfc command iocb data structure.
2253 * @rspiocb: pointer to lpfc response iocb data structure.
2254 *
2255 * This routine is the completion function for issuing the ELS Logout (LOGO)
2256 * command. If no error status was reported from the LOGO response, the
2257 * state machine of the associated ndlp shall be invoked for transition with
2258 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2259 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2260 **/
dea31012005-04-17 16:05:31 -05002261static void
James Smart2e0fef82007-06-17 19:56:36 -05002262lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2263 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002264{
James Smart2e0fef82007-06-17 19:56:36 -05002265 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2266 struct lpfc_vport *vport = ndlp->vport;
2267 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002268 IOCB_t *irsp;
2269 struct lpfc_sli *psli;
James Smart92494142011-02-16 12:39:44 -05002270 struct lpfcMboxq *mbox;
dea31012005-04-17 16:05:31 -05002271
2272 psli = &phba->sli;
2273 /* we pass cmdiocb to state machine which needs rspiocb as well */
2274 cmdiocb->context_un.rsp_iocb = rspiocb;
2275
2276 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002277 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002278 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002279 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002280
James Smart858c9f62007-06-17 19:56:39 -05002281 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2282 "LOGO cmpl: status:x%x/x%x did:x%x",
2283 irsp->ulpStatus, irsp->un.ulpWord[4],
2284 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002285 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002286 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2287 "0105 LOGO completes to NPort x%x "
2288 "Data: x%x x%x x%x x%x\n",
2289 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2290 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002291 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002292 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002293 goto out;
2294
James Smart92d7f7b2007-06-17 19:56:38 -05002295 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2296 /* NLP_EVT_DEVICE_RM should unregister the RPI
2297 * which should abort all outstanding IOs.
2298 */
2299 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2300 NLP_EVT_DEVICE_RM);
2301 goto out;
2302 }
2303
dea31012005-04-17 16:05:31 -05002304 if (irsp->ulpStatus) {
2305 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002306 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002307 /* ELS command is being retried */
2308 goto out;
dea31012005-04-17 16:05:31 -05002309 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002310 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2311 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2312 ndlp->nlp_DID, irsp->ulpStatus,
2313 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002314 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002315 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002316 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002317 else
James Smart2e0fef82007-06-17 19:56:36 -05002318 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002319 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002320 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002321 /* Good status, call state machine.
2322 * This will unregister the rpi if needed.
2323 */
James Smart2e0fef82007-06-17 19:56:36 -05002324 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002325 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002326out:
2327 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002328 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2329 if ((vport->fc_flag & FC_PT2PT) &&
2330 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2331 phba->pport->fc_myDID = 0;
2332 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2333 if (mbox) {
2334 lpfc_config_link(phba, mbox);
2335 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2336 mbox->vport = vport;
2337 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2338 MBX_NOT_FINISHED) {
2339 mempool_free(mbox, phba->mbox_mem_pool);
2340 }
2341 }
2342 }
dea31012005-04-17 16:05:31 -05002343 return;
2344}
2345
James Smarte59058c2008-08-24 21:49:00 -04002346/**
James Smart3621a712009-04-06 18:47:14 -04002347 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002348 * @vport: pointer to a virtual N_Port data structure.
2349 * @ndlp: pointer to a node-list data structure.
2350 * @retry: number of retries to the command IOCB.
2351 *
2352 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2353 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2354 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2355 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2356 *
2357 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2358 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2359 * will be stored into the context1 field of the IOCB for the completion
2360 * callback function to the LOGO ELS command.
2361 *
2362 * Return code
2363 * 0 - successfully issued logo
2364 * 1 - failed to issue logo
2365 **/
dea31012005-04-17 16:05:31 -05002366int
James Smart2e0fef82007-06-17 19:56:36 -05002367lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002368 uint8_t retry)
2369{
James Smart2e0fef82007-06-17 19:56:36 -05002370 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2371 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002372 IOCB_t *icmd;
2373 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002374 uint8_t *pcmd;
2375 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002376 int rc;
dea31012005-04-17 16:05:31 -05002377
James Smart98c9ea52007-10-27 13:37:33 -04002378 spin_lock_irq(shost->host_lock);
2379 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2380 spin_unlock_irq(shost->host_lock);
2381 return 0;
2382 }
2383 spin_unlock_irq(shost->host_lock);
2384
James Smart92d7f7b2007-06-17 19:56:38 -05002385 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002386 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2387 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002388 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002389 return 1;
dea31012005-04-17 16:05:31 -05002390
2391 icmd = &elsiocb->iocb;
2392 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2393 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002394 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002395
2396 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002397 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002398 pcmd += sizeof(uint32_t);
2399 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002400
James Smart858c9f62007-06-17 19:56:39 -05002401 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2402 "Issue LOGO: did:x%x",
2403 ndlp->nlp_DID, 0, 0);
2404
dea31012005-04-17 16:05:31 -05002405 phba->fc_stat.elsXmitLOGO++;
2406 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002407 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002408 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002409 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002410 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002411
2412 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002413 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002414 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002415 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002416 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002417 return 1;
dea31012005-04-17 16:05:31 -05002418 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002419 return 0;
dea31012005-04-17 16:05:31 -05002420}
2421
James Smarte59058c2008-08-24 21:49:00 -04002422/**
James Smart3621a712009-04-06 18:47:14 -04002423 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002424 * @phba: pointer to lpfc hba data structure.
2425 * @cmdiocb: pointer to lpfc command iocb data structure.
2426 * @rspiocb: pointer to lpfc response iocb data structure.
2427 *
2428 * This routine is a generic completion callback function for ELS commands.
2429 * Specifically, it is the callback function which does not need to perform
2430 * any command specific operations. It is currently used by the ELS command
2431 * issuing routines for the ELS State Change Request (SCR),
2432 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2433 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2434 * certain debug loggings, this callback function simply invokes the
2435 * lpfc_els_chk_latt() routine to check whether link went down during the
2436 * discovery process.
2437 **/
dea31012005-04-17 16:05:31 -05002438static void
James Smart2e0fef82007-06-17 19:56:36 -05002439lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2440 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002441{
James Smart2e0fef82007-06-17 19:56:36 -05002442 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002443 IOCB_t *irsp;
2444
2445 irsp = &rspiocb->iocb;
2446
James Smart858c9f62007-06-17 19:56:39 -05002447 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2448 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2449 irsp->ulpStatus, irsp->un.ulpWord[4],
2450 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002451 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002452 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2453 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2454 irsp->ulpIoTag, irsp->ulpStatus,
2455 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002456 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002457 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002458 lpfc_els_free_iocb(phba, cmdiocb);
2459 return;
2460}
2461
James Smarte59058c2008-08-24 21:49:00 -04002462/**
James Smart3621a712009-04-06 18:47:14 -04002463 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002464 * @vport: pointer to a host virtual N_Port data structure.
2465 * @nportid: N_Port identifier to the remote node.
2466 * @retry: number of retries to the command IOCB.
2467 *
2468 * This routine issues a State Change Request (SCR) to a fabric node
2469 * on a @vport. The remote node @nportid is passed into the function. It
2470 * first search the @vport node list to find the matching ndlp. If no such
2471 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2472 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2473 * routine is invoked to send the SCR IOCB.
2474 *
2475 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2476 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2477 * will be stored into the context1 field of the IOCB for the completion
2478 * callback function to the SCR ELS command.
2479 *
2480 * Return code
2481 * 0 - Successfully issued scr command
2482 * 1 - Failed to issue scr command
2483 **/
dea31012005-04-17 16:05:31 -05002484int
James Smart2e0fef82007-06-17 19:56:36 -05002485lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002486{
James Smart2e0fef82007-06-17 19:56:36 -05002487 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002488 IOCB_t *icmd;
2489 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002490 struct lpfc_sli *psli;
2491 uint8_t *pcmd;
2492 uint16_t cmdsize;
2493 struct lpfc_nodelist *ndlp;
2494
2495 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002496 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002497
James Smarte47c9092008-02-08 18:49:26 -05002498 ndlp = lpfc_findnode_did(vport, nportid);
2499 if (!ndlp) {
2500 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2501 if (!ndlp)
2502 return 1;
2503 lpfc_nlp_init(vport, ndlp, nportid);
2504 lpfc_enqueue_node(vport, ndlp);
2505 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2506 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2507 if (!ndlp)
2508 return 1;
2509 }
dea31012005-04-17 16:05:31 -05002510
James Smart2e0fef82007-06-17 19:56:36 -05002511 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2512 ndlp->nlp_DID, ELS_CMD_SCR);
2513
James Smart488d1462006-03-07 15:02:37 -05002514 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002515 /* This will trigger the release of the node just
2516 * allocated
2517 */
James Smart329f9bc2007-04-25 09:53:01 -04002518 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002519 return 1;
dea31012005-04-17 16:05:31 -05002520 }
2521
2522 icmd = &elsiocb->iocb;
2523 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2524
2525 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002526 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002527
2528 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002529 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002530 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2531
James Smart858c9f62007-06-17 19:56:39 -05002532 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2533 "Issue SCR: did:x%x",
2534 ndlp->nlp_DID, 0, 0);
2535
dea31012005-04-17 16:05:31 -05002536 phba->fc_stat.elsXmitSCR++;
2537 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002538 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2539 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002540 /* The additional lpfc_nlp_put will cause the following
2541 * lpfc_els_free_iocb routine to trigger the rlease of
2542 * the node.
2543 */
James Smart329f9bc2007-04-25 09:53:01 -04002544 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002545 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002546 return 1;
dea31012005-04-17 16:05:31 -05002547 }
James Smartfa4066b2008-01-11 01:53:27 -05002548 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2549 * trigger the release of node.
2550 */
James Smart329f9bc2007-04-25 09:53:01 -04002551 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002552 return 0;
dea31012005-04-17 16:05:31 -05002553}
2554
James Smarte59058c2008-08-24 21:49:00 -04002555/**
James Smart3621a712009-04-06 18:47:14 -04002556 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002557 * @vport: pointer to a host virtual N_Port data structure.
2558 * @nportid: N_Port identifier to the remote node.
2559 * @retry: number of retries to the command IOCB.
2560 *
2561 * This routine issues a Fibre Channel Address Resolution Response
2562 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2563 * is passed into the function. It first search the @vport node list to find
2564 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2565 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2566 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2567 *
2568 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2569 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2570 * will be stored into the context1 field of the IOCB for the completion
2571 * callback function to the PARPR ELS command.
2572 *
2573 * Return code
2574 * 0 - Successfully issued farpr command
2575 * 1 - Failed to issue farpr command
2576 **/
dea31012005-04-17 16:05:31 -05002577static int
James Smart2e0fef82007-06-17 19:56:36 -05002578lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002579{
James Smart2e0fef82007-06-17 19:56:36 -05002580 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002581 IOCB_t *icmd;
2582 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002583 struct lpfc_sli *psli;
2584 FARP *fp;
2585 uint8_t *pcmd;
2586 uint32_t *lp;
2587 uint16_t cmdsize;
2588 struct lpfc_nodelist *ondlp;
2589 struct lpfc_nodelist *ndlp;
2590
2591 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002592 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002593
James Smarte47c9092008-02-08 18:49:26 -05002594 ndlp = lpfc_findnode_did(vport, nportid);
2595 if (!ndlp) {
2596 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2597 if (!ndlp)
2598 return 1;
2599 lpfc_nlp_init(vport, ndlp, nportid);
2600 lpfc_enqueue_node(vport, ndlp);
2601 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2602 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2603 if (!ndlp)
2604 return 1;
2605 }
James Smart2e0fef82007-06-17 19:56:36 -05002606
2607 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2608 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002609 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002610 /* This will trigger the release of the node just
2611 * allocated
2612 */
James Smart329f9bc2007-04-25 09:53:01 -04002613 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002614 return 1;
dea31012005-04-17 16:05:31 -05002615 }
2616
2617 icmd = &elsiocb->iocb;
2618 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2619
2620 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002621 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002622
2623 /* Fill in FARPR payload */
2624 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002625 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002626 lp = (uint32_t *) pcmd;
2627 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002628 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002629 fp->Rflags = 0;
2630 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2631
James Smart92d7f7b2007-06-17 19:56:38 -05002632 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2633 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002634 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002635 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002636 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002637 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002638 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002639 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002640 }
2641
James Smart858c9f62007-06-17 19:56:39 -05002642 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2643 "Issue FARPR: did:x%x",
2644 ndlp->nlp_DID, 0, 0);
2645
dea31012005-04-17 16:05:31 -05002646 phba->fc_stat.elsXmitFARPR++;
2647 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002648 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2649 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002650 /* The additional lpfc_nlp_put will cause the following
2651 * lpfc_els_free_iocb routine to trigger the release of
2652 * the node.
2653 */
James Smart329f9bc2007-04-25 09:53:01 -04002654 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002655 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002656 return 1;
dea31012005-04-17 16:05:31 -05002657 }
James Smartfa4066b2008-01-11 01:53:27 -05002658 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2659 * trigger the release of the node.
2660 */
James Smart329f9bc2007-04-25 09:53:01 -04002661 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002662 return 0;
dea31012005-04-17 16:05:31 -05002663}
2664
James Smarte59058c2008-08-24 21:49:00 -04002665/**
James Smart3621a712009-04-06 18:47:14 -04002666 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002667 * @vport: pointer to a host virtual N_Port data structure.
2668 * @nlp: pointer to a node-list data structure.
2669 *
2670 * This routine cancels the timer with a delayed IOCB-command retry for
2671 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2672 * removes the ELS retry event if it presents. In addition, if the
2673 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2674 * commands are sent for the @vport's nodes that require issuing discovery
2675 * ADISC.
2676 **/
dea31012005-04-17 16:05:31 -05002677void
James Smart2e0fef82007-06-17 19:56:36 -05002678lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002679{
James Smart2e0fef82007-06-17 19:56:36 -05002680 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002681 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002682
James Smart0d2b6b82008-06-14 22:52:47 -04002683 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2684 return;
James Smart2e0fef82007-06-17 19:56:36 -05002685 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002686 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002687 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002688 del_timer_sync(&nlp->nlp_delayfunc);
2689 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002690 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002691 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002692 /* Decrement nlp reference count held for the delayed retry */
2693 evtp = &nlp->els_retry_evt;
2694 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2695 }
James Smartfdcebe22006-03-07 15:04:01 -05002696 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002697 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002698 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002699 spin_unlock_irq(shost->host_lock);
2700 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002701 if (vport->port_state < LPFC_VPORT_READY) {
2702 /* Check if there are more ADISCs to be sent */
2703 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002704 } else {
2705 /* Check if there are more PLOGIs to be sent */
2706 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002707 if (vport->num_disc_nodes == 0) {
2708 spin_lock_irq(shost->host_lock);
2709 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2710 spin_unlock_irq(shost->host_lock);
2711 lpfc_can_disctmo(vport);
2712 lpfc_end_rscn(vport);
2713 }
James Smartfdcebe22006-03-07 15:04:01 -05002714 }
2715 }
2716 }
2717 return;
2718}
2719
James Smarte59058c2008-08-24 21:49:00 -04002720/**
James Smart3621a712009-04-06 18:47:14 -04002721 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002722 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2723 *
2724 * This routine is invoked by the ndlp delayed-function timer to check
2725 * whether there is any pending ELS retry event(s) with the node. If not, it
2726 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2727 * adds the delayed events to the HBA work list and invokes the
2728 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2729 * event. Note that lpfc_nlp_get() is called before posting the event to
2730 * the work list to hold reference count of ndlp so that it guarantees the
2731 * reference to ndlp will still be available when the worker thread gets
2732 * to the event associated with the ndlp.
2733 **/
James Smartfdcebe22006-03-07 15:04:01 -05002734void
dea31012005-04-17 16:05:31 -05002735lpfc_els_retry_delay(unsigned long ptr)
2736{
James Smart2e0fef82007-06-17 19:56:36 -05002737 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2738 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002739 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002740 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002741 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002742
James Smart92d7f7b2007-06-17 19:56:38 -05002743 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002744 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002745 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002746 return;
2747 }
2748
James Smartfa4066b2008-01-11 01:53:27 -05002749 /* We need to hold the node by incrementing the reference
2750 * count until the queued work is done
2751 */
2752 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002753 if (evtp->evt_arg1) {
2754 evtp->evt = LPFC_EVT_ELS_RETRY;
2755 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002756 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002757 }
James Smart92d7f7b2007-06-17 19:56:38 -05002758 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002759 return;
2760}
2761
James Smarte59058c2008-08-24 21:49:00 -04002762/**
James Smart3621a712009-04-06 18:47:14 -04002763 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002764 * @ndlp: pointer to a node-list data structure.
2765 *
2766 * This routine is the worker-thread handler for processing the @ndlp delayed
2767 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2768 * the last ELS command from the associated ndlp and invokes the proper ELS
2769 * function according to the delayed ELS command to retry the command.
2770 **/
dea31012005-04-17 16:05:31 -05002771void
2772lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2773{
James Smart2e0fef82007-06-17 19:56:36 -05002774 struct lpfc_vport *vport = ndlp->vport;
2775 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2776 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002777
James Smart2e0fef82007-06-17 19:56:36 -05002778 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002779 did = ndlp->nlp_DID;
2780 cmd = ndlp->nlp_last_elscmd;
2781 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002782
2783 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002784 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002785 return;
2786 }
2787
2788 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002789 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002790 /*
2791 * If a discovery event readded nlp_delayfunc after timer
2792 * firing and before processing the timer, cancel the
2793 * nlp_delayfunc.
2794 */
2795 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002796 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002797 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002798
2799 switch (cmd) {
2800 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002801 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002802 break;
2803 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002804 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002805 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002806 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002807 }
dea31012005-04-17 16:05:31 -05002808 break;
2809 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002810 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002811 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002812 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002813 }
dea31012005-04-17 16:05:31 -05002814 break;
2815 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002816 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002817 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002818 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002819 }
dea31012005-04-17 16:05:31 -05002820 break;
2821 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002822 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002823 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002824 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002825 }
dea31012005-04-17 16:05:31 -05002826 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002827 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05002828 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
2829 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05002830 break;
dea31012005-04-17 16:05:31 -05002831 }
2832 return;
2833}
2834
James Smarte59058c2008-08-24 21:49:00 -04002835/**
James Smart3621a712009-04-06 18:47:14 -04002836 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002837 * @phba: pointer to lpfc hba data structure.
2838 * @cmdiocb: pointer to lpfc command iocb data structure.
2839 * @rspiocb: pointer to lpfc response iocb data structure.
2840 *
2841 * This routine makes a retry decision on an ELS command IOCB, which has
2842 * failed. The following ELS IOCBs use this function for retrying the command
2843 * when previously issued command responsed with error status: FLOGI, PLOGI,
2844 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2845 * returned error status, it makes the decision whether a retry shall be
2846 * issued for the command, and whether a retry shall be made immediately or
2847 * delayed. In the former case, the corresponding ELS command issuing-function
2848 * is called to retry the command. In the later case, the ELS command shall
2849 * be posted to the ndlp delayed event and delayed function timer set to the
2850 * ndlp for the delayed command issusing.
2851 *
2852 * Return code
2853 * 0 - No retry of els command is made
2854 * 1 - Immediate or delayed retry of els command is made
2855 **/
dea31012005-04-17 16:05:31 -05002856static int
James Smart2e0fef82007-06-17 19:56:36 -05002857lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2858 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002859{
James Smart2e0fef82007-06-17 19:56:36 -05002860 struct lpfc_vport *vport = cmdiocb->vport;
2861 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2862 IOCB_t *irsp = &rspiocb->iocb;
2863 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2864 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002865 uint32_t *elscmd;
2866 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002867 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002868 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002869 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002870 uint32_t did;
dea31012005-04-17 16:05:31 -05002871
James Smart488d1462006-03-07 15:02:37 -05002872
dea31012005-04-17 16:05:31 -05002873 /* Note: context2 may be 0 for internal driver abort
2874 * of delays ELS command.
2875 */
2876
2877 if (pcmd && pcmd->virt) {
2878 elscmd = (uint32_t *) (pcmd->virt);
2879 cmd = *elscmd++;
2880 }
2881
James Smarte47c9092008-02-08 18:49:26 -05002882 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002883 did = ndlp->nlp_DID;
2884 else {
2885 /* We should only hit this case for retrying PLOGI */
2886 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002887 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002888 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2889 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002890 return 1;
2891 }
2892
James Smart858c9f62007-06-17 19:56:39 -05002893 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2894 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2895 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2896
dea31012005-04-17 16:05:31 -05002897 switch (irsp->ulpStatus) {
2898 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05002899 break;
James Smart1151e3e2011-02-16 12:39:35 -05002900 case IOSTAT_REMOTE_STOP:
2901 if (phba->sli_rev == LPFC_SLI_REV4) {
2902 /* This IO was aborted by the target, we don't
2903 * know the rxid and because we did not send the
2904 * ABTS we cannot generate and RRQ.
2905 */
2906 lpfc_set_rrq_active(phba, ndlp,
2907 cmdiocb->sli4_xritag, 0, 0);
2908 }
2909 break;
dea31012005-04-17 16:05:31 -05002910 case IOSTAT_LOCAL_REJECT:
2911 switch ((irsp->un.ulpWord[4] & 0xff)) {
2912 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002913 if (cmd == ELS_CMD_FLOGI) {
2914 if (PCI_DEVICE_ID_HORNET ==
2915 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05002916 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05002917 phba->pport->fc_myDID = 0;
2918 phba->alpa_map[0] = 0;
2919 phba->alpa_map[1] = 0;
2920 }
2921 }
James Smart2e0fef82007-06-17 19:56:36 -05002922 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002923 delay = 1000;
dea31012005-04-17 16:05:31 -05002924 retry = 1;
2925 break;
2926
James Smart92d7f7b2007-06-17 19:56:38 -05002927 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002928 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2929 "0124 Retry illegal cmd x%x "
2930 "retry:x%x delay:x%x\n",
2931 cmd, cmdiocb->retry, delay);
2932 retry = 1;
2933 /* All command's retry policy */
2934 maxretry = 8;
2935 if (cmdiocb->retry > 2)
2936 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002937 break;
2938
dea31012005-04-17 16:05:31 -05002939 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002940 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002941 retry = 1;
2942 if (cmdiocb->retry > 100)
2943 delay = 100;
2944 maxretry = 250;
2945 break;
2946
2947 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002948 delay = 100;
dea31012005-04-17 16:05:31 -05002949 retry = 1;
2950 break;
2951
James Smart858c9f62007-06-17 19:56:39 -05002952 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002953 case IOERR_INVALID_RPI:
2954 retry = 1;
2955 break;
2956 }
2957 break;
2958
2959 case IOSTAT_NPORT_RJT:
2960 case IOSTAT_FABRIC_RJT:
2961 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2962 retry = 1;
2963 break;
2964 }
2965 break;
2966
2967 case IOSTAT_NPORT_BSY:
2968 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002969 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002970 retry = 1;
2971 break;
2972
2973 case IOSTAT_LS_RJT:
2974 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2975 /* Added for Vendor specifc support
2976 * Just keep retrying for these Rsn / Exp codes
2977 */
2978 switch (stat.un.b.lsRjtRsnCode) {
2979 case LSRJT_UNABLE_TPC:
2980 if (stat.un.b.lsRjtRsnCodeExp ==
2981 LSEXP_CMD_IN_PROGRESS) {
2982 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002983 delay = 1000;
dea31012005-04-17 16:05:31 -05002984 maxretry = 48;
2985 }
2986 retry = 1;
2987 break;
2988 }
James Smartffc95492010-06-07 15:23:17 -04002989 if (stat.un.b.lsRjtRsnCodeExp ==
2990 LSEXP_CANT_GIVE_DATA) {
2991 if (cmd == ELS_CMD_PLOGI) {
2992 delay = 1000;
2993 maxretry = 48;
2994 }
2995 retry = 1;
2996 break;
2997 }
dea31012005-04-17 16:05:31 -05002998 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002999 delay = 1000;
dea31012005-04-17 16:05:31 -05003000 maxretry = lpfc_max_els_tries + 1;
3001 retry = 1;
3002 break;
3003 }
James Smart92d7f7b2007-06-17 19:56:38 -05003004 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3005 (cmd == ELS_CMD_FDISC) &&
3006 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003007 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3008 "0125 FDISC Failed (x%x). "
3009 "Fabric out of resources\n",
3010 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003011 lpfc_vport_set_state(vport,
3012 FC_VPORT_NO_FABRIC_RSCS);
3013 }
dea31012005-04-17 16:05:31 -05003014 break;
3015
3016 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003017 if ((cmd == ELS_CMD_PLOGI) ||
3018 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003019 delay = 1000;
dea31012005-04-17 16:05:31 -05003020 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003021 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003022 /* FDISC retry policy */
3023 maxretry = 48;
3024 if (cmdiocb->retry >= 32)
3025 delay = 1000;
dea31012005-04-17 16:05:31 -05003026 }
3027 retry = 1;
3028 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003029
3030 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003031 /* There are some cases where switches return this
3032 * error when they are not ready and should be returning
3033 * Logical Busy. We should delay every time.
3034 */
3035 if (cmd == ELS_CMD_FDISC &&
3036 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3037 maxretry = 3;
3038 delay = 1000;
3039 retry = 1;
3040 break;
3041 }
James Smart92d7f7b2007-06-17 19:56:38 -05003042 case LSRJT_PROTOCOL_ERR:
3043 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3044 (cmd == ELS_CMD_FDISC) &&
3045 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3046 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3047 ) {
James Smarte8b62012007-08-02 11:10:09 -04003048 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003049 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003050 "Fabric Detected Bad WWN\n",
3051 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003052 lpfc_vport_set_state(vport,
3053 FC_VPORT_FABRIC_REJ_WWN);
3054 }
3055 break;
dea31012005-04-17 16:05:31 -05003056 }
3057 break;
3058
3059 case IOSTAT_INTERMED_RSP:
3060 case IOSTAT_BA_RJT:
3061 break;
3062
3063 default:
3064 break;
3065 }
3066
James Smart488d1462006-03-07 15:02:37 -05003067 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003068 retry = 1;
dea31012005-04-17 16:05:31 -05003069
James Smart695a8142010-01-26 23:08:03 -05003070 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart76a95d72010-11-20 23:11:48 -05003071 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003072 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003073 /* FLOGI retry policy */
3074 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04003075 /* retry forever */
3076 maxretry = 0;
3077 if (cmdiocb->retry >= 100)
3078 delay = 5000;
3079 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003080 delay = 1000;
3081 }
3082
James Smart6669f9b2009-10-02 15:16:45 -04003083 cmdiocb->retry++;
3084 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003085 phba->fc_stat.elsRetryExceeded++;
3086 retry = 0;
3087 }
3088
James Smarted957682007-06-17 19:56:37 -05003089 if ((vport->load_flag & FC_UNLOADING) != 0)
3090 retry = 0;
3091
dea31012005-04-17 16:05:31 -05003092 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003093 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3094 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3095 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3096 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3097 "2849 Stop retry ELS command "
3098 "x%x to remote NPORT x%x, "
3099 "Data: x%x x%x\n", cmd, did,
3100 cmdiocb->retry, delay);
3101 return 0;
3102 }
3103 }
dea31012005-04-17 16:05:31 -05003104
3105 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003106 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3107 "0107 Retry ELS command x%x to remote "
3108 "NPORT x%x Data: x%x x%x\n",
3109 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003110
James Smart858c9f62007-06-17 19:56:39 -05003111 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3112 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3113 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
3114 /* Don't reset timer for no resources */
3115
dea31012005-04-17 16:05:31 -05003116 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003117 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003118 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003119 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003120 }
3121
3122 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003123 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003124 phba->fc_stat.elsDelayRetry++;
3125 ndlp->nlp_retry = cmdiocb->retry;
3126
James Smart92d7f7b2007-06-17 19:56:38 -05003127 /* delay is specified in milliseconds */
3128 mod_timer(&ndlp->nlp_delayfunc,
3129 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003130 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003131 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003132 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003133
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003134 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003135 if (cmd == ELS_CMD_PRLI)
3136 lpfc_nlp_set_state(vport, ndlp,
3137 NLP_STE_REG_LOGIN_ISSUE);
3138 else
3139 lpfc_nlp_set_state(vport, ndlp,
3140 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003141 ndlp->nlp_last_elscmd = cmd;
3142
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003143 return 1;
dea31012005-04-17 16:05:31 -05003144 }
3145 switch (cmd) {
3146 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003147 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003148 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003149 case ELS_CMD_FDISC:
3150 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3151 return 1;
dea31012005-04-17 16:05:31 -05003152 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003153 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003154 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003155 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003156 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003157 }
James Smart2e0fef82007-06-17 19:56:36 -05003158 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003159 return 1;
dea31012005-04-17 16:05:31 -05003160 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003161 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003162 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3163 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003164 return 1;
dea31012005-04-17 16:05:31 -05003165 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003166 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003167 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3168 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003169 return 1;
dea31012005-04-17 16:05:31 -05003170 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003171 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003172 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3173 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003174 return 1;
dea31012005-04-17 16:05:31 -05003175 }
3176 }
dea31012005-04-17 16:05:31 -05003177 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003178 if (logerr) {
3179 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3180 "0137 No retry ELS command x%x to remote "
3181 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3182 cmd, did, irsp->ulpStatus,
3183 irsp->un.ulpWord[4]);
3184 }
3185 else {
3186 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003187 "0108 No retry ELS command x%x to remote "
3188 "NPORT x%x Retried:%d Error:x%x/%x\n",
3189 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3190 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003191 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003192 return 0;
dea31012005-04-17 16:05:31 -05003193}
3194
James Smarte59058c2008-08-24 21:49:00 -04003195/**
James Smart3621a712009-04-06 18:47:14 -04003196 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003197 * @phba: pointer to lpfc hba data structure.
3198 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3199 *
3200 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3201 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3202 * checks to see whether there is a lpfc DMA buffer associated with the
3203 * response of the command IOCB. If so, it will be released before releasing
3204 * the lpfc DMA buffer associated with the IOCB itself.
3205 *
3206 * Return code
3207 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3208 **/
James Smart09372822008-01-11 01:52:54 -05003209static int
James Smart87af33f2007-10-27 13:37:43 -04003210lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3211{
3212 struct lpfc_dmabuf *buf_ptr;
3213
James Smarte59058c2008-08-24 21:49:00 -04003214 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003215 if (!list_empty(&buf_ptr1->list)) {
3216 list_remove_head(&buf_ptr1->list, buf_ptr,
3217 struct lpfc_dmabuf,
3218 list);
3219 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3220 kfree(buf_ptr);
3221 }
3222 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3223 kfree(buf_ptr1);
3224 return 0;
3225}
3226
James Smarte59058c2008-08-24 21:49:00 -04003227/**
James Smart3621a712009-04-06 18:47:14 -04003228 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003229 * @phba: pointer to lpfc hba data structure.
3230 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3231 *
3232 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3233 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3234 * pool.
3235 *
3236 * Return code
3237 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3238 **/
James Smart09372822008-01-11 01:52:54 -05003239static int
James Smart87af33f2007-10-27 13:37:43 -04003240lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3241{
3242 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3243 kfree(buf_ptr);
3244 return 0;
3245}
3246
James Smarte59058c2008-08-24 21:49:00 -04003247/**
James Smart3621a712009-04-06 18:47:14 -04003248 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003249 * @phba: pointer to lpfc hba data structure.
3250 * @elsiocb: pointer to lpfc els command iocb data structure.
3251 *
3252 * This routine frees a command IOCB and its associated resources. The
3253 * command IOCB data structure contains the reference to various associated
3254 * resources, these fields must be set to NULL if the associated reference
3255 * not present:
3256 * context1 - reference to ndlp
3257 * context2 - reference to cmd
3258 * context2->next - reference to rsp
3259 * context3 - reference to bpl
3260 *
3261 * It first properly decrements the reference count held on ndlp for the
3262 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3263 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3264 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3265 * adds the DMA buffer the @phba data structure for the delayed release.
3266 * If reference to the Buffer Pointer List (BPL) is present, the
3267 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3268 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3269 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3270 *
3271 * Return code
3272 * 0 - Success (currently, always return 0)
3273 **/
James Smart87af33f2007-10-27 13:37:43 -04003274int
James Smart329f9bc2007-04-25 09:53:01 -04003275lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003276{
3277 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003278 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003279
James Smarta8adb832007-10-27 13:37:53 -04003280 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3281 if (ndlp) {
3282 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3283 lpfc_nlp_put(ndlp);
3284
3285 /* If the ndlp is not being used by another discovery
3286 * thread, free it.
3287 */
3288 if (!lpfc_nlp_not_used(ndlp)) {
3289 /* If ndlp is being used by another discovery
3290 * thread, just clear NLP_DEFER_RM
3291 */
3292 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3293 }
3294 }
3295 else
3296 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003297 elsiocb->context1 = NULL;
3298 }
dea31012005-04-17 16:05:31 -05003299 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3300 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003301 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3302 /* Firmware could still be in progress of DMAing
3303 * payload, so don't free data buffer till after
3304 * a hbeat.
3305 */
3306 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3307 buf_ptr = elsiocb->context2;
3308 elsiocb->context2 = NULL;
3309 if (buf_ptr) {
3310 buf_ptr1 = NULL;
3311 spin_lock_irq(&phba->hbalock);
3312 if (!list_empty(&buf_ptr->list)) {
3313 list_remove_head(&buf_ptr->list,
3314 buf_ptr1, struct lpfc_dmabuf,
3315 list);
3316 INIT_LIST_HEAD(&buf_ptr1->list);
3317 list_add_tail(&buf_ptr1->list,
3318 &phba->elsbuf);
3319 phba->elsbuf_cnt++;
3320 }
3321 INIT_LIST_HEAD(&buf_ptr->list);
3322 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3323 phba->elsbuf_cnt++;
3324 spin_unlock_irq(&phba->hbalock);
3325 }
3326 } else {
3327 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3328 lpfc_els_free_data(phba, buf_ptr1);
3329 }
dea31012005-04-17 16:05:31 -05003330 }
3331
3332 if (elsiocb->context3) {
3333 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003334 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003335 }
James Bottomley604a3e32005-10-29 10:28:33 -05003336 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003337 return 0;
3338}
3339
James Smarte59058c2008-08-24 21:49:00 -04003340/**
James Smart3621a712009-04-06 18:47:14 -04003341 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003342 * @phba: pointer to lpfc hba data structure.
3343 * @cmdiocb: pointer to lpfc command iocb data structure.
3344 * @rspiocb: pointer to lpfc response iocb data structure.
3345 *
3346 * This routine is the completion callback function to the Logout (LOGO)
3347 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3348 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3349 * release the ndlp if it has the last reference remaining (reference count
3350 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3351 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3352 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3353 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3354 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3355 * IOCB data structure.
3356 **/
dea31012005-04-17 16:05:31 -05003357static void
James Smart2e0fef82007-06-17 19:56:36 -05003358lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3359 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003360{
James Smart2e0fef82007-06-17 19:56:36 -05003361 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3362 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003363 IOCB_t *irsp;
3364
3365 irsp = &rspiocb->iocb;
3366 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3367 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3368 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003369 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003370 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3371 "0109 ACC to LOGO completes to NPort x%x "
3372 "Data: x%x x%x x%x\n",
3373 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3374 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003375
3376 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3377 /* NPort Recovery mode or node is just allocated */
3378 if (!lpfc_nlp_not_used(ndlp)) {
3379 /* If the ndlp is being used by another discovery
3380 * thread, just unregister the RPI.
3381 */
3382 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003383 } else {
3384 /* Indicate the node has already released, should
3385 * not reference to it from within lpfc_els_free_iocb.
3386 */
3387 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003388 }
dea31012005-04-17 16:05:31 -05003389 }
3390 lpfc_els_free_iocb(phba, cmdiocb);
3391 return;
3392}
3393
James Smarte59058c2008-08-24 21:49:00 -04003394/**
James Smart3621a712009-04-06 18:47:14 -04003395 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003396 * @phba: pointer to lpfc hba data structure.
3397 * @pmb: pointer to the driver internal queue element for mailbox command.
3398 *
3399 * This routine is the completion callback function for unregister default
3400 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3401 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3402 * decrements the ndlp reference count held for this completion callback
3403 * function. After that, it invokes the lpfc_nlp_not_used() to check
3404 * whether there is only one reference left on the ndlp. If so, it will
3405 * perform one more decrement and trigger the release of the ndlp.
3406 **/
James Smart858c9f62007-06-17 19:56:39 -05003407void
3408lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3409{
3410 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3411 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3412
3413 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003414 pmb->context2 = NULL;
3415
James Smart858c9f62007-06-17 19:56:39 -05003416 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3417 kfree(mp);
3418 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003419 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003420 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003421 /* This is the end of the default RPI cleanup logic for this
3422 * ndlp. If no other discovery threads are using this ndlp.
3423 * we should free all resources associated with it.
3424 */
3425 lpfc_nlp_not_used(ndlp);
3426 }
James Smart3772a992009-05-22 14:50:54 -04003427
James Smart858c9f62007-06-17 19:56:39 -05003428 return;
3429}
3430
James Smarte59058c2008-08-24 21:49:00 -04003431/**
James Smart3621a712009-04-06 18:47:14 -04003432 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003433 * @phba: pointer to lpfc hba data structure.
3434 * @cmdiocb: pointer to lpfc command iocb data structure.
3435 * @rspiocb: pointer to lpfc response iocb data structure.
3436 *
3437 * This routine is the completion callback function for ELS Response IOCB
3438 * command. In normal case, this callback function just properly sets the
3439 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3440 * field in the command IOCB is not NULL, the referred mailbox command will
3441 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3442 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3443 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3444 * routine shall be invoked trying to release the ndlp if no other threads
3445 * are currently referring it.
3446 **/
dea31012005-04-17 16:05:31 -05003447static void
James Smart858c9f62007-06-17 19:56:39 -05003448lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003449 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003450{
James Smart2e0fef82007-06-17 19:56:36 -05003451 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3452 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3453 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003454 IOCB_t *irsp;
3455 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003456 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003457 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003458 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003459
James Smart33ccf8d2006-08-17 11:57:58 -04003460 irsp = &rspiocb->iocb;
3461
dea31012005-04-17 16:05:31 -05003462 if (cmdiocb->context_un.mbox)
3463 mbox = cmdiocb->context_un.mbox;
3464
James Smartfa4066b2008-01-11 01:53:27 -05003465 /* First determine if this is a LS_RJT cmpl. Note, this callback
3466 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3467 */
James Smart87af33f2007-10-27 13:37:43 -04003468 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003469 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3470 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003471 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003472 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003473 */
3474 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3475 ls_rjt = 1;
3476 }
3477
dea31012005-04-17 16:05:31 -05003478 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003479 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003480 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003481 mp = (struct lpfc_dmabuf *) mbox->context1;
3482 if (mp) {
3483 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3484 kfree(mp);
3485 }
James Smart329f9bc2007-04-25 09:53:01 -04003486 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003487 }
James Smart58da1ff2008-04-07 10:15:56 -04003488 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3489 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003490 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003491 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003492 /* Indicate the node has already released,
3493 * should not reference to it from within
3494 * the routine lpfc_els_free_iocb.
3495 */
3496 cmdiocb->context1 = NULL;
3497 }
dea31012005-04-17 16:05:31 -05003498 goto out;
3499 }
3500
James Smart858c9f62007-06-17 19:56:39 -05003501 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003502 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003503 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003504 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003505 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003506 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3507 "0110 ELS response tag x%x completes "
3508 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3509 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3510 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3511 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3512 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003513 if (mbox) {
3514 if ((rspiocb->iocb.ulpStatus == 0)
3515 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003516 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003517 /* Increment reference count to ndlp to hold the
3518 * reference to ndlp for the callback function.
3519 */
James Smart329f9bc2007-04-25 09:53:01 -04003520 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003521 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003522 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3523 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3524 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3525 }
3526 else {
3527 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3528 ndlp->nlp_prev_state = ndlp->nlp_state;
3529 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003530 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003531 }
James Smart0b727fe2007-10-27 13:37:25 -04003532 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003533 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003534 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003535 else
3536 /* Decrement the ndlp reference count we
3537 * set for this failed mailbox command.
3538 */
3539 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003540
3541 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3542 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3543 "0138 ELS rsp: Cannot issue reg_login for x%x "
3544 "Data: x%x x%x x%x\n",
3545 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3546 ndlp->nlp_rpi);
3547
James Smartfa4066b2008-01-11 01:53:27 -05003548 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003549 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003550 /* Indicate node has already been released,
3551 * should not reference to it from within
3552 * the routine lpfc_els_free_iocb.
3553 */
3554 cmdiocb->context1 = NULL;
3555 }
dea31012005-04-17 16:05:31 -05003556 } else {
James Smart858c9f62007-06-17 19:56:39 -05003557 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3558 if (!lpfc_error_lost_link(irsp) &&
3559 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003560 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003561 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003562 /* Indicate node has already been
3563 * released, should not reference
3564 * to it from within the routine
3565 * lpfc_els_free_iocb.
3566 */
3567 cmdiocb->context1 = NULL;
3568 }
dea31012005-04-17 16:05:31 -05003569 }
3570 }
James Smart14691152006-12-02 13:34:28 -05003571 mp = (struct lpfc_dmabuf *) mbox->context1;
3572 if (mp) {
3573 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3574 kfree(mp);
3575 }
3576 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003577 }
3578out:
James Smart58da1ff2008-04-07 10:15:56 -04003579 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003580 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003581 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003582 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003583
3584 /* If the node is not being used by another discovery thread,
3585 * and we are sending a reject, we are done with it.
3586 * Release driver reference count here and free associated
3587 * resources.
3588 */
3589 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003590 if (lpfc_nlp_not_used(ndlp))
3591 /* Indicate node has already been released,
3592 * should not reference to it from within
3593 * the routine lpfc_els_free_iocb.
3594 */
3595 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003596 }
James Smart87af33f2007-10-27 13:37:43 -04003597
dea31012005-04-17 16:05:31 -05003598 lpfc_els_free_iocb(phba, cmdiocb);
3599 return;
3600}
3601
James Smarte59058c2008-08-24 21:49:00 -04003602/**
James Smart3621a712009-04-06 18:47:14 -04003603 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003604 * @vport: pointer to a host virtual N_Port data structure.
3605 * @flag: the els command code to be accepted.
3606 * @oldiocb: pointer to the original lpfc command iocb data structure.
3607 * @ndlp: pointer to a node-list data structure.
3608 * @mbox: pointer to the driver internal queue element for mailbox command.
3609 *
3610 * This routine prepares and issues an Accept (ACC) response IOCB
3611 * command. It uses the @flag to properly set up the IOCB field for the
3612 * specific ACC response command to be issued and invokes the
3613 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3614 * @mbox pointer is passed in, it will be put into the context_un.mbox
3615 * field of the IOCB for the completion callback function to issue the
3616 * mailbox command to the HBA later when callback is invoked.
3617 *
3618 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3619 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3620 * will be stored into the context1 field of the IOCB for the completion
3621 * callback function to the corresponding response ELS IOCB command.
3622 *
3623 * Return code
3624 * 0 - Successfully issued acc response
3625 * 1 - Failed to issue acc response
3626 **/
dea31012005-04-17 16:05:31 -05003627int
James Smart2e0fef82007-06-17 19:56:36 -05003628lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3629 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003630 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003631{
James Smart2e0fef82007-06-17 19:56:36 -05003632 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3633 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003634 IOCB_t *icmd;
3635 IOCB_t *oldcmd;
3636 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003637 struct lpfc_sli *psli;
3638 uint8_t *pcmd;
3639 uint16_t cmdsize;
3640 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003641 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003642
3643 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003644 oldcmd = &oldiocb->iocb;
3645
3646 switch (flag) {
3647 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003648 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003649 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3650 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003651 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003652 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003653 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003654 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003655 return 1;
dea31012005-04-17 16:05:31 -05003656 }
James Smart2e0fef82007-06-17 19:56:36 -05003657
dea31012005-04-17 16:05:31 -05003658 icmd = &elsiocb->iocb;
3659 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3660 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3661 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003662 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003663
3664 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3665 "Issue ACC: did:x%x flg:x%x",
3666 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003667 break;
3668 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003669 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003670 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3671 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003672 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003673 return 1;
James Smart488d1462006-03-07 15:02:37 -05003674
dea31012005-04-17 16:05:31 -05003675 icmd = &elsiocb->iocb;
3676 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3677 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3678
3679 if (mbox)
3680 elsiocb->context_un.mbox = mbox;
3681
3682 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003683 pcmd += sizeof(uint32_t);
3684 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003685
3686 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3687 "Issue ACC PLOGI: did:x%x flg:x%x",
3688 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003689 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003690 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003691 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003692 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003693 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3694 if (!elsiocb)
3695 return 1;
3696
3697 icmd = &elsiocb->iocb;
3698 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3699 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3700
3701 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003702 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003703 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3704 els_pkt_ptr = (ELS_PKT *) pcmd;
3705 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003706
3707 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3708 "Issue ACC PRLO: did:x%x flg:x%x",
3709 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003710 break;
dea31012005-04-17 16:05:31 -05003711 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003712 return 1;
dea31012005-04-17 16:05:31 -05003713 }
dea31012005-04-17 16:05:31 -05003714 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003715 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3716 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3717 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3718 elsiocb->iotag, elsiocb->iocb.ulpContext,
3719 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3720 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003721 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003722 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003723 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003724 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003725 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3726 } else {
James Smart858c9f62007-06-17 19:56:39 -05003727 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003728 }
3729
3730 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003731 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003732 if (rc == IOCB_ERROR) {
3733 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003734 return 1;
dea31012005-04-17 16:05:31 -05003735 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003736 return 0;
dea31012005-04-17 16:05:31 -05003737}
3738
James Smarte59058c2008-08-24 21:49:00 -04003739/**
James Smart3621a712009-04-06 18:47:14 -04003740 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003741 * @vport: pointer to a virtual N_Port data structure.
3742 * @rejectError:
3743 * @oldiocb: pointer to the original lpfc command iocb data structure.
3744 * @ndlp: pointer to a node-list data structure.
3745 * @mbox: pointer to the driver internal queue element for mailbox command.
3746 *
3747 * This routine prepares and issue an Reject (RJT) response IOCB
3748 * command. If a @mbox pointer is passed in, it will be put into the
3749 * context_un.mbox field of the IOCB for the completion callback function
3750 * to issue to the HBA later.
3751 *
3752 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3753 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3754 * will be stored into the context1 field of the IOCB for the completion
3755 * callback function to the reject response ELS IOCB command.
3756 *
3757 * Return code
3758 * 0 - Successfully issued reject response
3759 * 1 - Failed to issue reject response
3760 **/
dea31012005-04-17 16:05:31 -05003761int
James Smart2e0fef82007-06-17 19:56:36 -05003762lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003763 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3764 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003765{
James Smart2e0fef82007-06-17 19:56:36 -05003766 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003767 IOCB_t *icmd;
3768 IOCB_t *oldcmd;
3769 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003770 struct lpfc_sli *psli;
3771 uint8_t *pcmd;
3772 uint16_t cmdsize;
3773 int rc;
3774
3775 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003776 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003777 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3778 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003779 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003780 return 1;
dea31012005-04-17 16:05:31 -05003781
3782 icmd = &elsiocb->iocb;
3783 oldcmd = &oldiocb->iocb;
3784 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3785 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3786
3787 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003788 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003789 *((uint32_t *) (pcmd)) = rejectError;
3790
James Smart51ef4c22007-08-02 11:10:31 -04003791 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003792 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003793
dea31012005-04-17 16:05:31 -05003794 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003795 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3796 "0129 Xmit ELS RJT x%x response tag x%x "
3797 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3798 "rpi x%x\n",
3799 rejectError, elsiocb->iotag,
3800 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3801 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003802 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3803 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3804 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3805
dea31012005-04-17 16:05:31 -05003806 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003807 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003808 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003809
dea31012005-04-17 16:05:31 -05003810 if (rc == IOCB_ERROR) {
3811 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003812 return 1;
dea31012005-04-17 16:05:31 -05003813 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003814 return 0;
dea31012005-04-17 16:05:31 -05003815}
3816
James Smarte59058c2008-08-24 21:49:00 -04003817/**
James Smart3621a712009-04-06 18:47:14 -04003818 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003819 * @vport: pointer to a virtual N_Port data structure.
3820 * @oldiocb: pointer to the original lpfc command iocb data structure.
3821 * @ndlp: pointer to a node-list data structure.
3822 *
3823 * This routine prepares and issues an Accept (ACC) response to Address
3824 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3825 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3826 *
3827 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3828 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3829 * will be stored into the context1 field of the IOCB for the completion
3830 * callback function to the ADISC Accept response ELS IOCB command.
3831 *
3832 * Return code
3833 * 0 - Successfully issued acc adisc response
3834 * 1 - Failed to issue adisc acc response
3835 **/
dea31012005-04-17 16:05:31 -05003836int
James Smart2e0fef82007-06-17 19:56:36 -05003837lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3838 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003839{
James Smart2e0fef82007-06-17 19:56:36 -05003840 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003841 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003842 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003843 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003844 uint8_t *pcmd;
3845 uint16_t cmdsize;
3846 int rc;
3847
James Smart92d7f7b2007-06-17 19:56:38 -05003848 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003849 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3850 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003851 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003852 return 1;
dea31012005-04-17 16:05:31 -05003853
dea31012005-04-17 16:05:31 -05003854 icmd = &elsiocb->iocb;
3855 oldcmd = &oldiocb->iocb;
3856 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003857
3858 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003859 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3860 "0130 Xmit ADISC ACC response iotag x%x xri: "
3861 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3862 elsiocb->iotag, elsiocb->iocb.ulpContext,
3863 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3864 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003865 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3866
3867 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003868 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003869
3870 ap = (ADISC *) (pcmd);
3871 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003872 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3873 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003874 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003875
James Smart858c9f62007-06-17 19:56:39 -05003876 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3877 "Issue ACC ADISC: did:x%x flg:x%x",
3878 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3879
dea31012005-04-17 16:05:31 -05003880 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003881 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003882 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003883 if (rc == IOCB_ERROR) {
3884 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003885 return 1;
dea31012005-04-17 16:05:31 -05003886 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003887 return 0;
dea31012005-04-17 16:05:31 -05003888}
3889
James Smarte59058c2008-08-24 21:49:00 -04003890/**
James Smart3621a712009-04-06 18:47:14 -04003891 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003892 * @vport: pointer to a virtual N_Port data structure.
3893 * @oldiocb: pointer to the original lpfc command iocb data structure.
3894 * @ndlp: pointer to a node-list data structure.
3895 *
3896 * This routine prepares and issues an Accept (ACC) response to Process
3897 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3898 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3899 *
3900 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3901 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3902 * will be stored into the context1 field of the IOCB for the completion
3903 * callback function to the PRLI Accept response ELS IOCB command.
3904 *
3905 * Return code
3906 * 0 - Successfully issued acc prli response
3907 * 1 - Failed to issue acc prli response
3908 **/
dea31012005-04-17 16:05:31 -05003909int
James Smart2e0fef82007-06-17 19:56:36 -05003910lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003911 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003912{
James Smart2e0fef82007-06-17 19:56:36 -05003913 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003914 PRLI *npr;
3915 lpfc_vpd_t *vpd;
3916 IOCB_t *icmd;
3917 IOCB_t *oldcmd;
3918 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003919 struct lpfc_sli *psli;
3920 uint8_t *pcmd;
3921 uint16_t cmdsize;
3922 int rc;
3923
3924 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003925
James Smart92d7f7b2007-06-17 19:56:38 -05003926 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003927 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003928 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003929 if (!elsiocb)
3930 return 1;
dea31012005-04-17 16:05:31 -05003931
dea31012005-04-17 16:05:31 -05003932 icmd = &elsiocb->iocb;
3933 oldcmd = &oldiocb->iocb;
3934 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003935 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003936 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3937 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3938 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3939 elsiocb->iotag, elsiocb->iocb.ulpContext,
3940 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3941 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003942 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3943
3944 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003945 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003946
3947 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003948 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003949
3950 npr = (PRLI *) pcmd;
3951 vpd = &phba->vpd;
3952 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003953 * If the remote port is a target and our firmware version is 3.20 or
3954 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003955 */
James Smart0d2b6b82008-06-14 22:52:47 -04003956 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3957 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003958 npr->ConfmComplAllowed = 1;
3959 npr->Retry = 1;
3960 npr->TaskRetryIdReq = 1;
3961 }
3962
3963 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3964 npr->estabImagePair = 1;
3965 npr->readXferRdyDis = 1;
3966 npr->ConfmComplAllowed = 1;
3967
3968 npr->prliType = PRLI_FCP_TYPE;
3969 npr->initiatorFunc = 1;
3970
James Smart858c9f62007-06-17 19:56:39 -05003971 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3972 "Issue ACC PRLI: did:x%x flg:x%x",
3973 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3974
dea31012005-04-17 16:05:31 -05003975 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003976 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003977
James Smart3772a992009-05-22 14:50:54 -04003978 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003979 if (rc == IOCB_ERROR) {
3980 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003981 return 1;
dea31012005-04-17 16:05:31 -05003982 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003983 return 0;
dea31012005-04-17 16:05:31 -05003984}
3985
James Smarte59058c2008-08-24 21:49:00 -04003986/**
James Smart3621a712009-04-06 18:47:14 -04003987 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003988 * @vport: pointer to a virtual N_Port data structure.
3989 * @format: rnid command format.
3990 * @oldiocb: pointer to the original lpfc command iocb data structure.
3991 * @ndlp: pointer to a node-list data structure.
3992 *
3993 * This routine issues a Request Node Identification Data (RNID) Accept
3994 * (ACC) response. It constructs the RNID ACC response command according to
3995 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3996 * issue the response. Note that this command does not need to hold the ndlp
3997 * reference count for the callback. So, the ndlp reference count taken by
3998 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3999 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4000 * there is no ndlp reference available.
4001 *
4002 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4003 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4004 * will be stored into the context1 field of the IOCB for the completion
4005 * callback function. However, for the RNID Accept Response ELS command,
4006 * this is undone later by this routine after the IOCB is allocated.
4007 *
4008 * Return code
4009 * 0 - Successfully issued acc rnid response
4010 * 1 - Failed to issue acc rnid response
4011 **/
dea31012005-04-17 16:05:31 -05004012static int
James Smart2e0fef82007-06-17 19:56:36 -05004013lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004014 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004015{
James Smart2e0fef82007-06-17 19:56:36 -05004016 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004017 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004018 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004019 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004020 struct lpfc_sli *psli;
4021 uint8_t *pcmd;
4022 uint16_t cmdsize;
4023 int rc;
4024
4025 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004026 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4027 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004028 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004029 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004030
James Smart2e0fef82007-06-17 19:56:36 -05004031 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4032 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004033 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004034 return 1;
dea31012005-04-17 16:05:31 -05004035
dea31012005-04-17 16:05:31 -05004036 icmd = &elsiocb->iocb;
4037 oldcmd = &oldiocb->iocb;
4038 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04004039 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004040 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4041 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4042 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004043 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004044 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004045 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004046
James Smart92d7f7b2007-06-17 19:56:38 -05004047 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004048 rn = (RNID *) (pcmd);
4049 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004050 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4051 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4052 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004053 switch (format) {
4054 case 0:
4055 rn->SpecificLen = 0;
4056 break;
4057 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004058 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004059 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004060 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004061 rn->un.topologyDisc.unitType = RNID_HBA;
4062 rn->un.topologyDisc.physPort = 0;
4063 rn->un.topologyDisc.attachedNodes = 0;
4064 break;
4065 default:
4066 rn->CommonLen = 0;
4067 rn->SpecificLen = 0;
4068 break;
4069 }
4070
James Smart858c9f62007-06-17 19:56:39 -05004071 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4072 "Issue ACC RNID: did:x%x flg:x%x",
4073 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4074
dea31012005-04-17 16:05:31 -05004075 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004076 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04004077 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004078 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
4079 * it could be freed */
4080
James Smart3772a992009-05-22 14:50:54 -04004081 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004082 if (rc == IOCB_ERROR) {
4083 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004084 return 1;
dea31012005-04-17 16:05:31 -05004085 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004086 return 0;
dea31012005-04-17 16:05:31 -05004087}
4088
James Smarte59058c2008-08-24 21:49:00 -04004089/**
James Smart19ca7602010-11-20 23:11:55 -05004090 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4091 * @vport: pointer to a virtual N_Port data structure.
4092 * @iocb: pointer to the lpfc command iocb data structure.
4093 * @ndlp: pointer to a node-list data structure.
4094 *
4095 * Return
4096 **/
4097static void
4098lpfc_els_clear_rrq(struct lpfc_vport *vport,
4099 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4100{
4101 struct lpfc_hba *phba = vport->phba;
4102 uint8_t *pcmd;
4103 struct RRQ *rrq;
4104 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004105 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004106 struct lpfc_node_rrq *prrq;
4107
4108
4109 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4110 pcmd += sizeof(uint32_t);
4111 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004112 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b062011-04-16 11:03:17 -04004113 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004114
4115 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4116 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4117 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004118 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b062011-04-16 11:03:17 -04004119 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004120 rxid,
4121 iocb->iotag, iocb->iocb.ulpContext);
4122
4123 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4124 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4125 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004126 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b062011-04-16 11:03:17 -04004127 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004128 else
4129 xri = rxid;
4130 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004131 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004132 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004133 return;
4134}
4135
4136/**
James Smart12265f62010-10-22 11:05:53 -04004137 * lpfc_els_rsp_echo_acc - Issue echo acc response
4138 * @vport: pointer to a virtual N_Port data structure.
4139 * @data: pointer to echo data to return in the accept.
4140 * @oldiocb: pointer to the original lpfc command iocb data structure.
4141 * @ndlp: pointer to a node-list data structure.
4142 *
4143 * Return code
4144 * 0 - Successfully issued acc echo response
4145 * 1 - Failed to issue acc echo response
4146 **/
4147static int
4148lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4149 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4150{
4151 struct lpfc_hba *phba = vport->phba;
4152 struct lpfc_iocbq *elsiocb;
4153 struct lpfc_sli *psli;
4154 uint8_t *pcmd;
4155 uint16_t cmdsize;
4156 int rc;
4157
4158 psli = &phba->sli;
4159 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4160
4161 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4162 ndlp->nlp_DID, ELS_CMD_ACC);
4163 if (!elsiocb)
4164 return 1;
4165
4166 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */
4167 /* Xmit ECHO ACC response tag <ulpIoTag> */
4168 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4169 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4170 elsiocb->iotag, elsiocb->iocb.ulpContext);
4171 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4172 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4173 pcmd += sizeof(uint32_t);
4174 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4175
4176 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4177 "Issue ACC ECHO: did:x%x flg:x%x",
4178 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4179
4180 phba->fc_stat.elsXmitACC++;
4181 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4182 lpfc_nlp_put(ndlp);
4183 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
4184 * it could be freed */
4185
4186 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4187 if (rc == IOCB_ERROR) {
4188 lpfc_els_free_iocb(phba, elsiocb);
4189 return 1;
4190 }
4191 return 0;
4192}
4193
4194/**
James Smart3621a712009-04-06 18:47:14 -04004195 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004196 * @vport: pointer to a host virtual N_Port data structure.
4197 *
4198 * This routine issues Address Discover (ADISC) ELS commands to those
4199 * N_Ports which are in node port recovery state and ADISC has not been issued
4200 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4201 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4202 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4203 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4204 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4205 * IOCBs quit for later pick up. On the other hand, after walking through
4206 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4207 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4208 * no more ADISC need to be sent.
4209 *
4210 * Return code
4211 * The number of N_Ports with adisc issued.
4212 **/
dea31012005-04-17 16:05:31 -05004213int
James Smart2e0fef82007-06-17 19:56:36 -05004214lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004215{
James Smart2e0fef82007-06-17 19:56:36 -05004216 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004217 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004218 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004219
James Smart685f0bf2007-04-25 09:53:08 -04004220 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004221 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004222 if (!NLP_CHK_NODE_ACT(ndlp))
4223 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004224 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4225 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4226 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004227 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004228 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004229 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004230 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004231 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4232 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004233 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004234 vport->num_disc_nodes++;
4235 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004236 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004237 spin_lock_irq(shost->host_lock);
4238 vport->fc_flag |= FC_NLP_MORE;
4239 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004240 break;
dea31012005-04-17 16:05:31 -05004241 }
4242 }
4243 }
4244 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004245 spin_lock_irq(shost->host_lock);
4246 vport->fc_flag &= ~FC_NLP_MORE;
4247 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004248 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004249 return sentadisc;
dea31012005-04-17 16:05:31 -05004250}
4251
James Smarte59058c2008-08-24 21:49:00 -04004252/**
James Smart3621a712009-04-06 18:47:14 -04004253 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004254 * @vport: pointer to a host virtual N_Port data structure.
4255 *
4256 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4257 * which are in node port recovery state, with a @vport. Each time an ELS
4258 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4259 * the per @vport number of discover count (num_disc_nodes) shall be
4260 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4261 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4262 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4263 * later pick up. On the other hand, after walking through all the ndlps with
4264 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4265 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4266 * PLOGI need to be sent.
4267 *
4268 * Return code
4269 * The number of N_Ports with plogi issued.
4270 **/
dea31012005-04-17 16:05:31 -05004271int
James Smart2e0fef82007-06-17 19:56:36 -05004272lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004273{
James Smart2e0fef82007-06-17 19:56:36 -05004274 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004275 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004276 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004277
James Smart2e0fef82007-06-17 19:56:36 -05004278 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4279 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004280 if (!NLP_CHK_NODE_ACT(ndlp))
4281 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004282 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4283 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4284 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4285 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4286 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004287 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4288 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004289 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004290 vport->num_disc_nodes++;
4291 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004292 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004293 spin_lock_irq(shost->host_lock);
4294 vport->fc_flag |= FC_NLP_MORE;
4295 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004296 break;
dea31012005-04-17 16:05:31 -05004297 }
4298 }
4299 }
James Smart87af33f2007-10-27 13:37:43 -04004300 if (sentplogi) {
4301 lpfc_set_disctmo(vport);
4302 }
4303 else {
James Smart2e0fef82007-06-17 19:56:36 -05004304 spin_lock_irq(shost->host_lock);
4305 vport->fc_flag &= ~FC_NLP_MORE;
4306 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004307 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004308 return sentplogi;
dea31012005-04-17 16:05:31 -05004309}
4310
James Smarte59058c2008-08-24 21:49:00 -04004311/**
James Smart3621a712009-04-06 18:47:14 -04004312 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004313 * @vport: pointer to a host virtual N_Port data structure.
4314 *
4315 * This routine cleans up any Registration State Change Notification
4316 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4317 * @vport together with the host_lock is used to prevent multiple thread
4318 * trying to access the RSCN array on a same @vport at the same time.
4319 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004320void
James Smart2e0fef82007-06-17 19:56:36 -05004321lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004322{
James Smart2e0fef82007-06-17 19:56:36 -05004323 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4324 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004325 int i;
4326
James Smart7f5f3d02008-02-08 18:50:14 -05004327 spin_lock_irq(shost->host_lock);
4328 if (vport->fc_rscn_flush) {
4329 /* Another thread is walking fc_rscn_id_list on this vport */
4330 spin_unlock_irq(shost->host_lock);
4331 return;
4332 }
4333 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4334 vport->fc_rscn_flush = 1;
4335 spin_unlock_irq(shost->host_lock);
4336
James Smart2e0fef82007-06-17 19:56:36 -05004337 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004338 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004339 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004340 }
James Smart2e0fef82007-06-17 19:56:36 -05004341 spin_lock_irq(shost->host_lock);
4342 vport->fc_rscn_id_cnt = 0;
4343 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4344 spin_unlock_irq(shost->host_lock);
4345 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004346 /* Indicate we are done walking this fc_rscn_id_list */
4347 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004348}
4349
James Smarte59058c2008-08-24 21:49:00 -04004350/**
James Smart3621a712009-04-06 18:47:14 -04004351 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004352 * @vport: pointer to a host virtual N_Port data structure.
4353 * @did: remote destination port identifier.
4354 *
4355 * This routine checks whether there is any pending Registration State
4356 * Configuration Notification (RSCN) to a @did on @vport.
4357 *
4358 * Return code
4359 * None zero - The @did matched with a pending rscn
4360 * 0 - not able to match @did with a pending rscn
4361 **/
dea31012005-04-17 16:05:31 -05004362int
James Smart2e0fef82007-06-17 19:56:36 -05004363lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004364{
4365 D_ID ns_did;
4366 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004367 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004368 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004369 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004370
4371 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004372
4373 /* Never match fabric nodes for RSCNs */
4374 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004375 return 0;
dea31012005-04-17 16:05:31 -05004376
4377 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004378 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004379 return did;
dea31012005-04-17 16:05:31 -05004380
James Smart7f5f3d02008-02-08 18:50:14 -05004381 spin_lock_irq(shost->host_lock);
4382 if (vport->fc_rscn_flush) {
4383 /* Another thread is walking fc_rscn_id_list on this vport */
4384 spin_unlock_irq(shost->host_lock);
4385 return 0;
4386 }
4387 /* Indicate we are walking fc_rscn_id_list on this vport */
4388 vport->fc_rscn_flush = 1;
4389 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004390 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004391 lp = vport->fc_rscn_id_list[i]->virt;
4392 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4393 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004394 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004395 rscn_did.un.word = be32_to_cpu(*lp++);
4396 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004397 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4398 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004399 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4400 && (ns_did.un.b.area == rscn_did.un.b.area)
4401 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004402 goto return_did_out;
dea31012005-04-17 16:05:31 -05004403 break;
James Smarteaf15d52008-12-04 22:39:29 -05004404 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004405 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4406 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004407 goto return_did_out;
dea31012005-04-17 16:05:31 -05004408 break;
James Smarteaf15d52008-12-04 22:39:29 -05004409 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004410 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004411 goto return_did_out;
dea31012005-04-17 16:05:31 -05004412 break;
James Smarteaf15d52008-12-04 22:39:29 -05004413 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004414 goto return_did_out;
dea31012005-04-17 16:05:31 -05004415 }
4416 }
James Smart92d7f7b2007-06-17 19:56:38 -05004417 }
James Smart7f5f3d02008-02-08 18:50:14 -05004418 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4419 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004420 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004421return_did_out:
4422 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4423 vport->fc_rscn_flush = 0;
4424 return did;
dea31012005-04-17 16:05:31 -05004425}
4426
James Smarte59058c2008-08-24 21:49:00 -04004427/**
James Smart3621a712009-04-06 18:47:14 -04004428 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004429 * @vport: pointer to a host virtual N_Port data structure.
4430 *
4431 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4432 * state machine for a @vport's nodes that are with pending RSCN (Registration
4433 * State Change Notification).
4434 *
4435 * Return code
4436 * 0 - Successful (currently alway return 0)
4437 **/
dea31012005-04-17 16:05:31 -05004438static int
James Smart2e0fef82007-06-17 19:56:36 -05004439lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004440{
James Smart685f0bf2007-04-25 09:53:08 -04004441 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004442
James Smart0d2b6b82008-06-14 22:52:47 -04004443 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004444 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004445 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004446 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4447 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004448 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004449 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004450 NLP_EVT_DEVICE_RECOVERY);
4451 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004452 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004453 return 0;
dea31012005-04-17 16:05:31 -05004454}
4455
James Smarte59058c2008-08-24 21:49:00 -04004456/**
James Smart3621a712009-04-06 18:47:14 -04004457 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004458 * @vport: pointer to a host virtual N_Port data structure.
4459 * @cmdiocb: pointer to lpfc command iocb data structure.
4460 *
4461 * lpfc_send_rscn_event sends an RSCN netlink event to management
4462 * applications.
4463 */
4464static void
4465lpfc_send_rscn_event(struct lpfc_vport *vport,
4466 struct lpfc_iocbq *cmdiocb)
4467{
4468 struct lpfc_dmabuf *pcmd;
4469 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4470 uint32_t *payload_ptr;
4471 uint32_t payload_len;
4472 struct lpfc_rscn_event_header *rscn_event_data;
4473
4474 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4475 payload_ptr = (uint32_t *) pcmd->virt;
4476 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4477
4478 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4479 payload_len, GFP_KERNEL);
4480 if (!rscn_event_data) {
4481 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4482 "0147 Failed to allocate memory for RSCN event\n");
4483 return;
4484 }
4485 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4486 rscn_event_data->payload_length = payload_len;
4487 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4488 payload_len);
4489
4490 fc_host_post_vendor_event(shost,
4491 fc_get_event_number(),
4492 sizeof(struct lpfc_els_event_header) + payload_len,
4493 (char *)rscn_event_data,
4494 LPFC_NL_VENDOR_ID);
4495
4496 kfree(rscn_event_data);
4497}
4498
4499/**
James Smart3621a712009-04-06 18:47:14 -04004500 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004501 * @vport: pointer to a host virtual N_Port data structure.
4502 * @cmdiocb: pointer to lpfc command iocb data structure.
4503 * @ndlp: pointer to a node-list data structure.
4504 *
4505 * This routine processes an unsolicited RSCN (Registration State Change
4506 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4507 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4508 * discover state machine is about to begin discovery, it just accepts the
4509 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4510 * contains N_Port IDs for other vports on this HBA, it just accepts the
4511 * RSCN and ignore processing it. If the state machine is in the recovery
4512 * state, the fc_rscn_id_list of this @vport is walked and the
4513 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4514 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4515 * routine is invoked to handle the RSCN event.
4516 *
4517 * Return code
4518 * 0 - Just sent the acc response
4519 * 1 - Sent the acc response and waited for name server completion
4520 **/
dea31012005-04-17 16:05:31 -05004521static int
James Smart2e0fef82007-06-17 19:56:36 -05004522lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004523 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004524{
James Smart2e0fef82007-06-17 19:56:36 -05004525 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4526 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004527 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004528 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004529 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004530 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004531 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004532 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004533 int i;
dea31012005-04-17 16:05:31 -05004534
4535 icmd = &cmdiocb->iocb;
4536 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4537 lp = (uint32_t *) pcmd->virt;
4538
James Smart92d7f7b2007-06-17 19:56:38 -05004539 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4540 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004541 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004542 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4543 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004544 vport->fc_flag, payload_len, *lp,
4545 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004546
4547 /* Send an RSCN event to the management application */
4548 lpfc_send_rscn_event(vport, cmdiocb);
4549
James Smartd2873e42006-08-18 17:46:43 -04004550 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004551 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004552 FCH_EVT_RSCN, lp[i]);
4553
dea31012005-04-17 16:05:31 -05004554 /* If we are about to begin discovery, just ACC the RSCN.
4555 * Discovery processing will satisfy it.
4556 */
James Smart2e0fef82007-06-17 19:56:36 -05004557 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004558 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4559 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4560 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4561
James Smart51ef4c22007-08-02 11:10:31 -04004562 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004563 return 0;
dea31012005-04-17 16:05:31 -05004564 }
4565
James Smart92d7f7b2007-06-17 19:56:38 -05004566 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4567 * just ACC and ignore it.
4568 */
4569 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004570 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004571 i = payload_len;
4572 datap = lp;
4573 while (i > 0) {
4574 nportid = *datap++;
4575 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4576 i -= sizeof(uint32_t);
4577 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004578 if (lpfc_find_vport_by_did(phba, nportid))
4579 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004580 }
4581 if (rscn_id == hba_id) {
4582 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004583 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004584 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004585 "Data: x%x x%x x%x x%x\n",
4586 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004587 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004588 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4589 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4590 ndlp->nlp_DID, vport->port_state,
4591 ndlp->nlp_flag);
4592
James Smart92d7f7b2007-06-17 19:56:38 -05004593 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004594 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004595 return 0;
4596 }
4597 }
4598
James Smart7f5f3d02008-02-08 18:50:14 -05004599 spin_lock_irq(shost->host_lock);
4600 if (vport->fc_rscn_flush) {
4601 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004602 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004603 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004604 /* Send back ACC */
4605 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004606 return 0;
4607 }
4608 /* Indicate we are walking fc_rscn_id_list on this vport */
4609 vport->fc_rscn_flush = 1;
4610 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004611 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004612 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004613 /* If we are already processing an RSCN, save the received
4614 * RSCN payload buffer, cmdiocb->context2 to process later.
4615 */
James Smart2e0fef82007-06-17 19:56:36 -05004616 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004617 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4618 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4619 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4620
James Smart09372822008-01-11 01:52:54 -05004621 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004622 vport->fc_flag |= FC_RSCN_DEFERRED;
4623 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004624 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004625 vport->fc_flag |= FC_RSCN_MODE;
4626 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004627 if (rscn_cnt) {
4628 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4629 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4630 }
4631 if ((rscn_cnt) &&
4632 (payload_len + length <= LPFC_BPL_SIZE)) {
4633 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004634 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004635 memcpy(((uint8_t *)cmd) + length, lp,
4636 payload_len);
4637 } else {
4638 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4639 vport->fc_rscn_id_cnt++;
4640 /* If we zero, cmdiocb->context2, the calling
4641 * routine will not try to free it.
4642 */
4643 cmdiocb->context2 = NULL;
4644 }
dea31012005-04-17 16:05:31 -05004645 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004646 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4647 "0235 Deferred RSCN "
4648 "Data: x%x x%x x%x\n",
4649 vport->fc_rscn_id_cnt, vport->fc_flag,
4650 vport->port_state);
dea31012005-04-17 16:05:31 -05004651 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004652 vport->fc_flag |= FC_RSCN_DISCOVERY;
4653 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004654 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004655 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4656 "0234 ReDiscovery RSCN "
4657 "Data: x%x x%x x%x\n",
4658 vport->fc_rscn_id_cnt, vport->fc_flag,
4659 vport->port_state);
dea31012005-04-17 16:05:31 -05004660 }
James Smart7f5f3d02008-02-08 18:50:14 -05004661 /* Indicate we are done walking fc_rscn_id_list on this vport */
4662 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004663 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004664 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004665 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004666 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004667 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004668 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004669 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004670 return 0;
dea31012005-04-17 16:05:31 -05004671 }
James Smart858c9f62007-06-17 19:56:39 -05004672 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4673 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4674 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4675
James Smart2e0fef82007-06-17 19:56:36 -05004676 spin_lock_irq(shost->host_lock);
4677 vport->fc_flag |= FC_RSCN_MODE;
4678 spin_unlock_irq(shost->host_lock);
4679 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004680 /* Indicate we are done walking fc_rscn_id_list on this vport */
4681 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004682 /*
4683 * If we zero, cmdiocb->context2, the calling routine will
4684 * not try to free it.
4685 */
4686 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004687 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004688 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004689 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004690 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004691 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004692 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004693}
4694
James Smarte59058c2008-08-24 21:49:00 -04004695/**
James Smart3621a712009-04-06 18:47:14 -04004696 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004697 * @vport: pointer to a host virtual N_Port data structure.
4698 *
4699 * This routine handles the Registration State Configuration Notification
4700 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4701 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4702 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4703 * NameServer shall be issued. If CT command to the NameServer fails to be
4704 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4705 * RSCN activities with the @vport.
4706 *
4707 * Return code
4708 * 0 - Cleaned up rscn on the @vport
4709 * 1 - Wait for plogi to name server before proceed
4710 **/
dea31012005-04-17 16:05:31 -05004711int
James Smart2e0fef82007-06-17 19:56:36 -05004712lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004713{
4714 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004715 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004716
James Smart92d7f7b2007-06-17 19:56:38 -05004717 /* Ignore RSCN if the port is being torn down. */
4718 if (vport->load_flag & FC_UNLOADING) {
4719 lpfc_els_flush_rscn(vport);
4720 return 0;
4721 }
4722
dea31012005-04-17 16:05:31 -05004723 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004724 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004725
4726 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004727 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4728 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4729 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4730 vport->port_state);
dea31012005-04-17 16:05:31 -05004731
4732 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004733 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004734 vport->num_disc_nodes = 0;
4735
James Smart2e0fef82007-06-17 19:56:36 -05004736 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004737 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4738 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004739 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004740 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004741 /* Wait for NameServer query cmpl before we can
4742 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004743 return 1;
dea31012005-04-17 16:05:31 -05004744 } else {
4745 /* If login to NameServer does not exist, issue one */
4746 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004747 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004748 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004749 /* Wait for NameServer login cmpl before we can
4750 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004751 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004752
James Smarte47c9092008-02-08 18:49:26 -05004753 if (ndlp) {
4754 ndlp = lpfc_enable_node(vport, ndlp,
4755 NLP_STE_PLOGI_ISSUE);
4756 if (!ndlp) {
4757 lpfc_els_flush_rscn(vport);
4758 return 0;
4759 }
4760 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004761 } else {
James Smarte47c9092008-02-08 18:49:26 -05004762 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4763 if (!ndlp) {
4764 lpfc_els_flush_rscn(vport);
4765 return 0;
4766 }
James Smart2e0fef82007-06-17 19:56:36 -05004767 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004768 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004769 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004770 }
James Smarte47c9092008-02-08 18:49:26 -05004771 ndlp->nlp_type |= NLP_FABRIC;
4772 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4773 /* Wait for NameServer login cmpl before we can
4774 * continue
4775 */
4776 return 1;
dea31012005-04-17 16:05:31 -05004777 }
4778
James Smart2e0fef82007-06-17 19:56:36 -05004779 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004780 return 0;
dea31012005-04-17 16:05:31 -05004781}
4782
James Smarte59058c2008-08-24 21:49:00 -04004783/**
James Smart3621a712009-04-06 18:47:14 -04004784 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004785 * @vport: pointer to a host virtual N_Port data structure.
4786 * @cmdiocb: pointer to lpfc command iocb data structure.
4787 * @ndlp: pointer to a node-list data structure.
4788 *
4789 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4790 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4791 * point topology. As an unsolicited FLOGI should not be received in a loop
4792 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4793 * lpfc_check_sparm() routine is invoked to check the parameters in the
4794 * unsolicited FLOGI. If parameters validation failed, the routine
4795 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4796 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4797 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4798 * will initiate PLOGI. The higher lexicographical value party shall has
4799 * higher priority (as the winning port) and will initiate PLOGI and
4800 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4801 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4802 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4803 *
4804 * Return code
4805 * 0 - Successfully processed the unsolicited flogi
4806 * 1 - Failed to process the unsolicited flogi
4807 **/
dea31012005-04-17 16:05:31 -05004808static int
James Smart2e0fef82007-06-17 19:56:36 -05004809lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004810 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004811{
James Smart2e0fef82007-06-17 19:56:36 -05004812 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4813 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004814 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4815 uint32_t *lp = (uint32_t *) pcmd->virt;
4816 IOCB_t *icmd = &cmdiocb->iocb;
4817 struct serv_parm *sp;
4818 LPFC_MBOXQ_t *mbox;
4819 struct ls_rjt stat;
4820 uint32_t cmd, did;
4821 int rc;
4822
4823 cmd = *lp++;
4824 sp = (struct serv_parm *) lp;
4825
4826 /* FLOGI received */
4827
James Smart2e0fef82007-06-17 19:56:36 -05004828 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004829
James Smart76a95d72010-11-20 23:11:48 -05004830 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004831 /* We should never receive a FLOGI in loop mode, ignore it */
4832 did = icmd->un.elsreq64.remoteID;
4833
4834 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4835 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004836 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4837 "0113 An FLOGI ELS command x%x was "
4838 "received from DID x%x in Loop Mode\n",
4839 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004840 return 1;
dea31012005-04-17 16:05:31 -05004841 }
4842
4843 did = Fabric_DID;
4844
James Smart341af102010-01-26 23:07:37 -05004845 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004846 /* For a FLOGI we accept, then if our portname is greater
4847 * then the remote portname we initiate Nport login.
4848 */
4849
James Smart2e0fef82007-06-17 19:56:36 -05004850 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004851 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004852
4853 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004854 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4855 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004856 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004857
dea31012005-04-17 16:05:31 -05004858 lpfc_linkdown(phba);
4859 lpfc_init_link(phba, mbox,
4860 phba->cfg_topology,
4861 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004862 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004863 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004864 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004865 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004866 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004867 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004868 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004869 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004870 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004871 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004872 spin_lock_irq(shost->host_lock);
4873 vport->fc_flag |= FC_PT2PT_PLOGI;
4874 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004875 }
James Smart2e0fef82007-06-17 19:56:36 -05004876 spin_lock_irq(shost->host_lock);
4877 vport->fc_flag |= FC_PT2PT;
4878 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4879 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004880 } else {
4881 /* Reject this request because invalid parameters */
4882 stat.un.b.lsRjtRsvd0 = 0;
4883 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4884 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4885 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004886 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4887 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004888 return 1;
dea31012005-04-17 16:05:31 -05004889 }
4890
4891 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004892 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004893
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004894 return 0;
dea31012005-04-17 16:05:31 -05004895}
4896
James Smarte59058c2008-08-24 21:49:00 -04004897/**
James Smart3621a712009-04-06 18:47:14 -04004898 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004899 * @vport: pointer to a host virtual N_Port data structure.
4900 * @cmdiocb: pointer to lpfc command iocb data structure.
4901 * @ndlp: pointer to a node-list data structure.
4902 *
4903 * This routine processes Request Node Identification Data (RNID) IOCB
4904 * received as an ELS unsolicited event. Only when the RNID specified format
4905 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4906 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4907 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4908 * rejected by invoking the lpfc_els_rsp_reject() routine.
4909 *
4910 * Return code
4911 * 0 - Successfully processed rnid iocb (currently always return 0)
4912 **/
dea31012005-04-17 16:05:31 -05004913static int
James Smart2e0fef82007-06-17 19:56:36 -05004914lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4915 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004916{
4917 struct lpfc_dmabuf *pcmd;
4918 uint32_t *lp;
4919 IOCB_t *icmd;
4920 RNID *rn;
4921 struct ls_rjt stat;
4922 uint32_t cmd, did;
4923
4924 icmd = &cmdiocb->iocb;
4925 did = icmd->un.elsreq64.remoteID;
4926 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4927 lp = (uint32_t *) pcmd->virt;
4928
4929 cmd = *lp++;
4930 rn = (RNID *) lp;
4931
4932 /* RNID received */
4933
4934 switch (rn->Format) {
4935 case 0:
4936 case RNID_TOPOLOGY_DISC:
4937 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004938 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004939 break;
4940 default:
4941 /* Reject this request because format not supported */
4942 stat.un.b.lsRjtRsvd0 = 0;
4943 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4944 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4945 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004946 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4947 NULL);
dea31012005-04-17 16:05:31 -05004948 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004949 return 0;
dea31012005-04-17 16:05:31 -05004950}
4951
James Smarte59058c2008-08-24 21:49:00 -04004952/**
James Smart12265f62010-10-22 11:05:53 -04004953 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4954 * @vport: pointer to a host virtual N_Port data structure.
4955 * @cmdiocb: pointer to lpfc command iocb data structure.
4956 * @ndlp: pointer to a node-list data structure.
4957 *
4958 * Return code
4959 * 0 - Successfully processed echo iocb (currently always return 0)
4960 **/
4961static int
4962lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4963 struct lpfc_nodelist *ndlp)
4964{
4965 uint8_t *pcmd;
4966
4967 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4968
4969 /* skip over first word of echo command to find echo data */
4970 pcmd += sizeof(uint32_t);
4971
4972 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
4973 return 0;
4974}
4975
4976/**
James Smart3621a712009-04-06 18:47:14 -04004977 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004978 * @vport: pointer to a host virtual N_Port data structure.
4979 * @cmdiocb: pointer to lpfc command iocb data structure.
4980 * @ndlp: pointer to a node-list data structure.
4981 *
4982 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4983 * received as an ELS unsolicited event. Currently, this function just invokes
4984 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4985 *
4986 * Return code
4987 * 0 - Successfully processed lirr iocb (currently always return 0)
4988 **/
dea31012005-04-17 16:05:31 -05004989static int
James Smart2e0fef82007-06-17 19:56:36 -05004990lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4991 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004992{
4993 struct ls_rjt stat;
4994
4995 /* For now, unconditionally reject this command */
4996 stat.un.b.lsRjtRsvd0 = 0;
4997 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4998 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4999 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005000 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005001 return 0;
5002}
5003
James Smarte59058c2008-08-24 21:49:00 -04005004/**
James Smart5ffc2662009-11-18 15:39:44 -05005005 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5006 * @vport: pointer to a host virtual N_Port data structure.
5007 * @cmdiocb: pointer to lpfc command iocb data structure.
5008 * @ndlp: pointer to a node-list data structure.
5009 *
5010 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5011 * received as an ELS unsolicited event. A request to RRQ shall only
5012 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5013 * Nx_Port N_Port_ID of the target Exchange is the same as the
5014 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5015 * not accepted, an LS_RJT with reason code "Unable to perform
5016 * command request" and reason code explanation "Invalid Originator
5017 * S_ID" shall be returned. For now, we just unconditionally accept
5018 * RRQ from the target.
5019 **/
5020static void
5021lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5022 struct lpfc_nodelist *ndlp)
5023{
5024 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05005025 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5026 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05005027}
5028
5029/**
James Smart12265f62010-10-22 11:05:53 -04005030 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5031 * @phba: pointer to lpfc hba data structure.
5032 * @pmb: pointer to the driver internal queue element for mailbox command.
5033 *
5034 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5035 * mailbox command. This callback function is to actually send the Accept
5036 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5037 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5038 * mailbox command, constructs the RPS response with the link statistics
5039 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5040 * response to the RPS.
5041 *
5042 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5043 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5044 * will be stored into the context1 field of the IOCB for the completion
5045 * callback function to the RPS Accept Response ELS IOCB command.
5046 *
5047 **/
5048static void
5049lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5050{
5051 MAILBOX_t *mb;
5052 IOCB_t *icmd;
5053 struct RLS_RSP *rls_rsp;
5054 uint8_t *pcmd;
5055 struct lpfc_iocbq *elsiocb;
5056 struct lpfc_nodelist *ndlp;
5057 uint16_t xri;
5058 uint32_t cmdsize;
5059
5060 mb = &pmb->u.mb;
5061
5062 ndlp = (struct lpfc_nodelist *) pmb->context2;
5063 xri = (uint16_t) ((unsigned long)(pmb->context1));
5064 pmb->context1 = NULL;
5065 pmb->context2 = NULL;
5066
5067 if (mb->mbxStatus) {
5068 mempool_free(pmb, phba->mbox_mem_pool);
5069 return;
5070 }
5071
5072 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
5073 mempool_free(pmb, phba->mbox_mem_pool);
5074 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5075 lpfc_max_els_tries, ndlp,
5076 ndlp->nlp_DID, ELS_CMD_ACC);
5077
5078 /* Decrement the ndlp reference count from previous mbox command */
5079 lpfc_nlp_put(ndlp);
5080
5081 if (!elsiocb)
5082 return;
5083
5084 icmd = &elsiocb->iocb;
5085 icmd->ulpContext = xri;
5086
5087 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5088 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5089 pcmd += sizeof(uint32_t); /* Skip past command */
5090 rls_rsp = (struct RLS_RSP *)pcmd;
5091
5092 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5093 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5094 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5095 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5096 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5097 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
5098
5099 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5100 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5101 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5102 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5103 elsiocb->iotag, elsiocb->iocb.ulpContext,
5104 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5105 ndlp->nlp_rpi);
5106 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5107 phba->fc_stat.elsXmitACC++;
5108 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5109 lpfc_els_free_iocb(phba, elsiocb);
5110}
5111
5112/**
James Smart3621a712009-04-06 18:47:14 -04005113 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005114 * @phba: pointer to lpfc hba data structure.
5115 * @pmb: pointer to the driver internal queue element for mailbox command.
5116 *
5117 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5118 * mailbox command. This callback function is to actually send the Accept
5119 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5120 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5121 * mailbox command, constructs the RPS response with the link statistics
5122 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5123 * response to the RPS.
5124 *
5125 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5126 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5127 * will be stored into the context1 field of the IOCB for the completion
5128 * callback function to the RPS Accept Response ELS IOCB command.
5129 *
5130 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005131static void
James Smart329f9bc2007-04-25 09:53:01 -04005132lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005133{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005134 MAILBOX_t *mb;
5135 IOCB_t *icmd;
5136 RPS_RSP *rps_rsp;
5137 uint8_t *pcmd;
5138 struct lpfc_iocbq *elsiocb;
5139 struct lpfc_nodelist *ndlp;
5140 uint16_t xri, status;
5141 uint32_t cmdsize;
5142
James Smart04c68492009-05-22 14:52:52 -04005143 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005144
5145 ndlp = (struct lpfc_nodelist *) pmb->context2;
5146 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07005147 pmb->context1 = NULL;
5148 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005149
5150 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005151 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005152 return;
5153 }
5154
5155 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005156 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005157 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5158 lpfc_max_els_tries, ndlp,
5159 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005160
5161 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005162 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005163
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005164 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005165 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005166
5167 icmd = &elsiocb->iocb;
5168 icmd->ulpContext = xri;
5169
5170 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5171 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005172 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005173 rps_rsp = (RPS_RSP *)pcmd;
5174
James Smart76a95d72010-11-20 23:11:48 -05005175 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005176 status = 0x10;
5177 else
5178 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005179 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005180 status |= 0x4;
5181
5182 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005183 rps_rsp->portStatus = cpu_to_be16(status);
5184 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5185 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5186 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5187 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5188 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5189 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005190 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005191 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5192 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5193 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5194 elsiocb->iotag, elsiocb->iocb.ulpContext,
5195 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5196 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005197 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005198 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005199 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005200 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005201 return;
5202}
5203
James Smarte59058c2008-08-24 21:49:00 -04005204/**
James Smart12265f62010-10-22 11:05:53 -04005205 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5206 * @vport: pointer to a host virtual N_Port data structure.
5207 * @cmdiocb: pointer to lpfc command iocb data structure.
5208 * @ndlp: pointer to a node-list data structure.
5209 *
5210 * This routine processes Read Port Status (RPL) IOCB received as an
5211 * ELS unsolicited event. It first checks the remote port state. If the
5212 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5213 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5214 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5215 * for reading the HBA link statistics. It is for the callback function,
5216 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5217 * to actually sending out RPL Accept (ACC) response.
5218 *
5219 * Return codes
5220 * 0 - Successfully processed rls iocb (currently always return 0)
5221 **/
5222static int
5223lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5224 struct lpfc_nodelist *ndlp)
5225{
5226 struct lpfc_hba *phba = vport->phba;
5227 LPFC_MBOXQ_t *mbox;
5228 struct lpfc_dmabuf *pcmd;
5229 struct ls_rjt stat;
5230
5231 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5232 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5233 /* reject the unsolicited RPS request and done with it */
5234 goto reject_out;
5235
5236 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5237
5238 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5239 if (mbox) {
5240 lpfc_read_lnk_stat(phba, mbox);
5241 mbox->context1 =
5242 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
5243 mbox->context2 = lpfc_nlp_get(ndlp);
5244 mbox->vport = vport;
5245 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5246 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5247 != MBX_NOT_FINISHED)
5248 /* Mbox completion will send ELS Response */
5249 return 0;
5250 /* Decrement reference count used for the failed mbox
5251 * command.
5252 */
5253 lpfc_nlp_put(ndlp);
5254 mempool_free(mbox, phba->mbox_mem_pool);
5255 }
5256reject_out:
5257 /* issue rejection response */
5258 stat.un.b.lsRjtRsvd0 = 0;
5259 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5260 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5261 stat.un.b.vendorUnique = 0;
5262 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5263 return 0;
5264}
5265
5266/**
5267 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5268 * @vport: pointer to a host virtual N_Port data structure.
5269 * @cmdiocb: pointer to lpfc command iocb data structure.
5270 * @ndlp: pointer to a node-list data structure.
5271 *
5272 * This routine processes Read Timout Value (RTV) IOCB received as an
5273 * ELS unsolicited event. It first checks the remote port state. If the
5274 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5275 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5276 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5277 * Value (RTV) unsolicited IOCB event.
5278 *
5279 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5280 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5281 * will be stored into the context1 field of the IOCB for the completion
5282 * callback function to the RPS Accept Response ELS IOCB command.
5283 *
5284 * Return codes
5285 * 0 - Successfully processed rtv iocb (currently always return 0)
5286 **/
5287static int
5288lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5289 struct lpfc_nodelist *ndlp)
5290{
5291 struct lpfc_hba *phba = vport->phba;
5292 struct ls_rjt stat;
5293 struct RTV_RSP *rtv_rsp;
5294 uint8_t *pcmd;
5295 struct lpfc_iocbq *elsiocb;
5296 uint32_t cmdsize;
5297
5298
5299 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5300 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5301 /* reject the unsolicited RPS request and done with it */
5302 goto reject_out;
5303
5304 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5305 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5306 lpfc_max_els_tries, ndlp,
5307 ndlp->nlp_DID, ELS_CMD_ACC);
5308
5309 if (!elsiocb)
5310 return 1;
5311
5312 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5313 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5314 pcmd += sizeof(uint32_t); /* Skip past command */
5315
5316 /* use the command's xri in the response */
5317 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext;
5318
5319 rtv_rsp = (struct RTV_RSP *)pcmd;
5320
5321 /* populate RTV payload */
5322 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5323 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5324 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5325 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5326 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5327
5328 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5329 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5330 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5331 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5332 "Data: x%x x%x x%x\n",
5333 elsiocb->iotag, elsiocb->iocb.ulpContext,
5334 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5335 ndlp->nlp_rpi,
5336 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5337 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5338 phba->fc_stat.elsXmitACC++;
5339 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5340 lpfc_els_free_iocb(phba, elsiocb);
5341 return 0;
5342
5343reject_out:
5344 /* issue rejection response */
5345 stat.un.b.lsRjtRsvd0 = 0;
5346 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5347 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5348 stat.un.b.vendorUnique = 0;
5349 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5350 return 0;
5351}
5352
5353/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005354 * @vport: pointer to a host virtual N_Port data structure.
5355 * @cmdiocb: pointer to lpfc command iocb data structure.
5356 * @ndlp: pointer to a node-list data structure.
5357 *
5358 * This routine processes Read Port Status (RPS) IOCB received as an
5359 * ELS unsolicited event. It first checks the remote port state. If the
5360 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5361 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5362 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5363 * for reading the HBA link statistics. It is for the callback function,
5364 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5365 * to actually sending out RPS Accept (ACC) response.
5366 *
5367 * Return codes
5368 * 0 - Successfully processed rps iocb (currently always return 0)
5369 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005370static int
James Smart2e0fef82007-06-17 19:56:36 -05005371lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5372 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005373{
James Smart2e0fef82007-06-17 19:56:36 -05005374 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005375 uint32_t *lp;
5376 uint8_t flag;
5377 LPFC_MBOXQ_t *mbox;
5378 struct lpfc_dmabuf *pcmd;
5379 RPS *rps;
5380 struct ls_rjt stat;
5381
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005382 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005383 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5384 /* reject the unsolicited RPS request and done with it */
5385 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005386
5387 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5388 lp = (uint32_t *) pcmd->virt;
5389 flag = (be32_to_cpu(*lp++) & 0xf);
5390 rps = (RPS *) lp;
5391
5392 if ((flag == 0) ||
5393 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005394 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005395 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005396
James Smart92d7f7b2007-06-17 19:56:38 -05005397 printk("Fix me....\n");
5398 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005399 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5400 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005401 lpfc_read_lnk_stat(phba, mbox);
5402 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05005403 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04005404 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005405 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005406 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005407 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005408 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005409 /* Mbox completion will send ELS Response */
5410 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005411 /* Decrement reference count used for the failed mbox
5412 * command.
5413 */
James Smart329f9bc2007-04-25 09:53:01 -04005414 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005415 mempool_free(mbox, phba->mbox_mem_pool);
5416 }
5417 }
James Smart90160e02008-08-24 21:49:45 -04005418
5419reject_out:
5420 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005421 stat.un.b.lsRjtRsvd0 = 0;
5422 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5423 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5424 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005425 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005426 return 0;
5427}
5428
James Smart19ca7602010-11-20 23:11:55 -05005429/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5430 * @vport: pointer to a host virtual N_Port data structure.
5431 * @ndlp: pointer to a node-list data structure.
5432 * @did: DID of the target.
5433 * @rrq: Pointer to the rrq struct.
5434 *
5435 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5436 * Successful the the completion handler will clear the RRQ.
5437 *
5438 * Return codes
5439 * 0 - Successfully sent rrq els iocb.
5440 * 1 - Failed to send rrq els iocb.
5441 **/
5442static int
5443lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5444 uint32_t did, struct lpfc_node_rrq *rrq)
5445{
5446 struct lpfc_hba *phba = vport->phba;
5447 struct RRQ *els_rrq;
5448 IOCB_t *icmd;
5449 struct lpfc_iocbq *elsiocb;
5450 uint8_t *pcmd;
5451 uint16_t cmdsize;
5452 int ret;
5453
5454
5455 if (ndlp != rrq->ndlp)
5456 ndlp = rrq->ndlp;
5457 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5458 return 1;
5459
5460 /* If ndlp is not NULL, we will bump the reference count on it */
5461 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5462 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5463 ELS_CMD_RRQ);
5464 if (!elsiocb)
5465 return 1;
5466
5467 icmd = &elsiocb->iocb;
5468 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5469
5470 /* For RRQ request, remainder of payload is Exchange IDs */
5471 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5472 pcmd += sizeof(uint32_t);
5473 els_rrq = (struct RRQ *) pcmd;
5474
5475 bf_set(rrq_oxid, els_rrq, rrq->xritag);
5476 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5477 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5478 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5479 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5480
5481
5482 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5483 "Issue RRQ: did:x%x",
5484 did, rrq->xritag, rrq->rxid);
5485 elsiocb->context_un.rrq = rrq;
5486 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5487 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5488
5489 if (ret == IOCB_ERROR) {
5490 lpfc_els_free_iocb(phba, elsiocb);
5491 return 1;
5492 }
5493 return 0;
5494}
5495
5496/**
5497 * lpfc_send_rrq - Sends ELS RRQ if needed.
5498 * @phba: pointer to lpfc hba data structure.
5499 * @rrq: pointer to the active rrq.
5500 *
5501 * This routine will call the lpfc_issue_els_rrq if the rrq is
5502 * still active for the xri. If this function returns a failure then
5503 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5504 *
5505 * Returns 0 Success.
5506 * 1 Failure.
5507 **/
5508int
5509lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5510{
5511 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5512 rrq->nlp_DID);
5513 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5514 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5515 rrq->nlp_DID, rrq);
5516 else
5517 return 1;
5518}
5519
James Smarte59058c2008-08-24 21:49:00 -04005520/**
James Smart3621a712009-04-06 18:47:14 -04005521 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005522 * @vport: pointer to a host virtual N_Port data structure.
5523 * @cmdsize: size of the ELS command.
5524 * @oldiocb: pointer to the original lpfc command iocb data structure.
5525 * @ndlp: pointer to a node-list data structure.
5526 *
5527 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5528 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5529 *
5530 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5531 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5532 * will be stored into the context1 field of the IOCB for the completion
5533 * callback function to the RPL Accept Response ELS command.
5534 *
5535 * Return code
5536 * 0 - Successfully issued ACC RPL ELS command
5537 * 1 - Failed to issue ACC RPL ELS command
5538 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005539static int
James Smart2e0fef82007-06-17 19:56:36 -05005540lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5541 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005542{
James Smart2e0fef82007-06-17 19:56:36 -05005543 struct lpfc_hba *phba = vport->phba;
5544 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005545 RPL_RSP rpl_rsp;
5546 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005547 uint8_t *pcmd;
5548
James Smart2e0fef82007-06-17 19:56:36 -05005549 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5550 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005551
James Smart488d1462006-03-07 15:02:37 -05005552 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005553 return 1;
James Smart488d1462006-03-07 15:02:37 -05005554
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005555 icmd = &elsiocb->iocb;
5556 oldcmd = &oldiocb->iocb;
5557 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
5558
5559 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5560 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005561 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005562 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5563 pcmd += sizeof(uint16_t);
5564
5565 /* Setup the RPL ACC payload */
5566 rpl_rsp.listLen = be32_to_cpu(1);
5567 rpl_rsp.index = 0;
5568 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005569 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5570 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005571 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005572 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005573 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005574 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5575 "0120 Xmit ELS RPL ACC response tag x%x "
5576 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5577 "rpi x%x\n",
5578 elsiocb->iotag, elsiocb->iocb.ulpContext,
5579 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5580 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005581 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005582 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005583 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5584 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005585 lpfc_els_free_iocb(phba, elsiocb);
5586 return 1;
5587 }
5588 return 0;
5589}
5590
James Smarte59058c2008-08-24 21:49:00 -04005591/**
James Smart3621a712009-04-06 18:47:14 -04005592 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005593 * @vport: pointer to a host virtual N_Port data structure.
5594 * @cmdiocb: pointer to lpfc command iocb data structure.
5595 * @ndlp: pointer to a node-list data structure.
5596 *
5597 * This routine processes Read Port List (RPL) IOCB received as an ELS
5598 * unsolicited event. It first checks the remote port state. If the remote
5599 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5600 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5601 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5602 * to accept the RPL.
5603 *
5604 * Return code
5605 * 0 - Successfully processed rpl iocb (currently always return 0)
5606 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005607static int
James Smart2e0fef82007-06-17 19:56:36 -05005608lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5609 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005610{
5611 struct lpfc_dmabuf *pcmd;
5612 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005613 uint32_t maxsize;
5614 uint16_t cmdsize;
5615 RPL *rpl;
5616 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005617
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005618 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5619 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005620 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005621 stat.un.b.lsRjtRsvd0 = 0;
5622 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5623 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5624 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005625 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5626 NULL);
James Smart90160e02008-08-24 21:49:45 -04005627 /* rejected the unsolicited RPL request and done with it */
5628 return 0;
dea31012005-04-17 16:05:31 -05005629 }
5630
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005631 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5632 lp = (uint32_t *) pcmd->virt;
5633 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005634 maxsize = be32_to_cpu(rpl->maxsize);
5635
5636 /* We support only one port */
5637 if ((rpl->index == 0) &&
5638 ((maxsize == 0) ||
5639 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5640 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005641 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005642 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5643 }
James Smart2e0fef82007-06-17 19:56:36 -05005644 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005645
5646 return 0;
5647}
5648
James Smarte59058c2008-08-24 21:49:00 -04005649/**
James Smart3621a712009-04-06 18:47:14 -04005650 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005651 * @vport: pointer to a virtual N_Port data structure.
5652 * @cmdiocb: pointer to lpfc command iocb data structure.
5653 * @ndlp: pointer to a node-list data structure.
5654 *
5655 * This routine processes Fibre Channel Address Resolution Protocol
5656 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5657 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5658 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5659 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5660 * remote PortName is compared against the FC PortName stored in the @vport
5661 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5662 * compared against the FC NodeName stored in the @vport data structure.
5663 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5664 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5665 * invoked to send out FARP Response to the remote node. Before sending the
5666 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5667 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5668 * routine is invoked to log into the remote port first.
5669 *
5670 * Return code
5671 * 0 - Either the FARP Match Mode not supported or successfully processed
5672 **/
dea31012005-04-17 16:05:31 -05005673static int
James Smart2e0fef82007-06-17 19:56:36 -05005674lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5675 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005676{
5677 struct lpfc_dmabuf *pcmd;
5678 uint32_t *lp;
5679 IOCB_t *icmd;
5680 FARP *fp;
5681 uint32_t cmd, cnt, did;
5682
5683 icmd = &cmdiocb->iocb;
5684 did = icmd->un.elsreq64.remoteID;
5685 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5686 lp = (uint32_t *) pcmd->virt;
5687
5688 cmd = *lp++;
5689 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005690 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005691 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5692 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005693 /* We will only support match on WWPN or WWNN */
5694 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005695 return 0;
dea31012005-04-17 16:05:31 -05005696 }
5697
5698 cnt = 0;
5699 /* If this FARP command is searching for my portname */
5700 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005701 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005702 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005703 cnt = 1;
5704 }
5705
5706 /* If this FARP command is searching for my nodename */
5707 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005708 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005709 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005710 cnt = 1;
5711 }
5712
5713 if (cnt) {
5714 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5715 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5716 /* Log back into the node before sending the FARP. */
5717 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005718 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005719 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005720 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005721 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005722 }
5723
5724 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005725 if (fp->Rflags & FARP_REQUEST_FARPR)
5726 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005727 }
5728 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005729 return 0;
dea31012005-04-17 16:05:31 -05005730}
5731
James Smarte59058c2008-08-24 21:49:00 -04005732/**
James Smart3621a712009-04-06 18:47:14 -04005733 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005734 * @vport: pointer to a host virtual N_Port data structure.
5735 * @cmdiocb: pointer to lpfc command iocb data structure.
5736 * @ndlp: pointer to a node-list data structure.
5737 *
5738 * This routine processes Fibre Channel Address Resolution Protocol
5739 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5740 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5741 * the FARP response request.
5742 *
5743 * Return code
5744 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5745 **/
dea31012005-04-17 16:05:31 -05005746static int
James Smart2e0fef82007-06-17 19:56:36 -05005747lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5748 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005749{
5750 struct lpfc_dmabuf *pcmd;
5751 uint32_t *lp;
5752 IOCB_t *icmd;
5753 uint32_t cmd, did;
5754
5755 icmd = &cmdiocb->iocb;
5756 did = icmd->un.elsreq64.remoteID;
5757 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5758 lp = (uint32_t *) pcmd->virt;
5759
5760 cmd = *lp++;
5761 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005762 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5763 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005764 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005765 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005766
5767 return 0;
5768}
5769
James Smarte59058c2008-08-24 21:49:00 -04005770/**
James Smart3621a712009-04-06 18:47:14 -04005771 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005772 * @vport: pointer to a host virtual N_Port data structure.
5773 * @cmdiocb: pointer to lpfc command iocb data structure.
5774 * @fan_ndlp: pointer to a node-list data structure.
5775 *
5776 * This routine processes a Fabric Address Notification (FAN) IOCB
5777 * command received as an ELS unsolicited event. The FAN ELS command will
5778 * only be processed on a physical port (i.e., the @vport represents the
5779 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5780 * compared against those in the phba data structure. If any of those is
5781 * different, the lpfc_initial_flogi() routine is invoked to initialize
5782 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5783 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5784 * is invoked to register login to the fabric.
5785 *
5786 * Return code
5787 * 0 - Successfully processed fan iocb (currently always return 0).
5788 **/
dea31012005-04-17 16:05:31 -05005789static int
James Smart2e0fef82007-06-17 19:56:36 -05005790lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5791 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005792{
James Smart2e0fef82007-06-17 19:56:36 -05005793 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005794 uint32_t *lp;
5795 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005796
James Smart0d2b6b82008-06-14 22:52:47 -04005797 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5798 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5799 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005800 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005801 if ((vport == phba->pport) &&
5802 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005803 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005804 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005805 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005806 sizeof(struct lpfc_name)))) {
5807 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05005808 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005809 } else {
5810 /* FAN verified - skip FLOGI */
5811 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005812 if (phba->sli_rev < LPFC_SLI_REV4)
5813 lpfc_issue_fabric_reglogin(vport);
5814 else
5815 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005816 }
dea31012005-04-17 16:05:31 -05005817 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005818 return 0;
dea31012005-04-17 16:05:31 -05005819}
5820
James Smarte59058c2008-08-24 21:49:00 -04005821/**
James Smart3621a712009-04-06 18:47:14 -04005822 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005823 * @ptr: holder for the timer function associated data.
5824 *
5825 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5826 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5827 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5828 * up the worker thread. It is for the worker thread to invoke the routine
5829 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5830 **/
dea31012005-04-17 16:05:31 -05005831void
5832lpfc_els_timeout(unsigned long ptr)
5833{
James Smart2e0fef82007-06-17 19:56:36 -05005834 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5835 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005836 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005837 unsigned long iflag;
5838
James Smart2e0fef82007-06-17 19:56:36 -05005839 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005840 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5841 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005842 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005843 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005844
James Smart5e9d9b82008-06-14 22:52:53 -04005845 if (!tmo_posted)
5846 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005847 return;
5848}
5849
James Smart2a9bf3d2010-06-07 15:24:45 -04005850
James Smarte59058c2008-08-24 21:49:00 -04005851/**
James Smart3621a712009-04-06 18:47:14 -04005852 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005853 * @vport: pointer to a virtual N_Port data structure.
5854 *
5855 * This routine is the actual handler function that processes an ELS timeout
5856 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5857 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5858 * invoking the lpfc_sli_issue_abort_iotag() routine.
5859 **/
dea31012005-04-17 16:05:31 -05005860void
James Smart2e0fef82007-06-17 19:56:36 -05005861lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005862{
James Smart2e0fef82007-06-17 19:56:36 -05005863 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005864 struct lpfc_sli_ring *pring;
5865 struct lpfc_iocbq *tmp_iocb, *piocb;
5866 IOCB_t *cmd = NULL;
5867 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005868 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005869 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005870 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005871 LIST_HEAD(txcmplq_completions);
5872 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005873
James Smart2a9bf3d2010-06-07 15:24:45 -04005874
dea31012005-04-17 16:05:31 -05005875 timeout = (uint32_t)(phba->fc_ratov << 1);
5876
5877 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005878
James Smart2a9bf3d2010-06-07 15:24:45 -04005879 spin_lock_irq(&phba->hbalock);
5880 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5881 spin_unlock_irq(&phba->hbalock);
5882
5883 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005884 cmd = &piocb->iocb;
5885
James Smart2e0fef82007-06-17 19:56:36 -05005886 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5887 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5888 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005889 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005890
5891 if (piocb->vport != vport)
5892 continue;
5893
dea31012005-04-17 16:05:31 -05005894 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005895 if (pcmd)
5896 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005897
James Smart92d7f7b2007-06-17 19:56:38 -05005898 if (els_command == ELS_CMD_FARP ||
5899 els_command == ELS_CMD_FARPR ||
5900 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005901 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005902
dea31012005-04-17 16:05:31 -05005903 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005904 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005905 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005906 else
dea31012005-04-17 16:05:31 -05005907 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005908 continue;
5909 }
5910
James Smart2e0fef82007-06-17 19:56:36 -05005911 remote_ID = 0xffffffff;
5912 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005913 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005914 else {
5915 struct lpfc_nodelist *ndlp;
5916 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005917 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005918 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005919 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005920 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05005921 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005922 spin_lock_irq(&phba->hbalock);
5923 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05005924 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005925
James Smart2a9bf3d2010-06-07 15:24:45 -04005926 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5927 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5928 "0127 ELS timeout Data: x%x x%x x%x "
5929 "x%x\n", els_command,
5930 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5931 spin_lock_irq(&phba->hbalock);
5932 list_del_init(&piocb->dlist);
5933 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5934 spin_unlock_irq(&phba->hbalock);
5935 }
5936
James Smart2e0fef82007-06-17 19:56:36 -05005937 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5938 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005939}
5940
James Smarte59058c2008-08-24 21:49:00 -04005941/**
James Smart3621a712009-04-06 18:47:14 -04005942 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005943 * @vport: pointer to a host virtual N_Port data structure.
5944 *
5945 * This routine is used to clean up all the outstanding ELS commands on a
5946 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5947 * routine. After that, it walks the ELS transmit queue to remove all the
5948 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5949 * the IOCBs with a non-NULL completion callback function, the callback
5950 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5951 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5952 * callback function, the IOCB will simply be released. Finally, it walks
5953 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5954 * completion queue IOCB that is associated with the @vport and is not
5955 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5956 * part of the discovery state machine) out to HBA by invoking the
5957 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5958 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5959 * the IOCBs are aborted when this function returns.
5960 **/
dea31012005-04-17 16:05:31 -05005961void
James Smart2e0fef82007-06-17 19:56:36 -05005962lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005963{
James Smart2534ba72007-04-25 09:52:20 -04005964 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005965 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005966 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005967 struct lpfc_iocbq *tmp_iocb, *piocb;
5968 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005969
5970 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005971
James Smart2e0fef82007-06-17 19:56:36 -05005972 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005973 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5974 cmd = &piocb->iocb;
5975
5976 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5977 continue;
5978 }
5979
5980 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005981 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5982 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5983 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5984 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005985 continue;
dea31012005-04-17 16:05:31 -05005986
James Smart2e0fef82007-06-17 19:56:36 -05005987 if (piocb->vport != vport)
5988 continue;
5989
James Smart2534ba72007-04-25 09:52:20 -04005990 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005991 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005992 }
5993
5994 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005995 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5996 continue;
5997 }
dea31012005-04-17 16:05:31 -05005998
James Smart2e0fef82007-06-17 19:56:36 -05005999 if (piocb->vport != vport)
6000 continue;
6001
James Smart07951072007-04-25 09:51:38 -04006002 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05006003 }
James Smart2e0fef82007-06-17 19:56:36 -05006004 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04006005
James Smarta257bf92009-04-06 18:48:10 -04006006 /* Cancell all the IOCBs from the completions list */
6007 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6008 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04006009
dea31012005-04-17 16:05:31 -05006010 return;
6011}
6012
James Smarte59058c2008-08-24 21:49:00 -04006013/**
James Smart3621a712009-04-06 18:47:14 -04006014 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04006015 * @phba: pointer to lpfc hba data structure.
6016 *
6017 * This routine is used to clean up all the outstanding ELS commands on a
6018 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6019 * routine. After that, it walks the ELS transmit queue to remove all the
6020 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6021 * the IOCBs with the completion callback function associated, the callback
6022 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6023 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6024 * callback function associated, the IOCB will simply be released. Finally,
6025 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6026 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6027 * management plane IOCBs that are not part of the discovery state machine)
6028 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6029 **/
James Smart549e55c2007-08-02 11:09:51 -04006030void
6031lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6032{
6033 LIST_HEAD(completions);
6034 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6035 struct lpfc_iocbq *tmp_iocb, *piocb;
6036 IOCB_t *cmd = NULL;
6037
6038 lpfc_fabric_abort_hba(phba);
6039 spin_lock_irq(&phba->hbalock);
6040 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6041 cmd = &piocb->iocb;
6042 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6043 continue;
6044 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6045 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6046 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6047 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6048 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6049 continue;
6050 list_move_tail(&piocb->list, &completions);
6051 pring->txq_cnt--;
6052 }
6053 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6054 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6055 continue;
6056 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6057 }
6058 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04006059
6060 /* Cancel all the IOCBs from the completions list */
6061 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6062 IOERR_SLI_ABORTED);
6063
James Smart549e55c2007-08-02 11:09:51 -04006064 return;
6065}
6066
James Smarte59058c2008-08-24 21:49:00 -04006067/**
James Smart3621a712009-04-06 18:47:14 -04006068 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04006069 * @phba: Pointer to hba context object.
6070 * @cmdiocbp: Pointer to command iocb which reported error.
6071 * @rspiocbp: Pointer to response iocb which reported error.
6072 *
6073 * This function sends an event when there is an ELS command
6074 * failure.
6075 **/
6076void
6077lpfc_send_els_failure_event(struct lpfc_hba *phba,
6078 struct lpfc_iocbq *cmdiocbp,
6079 struct lpfc_iocbq *rspiocbp)
6080{
6081 struct lpfc_vport *vport = cmdiocbp->vport;
6082 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6083 struct lpfc_lsrjt_event lsrjt_event;
6084 struct lpfc_fabric_event_header fabric_event;
6085 struct ls_rjt stat;
6086 struct lpfc_nodelist *ndlp;
6087 uint32_t *pcmd;
6088
6089 ndlp = cmdiocbp->context1;
6090 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6091 return;
6092
6093 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6094 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6095 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6096 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6097 sizeof(struct lpfc_name));
6098 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6099 sizeof(struct lpfc_name));
6100 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6101 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006102 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006103 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6104 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6105 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6106 fc_host_post_vendor_event(shost,
6107 fc_get_event_number(),
6108 sizeof(lsrjt_event),
6109 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006110 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006111 return;
6112 }
6113 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6114 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6115 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6116 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6117 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6118 else
6119 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6120 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6121 sizeof(struct lpfc_name));
6122 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6123 sizeof(struct lpfc_name));
6124 fc_host_post_vendor_event(shost,
6125 fc_get_event_number(),
6126 sizeof(fabric_event),
6127 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006128 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006129 return;
6130 }
6131
6132}
6133
6134/**
James Smart3621a712009-04-06 18:47:14 -04006135 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006136 * @vport: Pointer to vport object.
6137 * @ndlp: Pointer FC node object.
6138 * @cmd: ELS command code.
6139 *
6140 * This function posts an event when there is an incoming
6141 * unsolicited ELS command.
6142 **/
6143static void
6144lpfc_send_els_event(struct lpfc_vport *vport,
6145 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006146 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006147{
James Smartddcc50f2008-12-04 22:38:46 -05006148 struct lpfc_els_event_header *els_data = NULL;
6149 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006150 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6151
James Smartddcc50f2008-12-04 22:38:46 -05006152 if (*payload == ELS_CMD_LOGO) {
6153 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6154 if (!logo_data) {
6155 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6156 "0148 Failed to allocate memory "
6157 "for LOGO event\n");
6158 return;
6159 }
6160 els_data = &logo_data->header;
6161 } else {
6162 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6163 GFP_KERNEL);
6164 if (!els_data) {
6165 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6166 "0149 Failed to allocate memory "
6167 "for ELS event\n");
6168 return;
6169 }
6170 }
6171 els_data->event_type = FC_REG_ELS_EVENT;
6172 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006173 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006174 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006175 break;
6176 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006177 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006178 break;
6179 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006180 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6181 break;
6182 case ELS_CMD_LOGO:
6183 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6184 /* Copy the WWPN in the LOGO payload */
6185 memcpy(logo_data->logo_wwpn, &payload[2],
6186 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006187 break;
6188 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006189 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006190 return;
6191 }
James Smartddcc50f2008-12-04 22:38:46 -05006192 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6193 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6194 if (*payload == ELS_CMD_LOGO) {
6195 fc_host_post_vendor_event(shost,
6196 fc_get_event_number(),
6197 sizeof(struct lpfc_logo_event),
6198 (char *)logo_data,
6199 LPFC_NL_VENDOR_ID);
6200 kfree(logo_data);
6201 } else {
6202 fc_host_post_vendor_event(shost,
6203 fc_get_event_number(),
6204 sizeof(struct lpfc_els_event_header),
6205 (char *)els_data,
6206 LPFC_NL_VENDOR_ID);
6207 kfree(els_data);
6208 }
James Smartea2151b2008-09-07 11:52:10 -04006209
6210 return;
6211}
6212
6213
6214/**
James Smart3621a712009-04-06 18:47:14 -04006215 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006216 * @phba: pointer to lpfc hba data structure.
6217 * @pring: pointer to a SLI ring.
6218 * @vport: pointer to a host virtual N_Port data structure.
6219 * @elsiocb: pointer to lpfc els command iocb data structure.
6220 *
6221 * This routine is used for processing the IOCB associated with a unsolicited
6222 * event. It first determines whether there is an existing ndlp that matches
6223 * the DID from the unsolicited IOCB. If not, it will create a new one with
6224 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6225 * IOCB is then used to invoke the proper routine and to set up proper state
6226 * of the discovery state machine.
6227 **/
James Smarted957682007-06-17 19:56:37 -05006228static void
6229lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006230 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006231{
James Smart87af33f2007-10-27 13:37:43 -04006232 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006233 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006234 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006235 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05006236 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006237 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006238
James Smarte47c9092008-02-08 18:49:26 -05006239 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006240 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006241
dea31012005-04-17 16:05:31 -05006242 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006243 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6244 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006245 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006246 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006247
James Smart858c9f62007-06-17 19:56:39 -05006248 did = icmd->un.rcvels.remoteID;
6249 if (icmd->ulpStatus) {
6250 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6251 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6252 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006253 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006254 }
dea31012005-04-17 16:05:31 -05006255
6256 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006257 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006258 goto dropit;
dea31012005-04-17 16:05:31 -05006259
James Smartc8685952009-11-18 15:39:16 -05006260 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006261 if (vport->load_flag & FC_UNLOADING)
6262 goto dropit;
6263
James Smart92494142011-02-16 12:39:44 -05006264 /* If NPort discovery is delayed drop incoming ELS */
6265 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6266 (cmd != ELS_CMD_PLOGI))
6267 goto dropit;
6268
James Smart2e0fef82007-06-17 19:56:36 -05006269 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006270 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006271 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006272 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006273 if (!ndlp)
dea31012005-04-17 16:05:31 -05006274 goto dropit;
dea31012005-04-17 16:05:31 -05006275
James Smart2e0fef82007-06-17 19:56:36 -05006276 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006277 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006278 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006279 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006280 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006281 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6282 ndlp = lpfc_enable_node(vport, ndlp,
6283 NLP_STE_UNUSED_NODE);
6284 if (!ndlp)
6285 goto dropit;
6286 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6287 newnode = 1;
6288 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6289 ndlp->nlp_type |= NLP_FABRIC;
6290 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6291 /* This is similar to the new node path */
6292 ndlp = lpfc_nlp_get(ndlp);
6293 if (!ndlp)
6294 goto dropit;
6295 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6296 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006297 }
dea31012005-04-17 16:05:31 -05006298
6299 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006300
James Smart329f9bc2007-04-25 09:53:01 -04006301 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006302 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006303
6304 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6305 cmd &= ELS_CMD_MASK;
6306 }
6307 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006308 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6309 "0112 ELS command x%x received from NPORT x%x "
6310 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006311 switch (cmd) {
6312 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006313 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6314 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6315 did, vport->port_state, ndlp->nlp_flag);
6316
dea31012005-04-17 16:05:31 -05006317 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006318 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6319
James Smartddcc50f2008-12-04 22:38:46 -05006320 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05006321
6322 /* If Nport discovery is delayed, reject PLOGIs */
6323 if (vport->fc_flag & FC_DISC_DELAYED) {
6324 rjt_err = LSRJT_UNABLE_TPC;
6325 break;
6326 }
James Smart858c9f62007-06-17 19:56:39 -05006327 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006328 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6329 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6330 rjt_err = LSRJT_UNABLE_TPC;
6331 break;
6332 }
6333 /* We get here, and drop thru, if we are PT2PT with
6334 * another NPort and the other side has initiated
6335 * the PLOGI before responding to our FLOGI.
6336 */
dea31012005-04-17 16:05:31 -05006337 }
James Smart87af33f2007-10-27 13:37:43 -04006338
6339 shost = lpfc_shost_from_vport(vport);
6340 spin_lock_irq(shost->host_lock);
6341 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6342 spin_unlock_irq(shost->host_lock);
6343
James Smart2e0fef82007-06-17 19:56:36 -05006344 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6345 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006346
dea31012005-04-17 16:05:31 -05006347 break;
6348 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006349 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6350 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6351 did, vport->port_state, ndlp->nlp_flag);
6352
dea31012005-04-17 16:05:31 -05006353 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006354 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006355 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006356 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006357 break;
6358 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006359 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6360 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6361 did, vport->port_state, ndlp->nlp_flag);
6362
dea31012005-04-17 16:05:31 -05006363 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006364 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006365 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006366 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006367 break;
6368 }
James Smart2e0fef82007-06-17 19:56:36 -05006369 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006370 break;
6371 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006372 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6373 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6374 did, vport->port_state, ndlp->nlp_flag);
6375
dea31012005-04-17 16:05:31 -05006376 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006377 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006378 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006379 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006380 break;
6381 }
James Smart2e0fef82007-06-17 19:56:36 -05006382 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006383 break;
6384 case ELS_CMD_RSCN:
6385 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006386 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006387 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006388 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006389 break;
6390 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006391 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6392 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6393 did, vport->port_state, ndlp->nlp_flag);
6394
James Smartddcc50f2008-12-04 22:38:46 -05006395 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006396 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006397 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006398 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006399 break;
6400 }
James Smart2e0fef82007-06-17 19:56:36 -05006401 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6402 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006403 break;
6404 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006405 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6406 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6407 did, vport->port_state, ndlp->nlp_flag);
6408
dea31012005-04-17 16:05:31 -05006409 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006410 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006411 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006412 break;
6413 }
James Smart2e0fef82007-06-17 19:56:36 -05006414 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6415 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006416 break;
6417 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006418 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6419 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6420 did, vport->port_state, ndlp->nlp_flag);
6421
dea31012005-04-17 16:05:31 -05006422 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006423 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006424 break;
6425 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006426 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6427 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6428 did, vport->port_state, ndlp->nlp_flag);
6429
dea31012005-04-17 16:05:31 -05006430 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006431 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006432 break;
6433 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006434 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6435 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6436 did, vport->port_state, ndlp->nlp_flag);
6437
dea31012005-04-17 16:05:31 -05006438 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006439 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006440 break;
dea31012005-04-17 16:05:31 -05006441 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006442 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6443 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6444 did, vport->port_state, ndlp->nlp_flag);
6445
dea31012005-04-17 16:05:31 -05006446 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006447 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006448 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006449 break;
6450 }
James Smart2e0fef82007-06-17 19:56:36 -05006451 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006452 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006453 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006454 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6455 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6456 did, vport->port_state, ndlp->nlp_flag);
6457
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006458 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006459 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006460 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006461 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006462 break;
James Smart12265f62010-10-22 11:05:53 -04006463 case ELS_CMD_RLS:
6464 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6465 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6466 did, vport->port_state, ndlp->nlp_flag);
6467
6468 phba->fc_stat.elsRcvRLS++;
6469 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6470 if (newnode)
6471 lpfc_nlp_put(ndlp);
6472 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006473 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006474 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6475 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6476 did, vport->port_state, ndlp->nlp_flag);
6477
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006478 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006479 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006480 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006481 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006482 break;
6483 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006484 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6485 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6486 did, vport->port_state, ndlp->nlp_flag);
6487
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006488 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006489 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006490 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006491 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006492 break;
dea31012005-04-17 16:05:31 -05006493 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006494 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6495 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6496 did, vport->port_state, ndlp->nlp_flag);
6497
dea31012005-04-17 16:05:31 -05006498 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006499 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006500 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006501 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006502 break;
James Smart12265f62010-10-22 11:05:53 -04006503 case ELS_CMD_RTV:
6504 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6505 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6506 did, vport->port_state, ndlp->nlp_flag);
6507 phba->fc_stat.elsRcvRTV++;
6508 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6509 if (newnode)
6510 lpfc_nlp_put(ndlp);
6511 break;
James Smart5ffc2662009-11-18 15:39:44 -05006512 case ELS_CMD_RRQ:
6513 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6514 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6515 did, vport->port_state, ndlp->nlp_flag);
6516
6517 phba->fc_stat.elsRcvRRQ++;
6518 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6519 if (newnode)
6520 lpfc_nlp_put(ndlp);
6521 break;
James Smart12265f62010-10-22 11:05:53 -04006522 case ELS_CMD_ECHO:
6523 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6524 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6525 did, vport->port_state, ndlp->nlp_flag);
6526
6527 phba->fc_stat.elsRcvECHO++;
6528 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6529 if (newnode)
6530 lpfc_nlp_put(ndlp);
6531 break;
dea31012005-04-17 16:05:31 -05006532 default:
James Smart858c9f62007-06-17 19:56:39 -05006533 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6534 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6535 cmd, did, vport->port_state);
6536
dea31012005-04-17 16:05:31 -05006537 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006538 rjt_err = LSRJT_CMD_UNSUPPORTED;
dea31012005-04-17 16:05:31 -05006539
6540 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006541 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6542 "0115 Unknown ELS command x%x "
6543 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006544 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006545 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006546 break;
6547 }
6548
6549 /* check if need to LS_RJT received ELS cmd */
6550 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006551 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006552 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006553 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006554 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6555 NULL);
dea31012005-04-17 16:05:31 -05006556 }
6557
James Smartd7c255b2008-08-24 21:50:00 -04006558 lpfc_nlp_put(elsiocb->context1);
6559 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006560 return;
6561
6562dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006563 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006564 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6565 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006566 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006567 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006568 phba->fc_stat.elsRcvDrop++;
6569}
6570
James Smarte59058c2008-08-24 21:49:00 -04006571/**
James Smart3621a712009-04-06 18:47:14 -04006572 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04006573 * @phba: pointer to lpfc hba data structure.
6574 * @vpi: host virtual N_Port identifier.
6575 *
6576 * This routine finds a vport on a HBA (referred by @phba) through a
6577 * @vpi. The function walks the HBA's vport list and returns the address
6578 * of the vport with the matching @vpi.
6579 *
6580 * Return code
6581 * NULL - No vport with the matching @vpi found
6582 * Otherwise - Address to the vport with the matching @vpi.
6583 **/
James Smart6669f9b2009-10-02 15:16:45 -04006584struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05006585lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6586{
6587 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04006588 unsigned long flags;
James Smart6d368e52011-05-24 11:44:12 -04006589 int i;
6590
6591 /* The physical ports are always vpi 0 - translate is unnecessary. */
6592 if (vpi > 0) {
6593 /*
6594 * Translate the physical vpi to the logical vpi. The
6595 * vport stores the logical vpi.
6596 */
6597 for (i = 0; i < phba->max_vpi; i++) {
6598 if (vpi == phba->vpi_ids[i])
6599 break;
6600 }
6601
6602 if (i >= phba->max_vpi) {
6603 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
6604 "2936 Could not find Vport mapped "
6605 "to vpi %d\n", vpi);
6606 return NULL;
6607 }
6608 }
James Smart92d7f7b2007-06-17 19:56:38 -05006609
James Smart549e55c2007-08-02 11:09:51 -04006610 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006611 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04006612 if (vport->vpi == vpi) {
6613 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006614 return vport;
James Smart549e55c2007-08-02 11:09:51 -04006615 }
James Smart92d7f7b2007-06-17 19:56:38 -05006616 }
James Smart549e55c2007-08-02 11:09:51 -04006617 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006618 return NULL;
6619}
James Smarted957682007-06-17 19:56:37 -05006620
James Smarte59058c2008-08-24 21:49:00 -04006621/**
James Smart3621a712009-04-06 18:47:14 -04006622 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006623 * @phba: pointer to lpfc hba data structure.
6624 * @pring: pointer to a SLI ring.
6625 * @elsiocb: pointer to lpfc els iocb data structure.
6626 *
6627 * This routine is used to process an unsolicited event received from a SLI
6628 * (Service Level Interface) ring. The actual processing of the data buffer
6629 * associated with the unsolicited event is done by invoking the routine
6630 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6631 * SLI ring on which the unsolicited event was received.
6632 **/
James Smarted957682007-06-17 19:56:37 -05006633void
6634lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6635 struct lpfc_iocbq *elsiocb)
6636{
6637 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006638 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006639 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006640 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6641 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006642
James Smartd7c255b2008-08-24 21:50:00 -04006643 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006644 elsiocb->context2 = NULL;
6645 elsiocb->context3 = NULL;
6646
6647 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6648 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6649 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6650 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006651 phba->fc_stat.NoRcvBuf++;
6652 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006653 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006654 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006655 return;
6656 }
6657
James Smart92d7f7b2007-06-17 19:56:38 -05006658 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6659 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6660 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6661 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6662 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006663 else
6664 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04006665 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05006666 }
James Smart6d368e52011-05-24 11:44:12 -04006667
James Smart7f5f3d02008-02-08 18:50:14 -05006668 /* If there are no BDEs associated
6669 * with this IOCB, there is nothing to do.
6670 */
James Smarted957682007-06-17 19:56:37 -05006671 if (icmd->ulpBdeCount == 0)
6672 return;
6673
James Smart7f5f3d02008-02-08 18:50:14 -05006674 /* type of ELS cmd is first 32bit word
6675 * in packet
6676 */
James Smarted957682007-06-17 19:56:37 -05006677 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006678 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006679 } else {
6680 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6681 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006682 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6683 paddr);
James Smarted957682007-06-17 19:56:37 -05006684 }
6685
James Smart92d7f7b2007-06-17 19:56:38 -05006686 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6687 /*
6688 * The different unsolicited event handlers would tell us
6689 * if they are done with "mp" by setting context2 to NULL.
6690 */
dea31012005-04-17 16:05:31 -05006691 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006692 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6693 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006694 }
James Smarted957682007-06-17 19:56:37 -05006695
6696 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006697 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006698 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006699 elsiocb->context2 = bdeBuf2;
6700 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006701 /* free mp if we are done with it */
6702 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006703 lpfc_in_buf_free(phba, elsiocb->context2);
6704 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006705 }
dea31012005-04-17 16:05:31 -05006706 }
dea31012005-04-17 16:05:31 -05006707}
James Smart92d7f7b2007-06-17 19:56:38 -05006708
James Smarte59058c2008-08-24 21:49:00 -04006709/**
James Smart3621a712009-04-06 18:47:14 -04006710 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006711 * @phba: pointer to lpfc hba data structure.
6712 * @vport: pointer to a virtual N_Port data structure.
6713 *
6714 * This routine issues a Port Login (PLOGI) to the Name Server with
6715 * State Change Request (SCR) for a @vport. This routine will create an
6716 * ndlp for the Name Server associated to the @vport if such node does
6717 * not already exist. The PLOGI to Name Server is issued by invoking the
6718 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6719 * (FDMI) is configured to the @vport, a FDMI node will be created and
6720 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6721 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006722void
6723lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6724{
6725 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05006726 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6727
6728 /*
6729 * If lpfc_delay_discovery parameter is set and the clean address
6730 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6731 * discovery.
6732 */
6733 spin_lock_irq(shost->host_lock);
6734 if (vport->fc_flag & FC_DISC_DELAYED) {
6735 spin_unlock_irq(shost->host_lock);
6736 mod_timer(&vport->delayed_disc_tmo,
6737 jiffies + HZ * phba->fc_ratov);
6738 return;
6739 }
6740 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006741
6742 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6743 if (!ndlp) {
6744 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6745 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006746 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05006747 lpfc_disc_start(vport);
6748 return;
6749 }
6750 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006751 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6752 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006753 return;
6754 }
6755 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006756 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6757 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6758 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006759 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05006760 lpfc_disc_start(vport);
6761 return;
6762 }
6763 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6764 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6765 "0348 NameServer login: node freed\n");
6766 return;
6767 }
James Smart92d7f7b2007-06-17 19:56:38 -05006768 }
James Smart58da1ff2008-04-07 10:15:56 -04006769 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006770
6771 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6772
6773 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6774 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006775 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6776 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006777 return;
6778 }
6779
James Smart3de2a652007-08-02 11:09:59 -04006780 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05006781 /* If this is the first time, allocate an ndlp and initialize
6782 * it. Otherwise, make sure the node is enabled and then do the
6783 * login.
6784 */
6785 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
6786 if (!ndlp_fdmi) {
6787 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6788 GFP_KERNEL);
6789 if (ndlp_fdmi) {
6790 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6791 ndlp_fdmi->nlp_type |= NLP_FABRIC;
6792 } else
6793 return;
6794 }
6795 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
6796 ndlp_fdmi = lpfc_enable_node(vport,
6797 ndlp_fdmi,
6798 NLP_STE_NPR_NODE);
6799
James Smart92d7f7b2007-06-17 19:56:38 -05006800 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04006801 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05006802 NLP_STE_PLOGI_ISSUE);
6803 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006804 }
6805 }
James Smart92d7f7b2007-06-17 19:56:38 -05006806}
6807
James Smarte59058c2008-08-24 21:49:00 -04006808/**
James Smart3621a712009-04-06 18:47:14 -04006809 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006810 * @phba: pointer to lpfc hba data structure.
6811 * @pmb: pointer to the driver internal queue element for mailbox command.
6812 *
6813 * This routine is the completion callback function to register new vport
6814 * mailbox command. If the new vport mailbox command completes successfully,
6815 * the fabric registration login shall be performed on physical port (the
6816 * new vport created is actually a physical port, with VPI 0) or the port
6817 * login to Name Server for State Change Request (SCR) will be performed
6818 * on virtual port (real virtual port, with VPI greater than 0).
6819 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006820static void
6821lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6822{
6823 struct lpfc_vport *vport = pmb->vport;
6824 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6825 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006826 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006827 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006828
James Smart09372822008-01-11 01:52:54 -05006829 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006830 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006831 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006832
6833 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006834 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006835 "0915 Register VPI failed : Status: x%x"
6836 " upd bit: x%x \n", mb->mbxStatus,
6837 mb->un.varRegVpi.upd);
6838 if (phba->sli_rev == LPFC_SLI_REV4 &&
6839 mb->un.varRegVpi.upd)
6840 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006841
6842 switch (mb->mbxStatus) {
6843 case 0x11: /* unsupported feature */
6844 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006845 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006846 /* giving up on vport registration */
6847 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6848 spin_lock_irq(shost->host_lock);
6849 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6850 spin_unlock_irq(shost->host_lock);
6851 lpfc_can_disctmo(vport);
6852 break;
James Smart695a8142010-01-26 23:08:03 -05006853 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6854 case 0x20:
6855 spin_lock_irq(shost->host_lock);
6856 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6857 spin_unlock_irq(shost->host_lock);
6858 lpfc_init_vpi(phba, pmb, vport->vpi);
6859 pmb->vport = vport;
6860 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6861 rc = lpfc_sli_issue_mbox(phba, pmb,
6862 MBX_NOWAIT);
6863 if (rc == MBX_NOT_FINISHED) {
6864 lpfc_printf_vlog(vport,
6865 KERN_ERR, LOG_MBOX,
6866 "2732 Failed to issue INIT_VPI"
6867 " mailbox command\n");
6868 } else {
6869 lpfc_nlp_put(ndlp);
6870 return;
6871 }
6872
James Smart92d7f7b2007-06-17 19:56:38 -05006873 default:
6874 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04006875 if (phba->sli_rev == LPFC_SLI_REV4)
6876 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006877 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006878 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006879 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006880 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006881 if (vport->port_type == LPFC_PHYSICAL_PORT
6882 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05006883 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05006884 else
6885 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006886 break;
6887 }
James Smart92d7f7b2007-06-17 19:56:38 -05006888 } else {
James Smart695a8142010-01-26 23:08:03 -05006889 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006890 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006891 spin_unlock_irq(shost->host_lock);
6892 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006893 if (phba->sli_rev < LPFC_SLI_REV4)
6894 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006895 else {
James Smartfc2b9892010-02-26 14:15:29 -05006896 /*
6897 * If the physical port is instantiated using
6898 * FDISC, do not start vport discovery.
6899 */
6900 if (vport->port_state != LPFC_FDISC)
6901 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006902 lpfc_do_scr_ns_plogi(phba, vport);
6903 }
6904 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006905 lpfc_do_scr_ns_plogi(phba, vport);
6906 }
James Smart38b92ef2010-08-04 16:11:39 -04006907mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05006908 /* Now, we decrement the ndlp reference count held for this
6909 * callback function
6910 */
6911 lpfc_nlp_put(ndlp);
6912
James Smart92d7f7b2007-06-17 19:56:38 -05006913 mempool_free(pmb, phba->mbox_mem_pool);
6914 return;
6915}
6916
James Smarte59058c2008-08-24 21:49:00 -04006917/**
James Smart3621a712009-04-06 18:47:14 -04006918 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006919 * @phba: pointer to lpfc hba data structure.
6920 * @vport: pointer to a host virtual N_Port data structure.
6921 * @ndlp: pointer to a node-list data structure.
6922 *
6923 * This routine registers the @vport as a new virtual port with a HBA.
6924 * It is done through a registering vpi mailbox command.
6925 **/
James Smart695a8142010-01-26 23:08:03 -05006926void
James Smart92d7f7b2007-06-17 19:56:38 -05006927lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6928 struct lpfc_nodelist *ndlp)
6929{
James Smart09372822008-01-11 01:52:54 -05006930 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006931 LPFC_MBOXQ_t *mbox;
6932
6933 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6934 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006935 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006936 mbox->vport = vport;
6937 mbox->context2 = lpfc_nlp_get(ndlp);
6938 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006939 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006940 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006941 /* mailbox command not success, decrement ndlp
6942 * reference count for this command
6943 */
6944 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006945 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006946
James Smarte8b62012007-08-02 11:10:09 -04006947 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6948 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006949 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006950 }
6951 } else {
James Smarte8b62012007-08-02 11:10:09 -04006952 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6953 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006954 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006955 }
James Smartfa4066b2008-01-11 01:53:27 -05006956 return;
6957
6958mbox_err_exit:
6959 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6960 spin_lock_irq(shost->host_lock);
6961 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6962 spin_unlock_irq(shost->host_lock);
6963 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006964}
6965
James Smarte59058c2008-08-24 21:49:00 -04006966/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006967 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006968 * @phba: pointer to lpfc hba data structure.
6969 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006970 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006971 **/
6972void
James Smart0c9ab6f2010-02-26 14:15:57 -05006973lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006974{
6975 struct lpfc_vport **vports;
6976 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006977 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006978 int i;
James Smart695a8142010-01-26 23:08:03 -05006979
6980 /* Treat this failure as linkdown for all vports */
6981 link_state = phba->link_state;
6982 lpfc_linkdown(phba);
6983 phba->link_state = link_state;
6984
6985 vports = lpfc_create_vport_work_array(phba);
6986
6987 if (vports) {
6988 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6989 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6990 if (ndlp)
6991 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6992 lpfc_els_flush_cmd(vports[i]);
6993 }
6994 lpfc_destroy_vport_work_array(phba, vports);
6995 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006996}
6997
6998/**
6999 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7000 * @phba: pointer to lpfc hba data structure.
7001 *
7002 * This routine abort all pending discovery commands and
7003 * start a timer to retry FLOGI for the physical port
7004 * discovery.
7005 **/
7006void
7007lpfc_retry_pport_discovery(struct lpfc_hba *phba)
7008{
7009 struct lpfc_nodelist *ndlp;
7010 struct Scsi_Host *shost;
7011
7012 /* Cancel the all vports retry delay retry timers */
7013 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05007014
7015 /* If fabric require FLOGI, then re-instantiate physical login */
7016 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
7017 if (!ndlp)
7018 return;
7019
James Smart695a8142010-01-26 23:08:03 -05007020 shost = lpfc_shost_from_vport(phba->pport);
7021 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
7022 spin_lock_irq(shost->host_lock);
7023 ndlp->nlp_flag |= NLP_DELAY_TMO;
7024 spin_unlock_irq(shost->host_lock);
7025 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7026 phba->pport->port_state = LPFC_FLOGI;
7027 return;
7028}
7029
7030/**
7031 * lpfc_fabric_login_reqd - Check if FLOGI required.
7032 * @phba: pointer to lpfc hba data structure.
7033 * @cmdiocb: pointer to FDISC command iocb.
7034 * @rspiocb: pointer to FDISC response iocb.
7035 *
7036 * This routine checks if a FLOGI is reguired for FDISC
7037 * to succeed.
7038 **/
7039static int
7040lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7041 struct lpfc_iocbq *cmdiocb,
7042 struct lpfc_iocbq *rspiocb)
7043{
7044
7045 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7046 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7047 return 0;
7048 else
7049 return 1;
7050}
7051
7052/**
James Smart3621a712009-04-06 18:47:14 -04007053 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007054 * @phba: pointer to lpfc hba data structure.
7055 * @cmdiocb: pointer to lpfc command iocb data structure.
7056 * @rspiocb: pointer to lpfc response iocb data structure.
7057 *
7058 * This routine is the completion callback function to a Fabric Discover
7059 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7060 * single threaded, each FDISC completion callback function will reset
7061 * the discovery timer for all vports such that the timers will not get
7062 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7063 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7064 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7065 * assigned to the vport has been changed with the completion of the FDISC
7066 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7067 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7068 * routine is invoked to register new vport with the HBA. Otherwise, the
7069 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7070 * Server for State Change Request (SCR).
7071 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007072static void
7073lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7074 struct lpfc_iocbq *rspiocb)
7075{
7076 struct lpfc_vport *vport = cmdiocb->vport;
7077 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7078 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7079 struct lpfc_nodelist *np;
7080 struct lpfc_nodelist *next_np;
7081 IOCB_t *irsp = &rspiocb->iocb;
7082 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05007083 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7084 struct serv_parm *sp;
7085 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05007086
James Smarte8b62012007-08-02 11:10:09 -04007087 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7088 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7089 irsp->ulpStatus, irsp->un.ulpWord[4],
7090 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05007091 /* Since all FDISCs are being single threaded, we
7092 * must reset the discovery timer for ALL vports
7093 * waiting to send FDISC when one completes.
7094 */
7095 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7096 lpfc_set_disctmo(piocb->vport);
7097 }
7098
James Smart858c9f62007-06-17 19:56:39 -05007099 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7100 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7101 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7102
James Smart92d7f7b2007-06-17 19:56:38 -05007103 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05007104
7105 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7106 lpfc_retry_pport_discovery(phba);
7107 goto out;
7108 }
7109
James Smart92d7f7b2007-06-17 19:56:38 -05007110 /* Check for retry */
7111 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7112 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007113 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04007114 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04007115 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04007116 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04007117 goto fdisc_failed;
7118 }
James Smartd7c255b2008-08-24 21:50:00 -04007119 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05007120 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04007121 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04007122 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05007123 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04007124 vport->fc_flag |= FC_PUBLIC_LOOP;
7125 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007126
James Smartd7c255b2008-08-24 21:50:00 -04007127 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7128 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05007129 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7130 sp = prsp->virt + sizeof(uint32_t);
7131 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7132 memcpy(&vport->fabric_portname, &sp->portName,
7133 sizeof(struct lpfc_name));
7134 memcpy(&vport->fabric_nodename, &sp->nodeName,
7135 sizeof(struct lpfc_name));
7136 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04007137 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7138 /* If our NportID changed, we need to ensure all
7139 * remaining NPORTs get unreg_login'ed so we can
7140 * issue unreg_vpi.
7141 */
7142 list_for_each_entry_safe(np, next_np,
7143 &vport->fc_nodes, nlp_listp) {
7144 if (!NLP_CHK_NODE_ACT(ndlp) ||
7145 (np->nlp_state != NLP_STE_NPR_NODE) ||
7146 !(np->nlp_flag & NLP_NPR_ADISC))
7147 continue;
James Smart09372822008-01-11 01:52:54 -05007148 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007149 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007150 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007151 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007152 }
James Smart78730cf2010-04-06 15:06:30 -04007153 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007154
7155 if (phba->sli_rev == LPFC_SLI_REV4)
7156 lpfc_sli4_unreg_all_rpis(vport);
7157
James Smartd7c255b2008-08-24 21:50:00 -04007158 lpfc_mbx_unreg_vpi(vport);
7159 spin_lock_irq(shost->host_lock);
7160 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007161 if (phba->sli_rev == LPFC_SLI_REV4)
7162 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007163 else
7164 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007165 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007166 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7167 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7168 /*
7169 * Driver needs to re-reg VPI in order for f/w
7170 * to update the MAC address.
7171 */
7172 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007173 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007174 }
7175
James Smartecfd03c2010-02-12 14:41:27 -05007176 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7177 lpfc_issue_init_vpi(vport);
7178 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007179 lpfc_register_new_vport(phba, vport, ndlp);
7180 else
7181 lpfc_do_scr_ns_plogi(phba, vport);
7182 goto out;
7183fdisc_failed:
7184 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7185 /* Cancel discovery timer */
7186 lpfc_can_disctmo(vport);
7187 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007188out:
7189 lpfc_els_free_iocb(phba, cmdiocb);
7190}
7191
James Smarte59058c2008-08-24 21:49:00 -04007192/**
James Smart3621a712009-04-06 18:47:14 -04007193 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007194 * @vport: pointer to a virtual N_Port data structure.
7195 * @ndlp: pointer to a node-list data structure.
7196 * @retry: number of retries to the command IOCB.
7197 *
7198 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7199 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7200 * routine to issue the IOCB, which makes sure only one outstanding fabric
7201 * IOCB will be sent off HBA at any given time.
7202 *
7203 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7204 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7205 * will be stored into the context1 field of the IOCB for the completion
7206 * callback function to the FDISC ELS command.
7207 *
7208 * Return code
7209 * 0 - Successfully issued fdisc iocb command
7210 * 1 - Failed to issue fdisc iocb command
7211 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007212static int
James Smart92d7f7b2007-06-17 19:56:38 -05007213lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7214 uint8_t retry)
7215{
7216 struct lpfc_hba *phba = vport->phba;
7217 IOCB_t *icmd;
7218 struct lpfc_iocbq *elsiocb;
7219 struct serv_parm *sp;
7220 uint8_t *pcmd;
7221 uint16_t cmdsize;
7222 int did = ndlp->nlp_DID;
7223 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007224
James Smart5ffc2662009-11-18 15:39:44 -05007225 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05007226 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7227 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7228 ELS_CMD_FDISC);
7229 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007230 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007231 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7232 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007233 return 1;
7234 }
7235
7236 icmd = &elsiocb->iocb;
7237 icmd->un.elsreq64.myID = 0;
7238 icmd->un.elsreq64.fl = 1;
7239
James Smart40426292010-12-15 17:58:10 -05007240 if ((phba->sli_rev == LPFC_SLI_REV4) &&
7241 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
7242 LPFC_SLI_INTF_IF_TYPE_0)) {
James Smartf1126682009-06-10 17:22:44 -04007243 /* FDISC needs to be 1 for WQE VPI */
7244 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
7245 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
7246 /* Set the ulpContext to the vpi */
James Smart6d368e52011-05-24 11:44:12 -04007247 elsiocb->iocb.ulpContext = phba->vpi_ids[vport->vpi];
James Smartf1126682009-06-10 17:22:44 -04007248 } else {
7249 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
7250 icmd->ulpCt_h = 1;
7251 icmd->ulpCt_l = 0;
7252 }
James Smart92d7f7b2007-06-17 19:56:38 -05007253
7254 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7255 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7256 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7257 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7258 sp = (struct serv_parm *) pcmd;
7259 /* Setup CSPs accordingly for Fabric */
7260 sp->cmn.e_d_tov = 0;
7261 sp->cmn.w2.r_a_tov = 0;
7262 sp->cls1.classValid = 0;
7263 sp->cls2.seqDelivery = 1;
7264 sp->cls3.seqDelivery = 1;
7265
7266 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7267 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7268 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7269 pcmd += sizeof(uint32_t); /* Port Name */
7270 memcpy(pcmd, &vport->fc_portname, 8);
7271 pcmd += sizeof(uint32_t); /* Node Name */
7272 pcmd += sizeof(uint32_t); /* Node Name */
7273 memcpy(pcmd, &vport->fc_nodename, 8);
7274
7275 lpfc_set_disctmo(vport);
7276
7277 phba->fc_stat.elsXmitFDISC++;
7278 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7279
James Smart858c9f62007-06-17 19:56:39 -05007280 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7281 "Issue FDISC: did:x%x",
7282 did, 0, 0);
7283
James Smart92d7f7b2007-06-17 19:56:38 -05007284 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7285 if (rc == IOCB_ERROR) {
7286 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007287 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007288 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7289 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007290 return 1;
7291 }
7292 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007293 return 0;
7294}
7295
James Smarte59058c2008-08-24 21:49:00 -04007296/**
James Smart3621a712009-04-06 18:47:14 -04007297 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007298 * @phba: pointer to lpfc hba data structure.
7299 * @cmdiocb: pointer to lpfc command iocb data structure.
7300 * @rspiocb: pointer to lpfc response iocb data structure.
7301 *
7302 * This routine is the completion callback function to the issuing of a LOGO
7303 * ELS command off a vport. It frees the command IOCB and then decrement the
7304 * reference count held on ndlp for this completion function, indicating that
7305 * the reference to the ndlp is no long needed. Note that the
7306 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7307 * callback function and an additional explicit ndlp reference decrementation
7308 * will trigger the actual release of the ndlp.
7309 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007310static void
7311lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7312 struct lpfc_iocbq *rspiocb)
7313{
7314 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007315 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007316 struct lpfc_nodelist *ndlp;
James Smart9589b062011-04-16 11:03:17 -04007317 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05007318
James Smart9589b062011-04-16 11:03:17 -04007319 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007320 irsp = &rspiocb->iocb;
7321 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7322 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7323 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007324
7325 lpfc_els_free_iocb(phba, cmdiocb);
7326 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007327
7328 /* Trigger the release of the ndlp after logo */
7329 lpfc_nlp_put(ndlp);
James Smart9589b062011-04-16 11:03:17 -04007330
7331 /* NPIV LOGO completes to NPort <nlp_DID> */
7332 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7333 "2928 NPIV LOGO completes to NPort x%x "
7334 "Data: x%x x%x x%x x%x\n",
7335 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
7336 irsp->ulpTimeout, vport->num_disc_nodes);
7337
7338 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
7339 spin_lock_irq(shost->host_lock);
7340 vport->fc_flag &= ~FC_FABRIC;
7341 spin_unlock_irq(shost->host_lock);
7342 }
James Smart92d7f7b2007-06-17 19:56:38 -05007343}
7344
James Smarte59058c2008-08-24 21:49:00 -04007345/**
James Smart3621a712009-04-06 18:47:14 -04007346 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007347 * @vport: pointer to a virtual N_Port data structure.
7348 * @ndlp: pointer to a node-list data structure.
7349 *
7350 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7351 *
7352 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7353 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7354 * will be stored into the context1 field of the IOCB for the completion
7355 * callback function to the LOGO ELS command.
7356 *
7357 * Return codes
7358 * 0 - Successfully issued logo off the @vport
7359 * 1 - Failed to issue logo off the @vport
7360 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007361int
7362lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7363{
7364 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7365 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007366 IOCB_t *icmd;
7367 struct lpfc_iocbq *elsiocb;
7368 uint8_t *pcmd;
7369 uint16_t cmdsize;
7370
7371 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7372 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7373 ELS_CMD_LOGO);
7374 if (!elsiocb)
7375 return 1;
7376
7377 icmd = &elsiocb->iocb;
7378 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7379 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7380 pcmd += sizeof(uint32_t);
7381
7382 /* Fill in LOGO payload */
7383 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7384 pcmd += sizeof(uint32_t);
7385 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7386
James Smart858c9f62007-06-17 19:56:39 -05007387 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7388 "Issue LOGO npiv did:x%x flg:x%x",
7389 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7390
James Smart92d7f7b2007-06-17 19:56:38 -05007391 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7392 spin_lock_irq(shost->host_lock);
7393 ndlp->nlp_flag |= NLP_LOGO_SND;
7394 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007395 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7396 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007397 spin_lock_irq(shost->host_lock);
7398 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7399 spin_unlock_irq(shost->host_lock);
7400 lpfc_els_free_iocb(phba, elsiocb);
7401 return 1;
7402 }
7403 return 0;
7404}
7405
James Smarte59058c2008-08-24 21:49:00 -04007406/**
James Smart3621a712009-04-06 18:47:14 -04007407 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007408 * @ptr: holder for the timer function associated data.
7409 *
7410 * This routine is invoked by the fabric iocb block timer after
7411 * timeout. It posts the fabric iocb block timeout event by setting the
7412 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7413 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7414 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7415 * posted event WORKER_FABRIC_BLOCK_TMO.
7416 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007417void
7418lpfc_fabric_block_timeout(unsigned long ptr)
7419{
7420 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7421 unsigned long iflags;
7422 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007423
James Smart92d7f7b2007-06-17 19:56:38 -05007424 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7425 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7426 if (!tmo_posted)
7427 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7428 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7429
James Smart5e9d9b82008-06-14 22:52:53 -04007430 if (!tmo_posted)
7431 lpfc_worker_wake_up(phba);
7432 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007433}
7434
James Smarte59058c2008-08-24 21:49:00 -04007435/**
James Smart3621a712009-04-06 18:47:14 -04007436 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007437 * @phba: pointer to lpfc hba data structure.
7438 *
7439 * This routine issues one fabric iocb from the driver internal list to
7440 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7441 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7442 * remove one pending fabric iocb from the driver internal list and invokes
7443 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7444 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007445static void
7446lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7447{
7448 struct lpfc_iocbq *iocb;
7449 unsigned long iflags;
7450 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007451 IOCB_t *cmd;
7452
7453repeat:
7454 iocb = NULL;
7455 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007456 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007457 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7458 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7459 list);
7460 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007461 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007462 atomic_inc(&phba->fabric_iocb_count);
7463 }
7464 spin_unlock_irqrestore(&phba->hbalock, iflags);
7465 if (iocb) {
7466 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7467 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7468 iocb->iocb_flag |= LPFC_IO_FABRIC;
7469
James Smart858c9f62007-06-17 19:56:39 -05007470 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7471 "Fabric sched1: ste:x%x",
7472 iocb->vport->port_state, 0, 0);
7473
James Smart3772a992009-05-22 14:50:54 -04007474 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007475
7476 if (ret == IOCB_ERROR) {
7477 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7478 iocb->fabric_iocb_cmpl = NULL;
7479 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7480 cmd = &iocb->iocb;
7481 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7482 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7483 iocb->iocb_cmpl(phba, iocb, iocb);
7484
7485 atomic_dec(&phba->fabric_iocb_count);
7486 goto repeat;
7487 }
7488 }
7489
7490 return;
7491}
7492
James Smarte59058c2008-08-24 21:49:00 -04007493/**
James Smart3621a712009-04-06 18:47:14 -04007494 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007495 * @phba: pointer to lpfc hba data structure.
7496 *
7497 * This routine unblocks the issuing fabric iocb command. The function
7498 * will clear the fabric iocb block bit and then invoke the routine
7499 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7500 * from the driver internal fabric iocb list.
7501 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007502void
7503lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7504{
7505 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7506
7507 lpfc_resume_fabric_iocbs(phba);
7508 return;
7509}
7510
James Smarte59058c2008-08-24 21:49:00 -04007511/**
James Smart3621a712009-04-06 18:47:14 -04007512 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007513 * @phba: pointer to lpfc hba data structure.
7514 *
7515 * This routine blocks the issuing fabric iocb for a specified amount of
7516 * time (currently 100 ms). This is done by set the fabric iocb block bit
7517 * and set up a timeout timer for 100ms. When the block bit is set, no more
7518 * fabric iocb will be issued out of the HBA.
7519 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007520static void
7521lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7522{
7523 int blocked;
7524
7525 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007526 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007527 if (!blocked)
7528 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7529
7530 return;
7531}
7532
James Smarte59058c2008-08-24 21:49:00 -04007533/**
James Smart3621a712009-04-06 18:47:14 -04007534 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007535 * @phba: pointer to lpfc hba data structure.
7536 * @cmdiocb: pointer to lpfc command iocb data structure.
7537 * @rspiocb: pointer to lpfc response iocb data structure.
7538 *
7539 * This routine is the callback function that is put to the fabric iocb's
7540 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7541 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7542 * function first restores and invokes the original iocb's callback function
7543 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7544 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7545 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007546static void
7547lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7548 struct lpfc_iocbq *rspiocb)
7549{
7550 struct ls_rjt stat;
7551
7552 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7553 BUG();
7554
7555 switch (rspiocb->iocb.ulpStatus) {
7556 case IOSTAT_NPORT_RJT:
7557 case IOSTAT_FABRIC_RJT:
7558 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7559 lpfc_block_fabric_iocbs(phba);
7560 }
7561 break;
7562
7563 case IOSTAT_NPORT_BSY:
7564 case IOSTAT_FABRIC_BSY:
7565 lpfc_block_fabric_iocbs(phba);
7566 break;
7567
7568 case IOSTAT_LS_RJT:
7569 stat.un.lsRjtError =
7570 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7571 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7572 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7573 lpfc_block_fabric_iocbs(phba);
7574 break;
7575 }
7576
7577 if (atomic_read(&phba->fabric_iocb_count) == 0)
7578 BUG();
7579
7580 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7581 cmdiocb->fabric_iocb_cmpl = NULL;
7582 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7583 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7584
7585 atomic_dec(&phba->fabric_iocb_count);
7586 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007587 /* Post any pending iocbs to HBA */
7588 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007589 }
7590}
7591
James Smarte59058c2008-08-24 21:49:00 -04007592/**
James Smart3621a712009-04-06 18:47:14 -04007593 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007594 * @phba: pointer to lpfc hba data structure.
7595 * @iocb: pointer to lpfc command iocb data structure.
7596 *
7597 * This routine is used as the top-level API for issuing a fabric iocb command
7598 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7599 * function makes sure that only one fabric bound iocb will be outstanding at
7600 * any given time. As such, this function will first check to see whether there
7601 * is already an outstanding fabric iocb on the wire. If so, it will put the
7602 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7603 * issued later. Otherwise, it will issue the iocb on the wire and update the
7604 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7605 *
7606 * Note, this implementation has a potential sending out fabric IOCBs out of
7607 * order. The problem is caused by the construction of the "ready" boolen does
7608 * not include the condition that the internal fabric IOCB list is empty. As
7609 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7610 * ahead of the fabric IOCBs in the internal list.
7611 *
7612 * Return code
7613 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7614 * IOCB_ERROR - failed to issue fabric iocb
7615 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007616static int
James Smart92d7f7b2007-06-17 19:56:38 -05007617lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7618{
7619 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007620 int ready;
7621 int ret;
7622
7623 if (atomic_read(&phba->fabric_iocb_count) > 1)
7624 BUG();
7625
7626 spin_lock_irqsave(&phba->hbalock, iflags);
7627 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7628 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7629
James Smart7f5f3d02008-02-08 18:50:14 -05007630 if (ready)
7631 /* Increment fabric iocb count to hold the position */
7632 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007633 spin_unlock_irqrestore(&phba->hbalock, iflags);
7634 if (ready) {
7635 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7636 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7637 iocb->iocb_flag |= LPFC_IO_FABRIC;
7638
James Smart858c9f62007-06-17 19:56:39 -05007639 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7640 "Fabric sched2: ste:x%x",
7641 iocb->vport->port_state, 0, 0);
7642
James Smart3772a992009-05-22 14:50:54 -04007643 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007644
7645 if (ret == IOCB_ERROR) {
7646 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7647 iocb->fabric_iocb_cmpl = NULL;
7648 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7649 atomic_dec(&phba->fabric_iocb_count);
7650 }
7651 } else {
7652 spin_lock_irqsave(&phba->hbalock, iflags);
7653 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7654 spin_unlock_irqrestore(&phba->hbalock, iflags);
7655 ret = IOCB_SUCCESS;
7656 }
7657 return ret;
7658}
7659
James Smarte59058c2008-08-24 21:49:00 -04007660/**
James Smart3621a712009-04-06 18:47:14 -04007661 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007662 * @vport: pointer to a virtual N_Port data structure.
7663 *
7664 * This routine aborts all the IOCBs associated with a @vport from the
7665 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7666 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7667 * list, removes each IOCB associated with the @vport off the list, set the
7668 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7669 * associated with the IOCB.
7670 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007671static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007672{
7673 LIST_HEAD(completions);
7674 struct lpfc_hba *phba = vport->phba;
7675 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007676
7677 spin_lock_irq(&phba->hbalock);
7678 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7679 list) {
7680
7681 if (piocb->vport != vport)
7682 continue;
7683
7684 list_move_tail(&piocb->list, &completions);
7685 }
7686 spin_unlock_irq(&phba->hbalock);
7687
James Smarta257bf92009-04-06 18:48:10 -04007688 /* Cancel all the IOCBs from the completions list */
7689 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7690 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007691}
7692
James Smarte59058c2008-08-24 21:49:00 -04007693/**
James Smart3621a712009-04-06 18:47:14 -04007694 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007695 * @ndlp: pointer to a node-list data structure.
7696 *
7697 * This routine aborts all the IOCBs associated with an @ndlp from the
7698 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7699 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7700 * list, removes each IOCB associated with the @ndlp off the list, set the
7701 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7702 * associated with the IOCB.
7703 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007704void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7705{
7706 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007707 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007708 struct lpfc_iocbq *tmp_iocb, *piocb;
7709 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007710
7711 spin_lock_irq(&phba->hbalock);
7712 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7713 list) {
7714 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7715
7716 list_move_tail(&piocb->list, &completions);
7717 }
7718 }
7719 spin_unlock_irq(&phba->hbalock);
7720
James Smarta257bf92009-04-06 18:48:10 -04007721 /* Cancel all the IOCBs from the completions list */
7722 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7723 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007724}
7725
James Smarte59058c2008-08-24 21:49:00 -04007726/**
James Smart3621a712009-04-06 18:47:14 -04007727 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007728 * @phba: pointer to lpfc hba data structure.
7729 *
7730 * This routine aborts all the IOCBs currently on the driver internal
7731 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7732 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7733 * list, removes IOCBs off the list, set the status feild to
7734 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7735 * the IOCB.
7736 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007737void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7738{
7739 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007740
7741 spin_lock_irq(&phba->hbalock);
7742 list_splice_init(&phba->fabric_iocb_list, &completions);
7743 spin_unlock_irq(&phba->hbalock);
7744
James Smarta257bf92009-04-06 18:48:10 -04007745 /* Cancel all the IOCBs from the completions list */
7746 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7747 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007748}
James Smart6fb120a2009-05-22 14:52:59 -04007749
7750/**
James Smart1151e3e2011-02-16 12:39:35 -05007751 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7752 * @vport: pointer to lpfc vport data structure.
7753 *
7754 * This routine is invoked by the vport cleanup for deletions and the cleanup
7755 * for an ndlp on removal.
7756 **/
7757void
7758lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
7759{
7760 struct lpfc_hba *phba = vport->phba;
7761 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7762 unsigned long iflag = 0;
7763
7764 spin_lock_irqsave(&phba->hbalock, iflag);
7765 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7766 list_for_each_entry_safe(sglq_entry, sglq_next,
7767 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7768 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
7769 sglq_entry->ndlp = NULL;
7770 }
7771 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7772 spin_unlock_irqrestore(&phba->hbalock, iflag);
7773 return;
7774}
7775
7776/**
James Smart6fb120a2009-05-22 14:52:59 -04007777 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7778 * @phba: pointer to lpfc hba data structure.
7779 * @axri: pointer to the els xri abort wcqe structure.
7780 *
7781 * This routine is invoked by the worker thread to process a SLI4 slow-path
7782 * ELS aborted xri.
7783 **/
7784void
7785lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7786 struct sli4_wcqe_xri_aborted *axri)
7787{
7788 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05007789 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
7790
James Smart6fb120a2009-05-22 14:52:59 -04007791 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7792 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05007793 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04007794 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007795
James Smart0f65ff62010-02-26 14:14:23 -05007796 spin_lock_irqsave(&phba->hbalock, iflag);
7797 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007798 list_for_each_entry_safe(sglq_entry, sglq_next,
7799 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7800 if (sglq_entry->sli4_xritag == xri) {
7801 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05007802 ndlp = sglq_entry->ndlp;
7803 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04007804 list_add_tail(&sglq_entry->list,
7805 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007806 sglq_entry->state = SGL_FREED;
7807 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007808 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart19ca7602010-11-20 23:11:55 -05007809 lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04007810
7811 /* Check if TXQ queue needs to be serviced */
7812 if (pring->txq_cnt)
7813 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007814 return;
7815 }
7816 }
James Smart0f65ff62010-02-26 14:14:23 -05007817 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7818 sglq_entry = __lpfc_get_active_sglq(phba, xri);
7819 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7820 spin_unlock_irqrestore(&phba->hbalock, iflag);
7821 return;
7822 }
7823 sglq_entry->state = SGL_XRI_ABORTED;
7824 spin_unlock_irqrestore(&phba->hbalock, iflag);
7825 return;
James Smart6fb120a2009-05-22 14:52:59 -04007826}