blob: 0b662db232848ddfe22bac96f3df1c624e4cce0b [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
James Smart5248a742011-07-22 18:37:06 -0400650 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart5af5eee2010-10-22 11:06:38 -0400651 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500652 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500653 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500654 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart5248a742011-07-22 18:37:06 -0400655 /*
656 * If VPI is unreged, driver need to do INIT_VPI
657 * before re-registering
658 */
James Smartecfd03c2010-02-12 14:41:27 -0500659 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
660 spin_unlock_irq(shost->host_lock);
661 }
James Smart38b92ef2010-08-04 16:11:39 -0400662 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
663 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
664 /*
665 * Driver needs to re-reg VPI in order for f/w
666 * to update the MAC address.
667 */
James Smart9589b062011-04-16 11:03:17 -0400668 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400669 lpfc_register_new_vport(phba, vport, ndlp);
670 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500671 }
672
James Smart6fb120a2009-05-22 14:52:59 -0400673 if (phba->sli_rev < LPFC_SLI_REV4) {
674 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
675 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
676 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
677 lpfc_register_new_vport(phba, vport, ndlp);
678 else
679 lpfc_issue_fabric_reglogin(vport);
680 } else {
681 ndlp->nlp_type |= NLP_FABRIC;
682 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500683 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
684 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400685 lpfc_start_fdiscs(phba);
686 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500687 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500688 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500689 else
James Smart6fb120a2009-05-22 14:52:59 -0400690 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500691 }
dea31012005-04-17 16:05:31 -0500692 return 0;
dea31012005-04-17 16:05:31 -0500693}
James Smarte59058c2008-08-24 21:49:00 -0400694/**
James Smart3621a712009-04-06 18:47:14 -0400695 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400696 * @vport: pointer to a host virtual N_Port data structure.
697 * @ndlp: pointer to a node-list data structure.
698 * @sp: pointer to service parameter data structure.
699 *
700 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
701 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
702 * in a point-to-point topology. First, the @vport's N_Port Name is compared
703 * with the received N_Port Name: if the @vport's N_Port Name is greater than
704 * the received N_Port Name lexicographically, this node shall assign local
705 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
706 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
707 * this node shall just wait for the remote node to issue PLOGI and assign
708 * N_Port IDs.
709 *
710 * Return code
711 * 0 - Success
712 * -ENXIO - Fail
713 **/
dea31012005-04-17 16:05:31 -0500714static int
James Smart2e0fef82007-06-17 19:56:36 -0500715lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
716 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500717{
James Smart2e0fef82007-06-17 19:56:36 -0500718 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
719 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500720 LPFC_MBOXQ_t *mbox;
721 int rc;
722
James Smart2e0fef82007-06-17 19:56:36 -0500723 spin_lock_irq(shost->host_lock);
724 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
725 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500726
727 phba->fc_edtov = FF_DEF_EDTOV;
728 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500729 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500730 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500731 if (rc >= 0) {
732 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500733 spin_lock_irq(shost->host_lock);
734 vport->fc_flag |= FC_PT2PT_PLOGI;
735 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500736
737 /*
738 * N_Port ID cannot be 0, set our to LocalID the other
739 * side will be RemoteID.
740 */
741
742 /* not equal */
743 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500744 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500745
746 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
747 if (!mbox)
748 goto fail;
749
750 lpfc_config_link(phba, mbox);
751
752 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500753 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400754 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500755 if (rc == MBX_NOT_FINISHED) {
756 mempool_free(mbox, phba->mbox_mem_pool);
757 goto fail;
758 }
James Smarte47c9092008-02-08 18:49:26 -0500759 /* Decrement ndlp reference count indicating that ndlp can be
760 * safely released when other references to it are done.
761 */
James Smart329f9bc2007-04-25 09:53:01 -0400762 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500763
James Smart2e0fef82007-06-17 19:56:36 -0500764 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500765 if (!ndlp) {
766 /*
767 * Cannot find existing Fabric ndlp, so allocate a
768 * new one
769 */
770 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
771 if (!ndlp)
772 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500773 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500774 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
775 ndlp = lpfc_enable_node(vport, ndlp,
776 NLP_STE_UNUSED_NODE);
777 if(!ndlp)
778 goto fail;
dea31012005-04-17 16:05:31 -0500779 }
780
781 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500782 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500783 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500784 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500785 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500786 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
787 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500788 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500789 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500790 } else
791 /* This side will wait for the PLOGI, decrement ndlp reference
792 * count indicating that ndlp can be released when other
793 * references to it are done.
794 */
James Smart329f9bc2007-04-25 09:53:01 -0400795 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500796
James Smart09372822008-01-11 01:52:54 -0500797 /* If we are pt2pt with another NPort, force NPIV off! */
798 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
799
James Smart2e0fef82007-06-17 19:56:36 -0500800 spin_lock_irq(shost->host_lock);
801 vport->fc_flag |= FC_PT2PT;
802 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500803
804 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500805 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500806 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500807fail:
dea31012005-04-17 16:05:31 -0500808 return -ENXIO;
809}
810
James Smarte59058c2008-08-24 21:49:00 -0400811/**
James Smart3621a712009-04-06 18:47:14 -0400812 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400813 * @phba: pointer to lpfc hba data structure.
814 * @cmdiocb: pointer to lpfc command iocb data structure.
815 * @rspiocb: pointer to lpfc response iocb data structure.
816 *
817 * This routine is the top-level completion callback function for issuing
818 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
819 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
820 * retry has been made (either immediately or delayed with lpfc_els_retry()
821 * returning 1), the command IOCB will be released and function returned.
822 * If the retry attempt has been given up (possibly reach the maximum
823 * number of retries), one additional decrement of ndlp reference shall be
824 * invoked before going out after releasing the command IOCB. This will
825 * actually release the remote node (Note, lpfc_els_free_iocb() will also
826 * invoke one decrement of ndlp reference count). If no error reported in
827 * the IOCB status, the command Port ID field is used to determine whether
828 * this is a point-to-point topology or a fabric topology: if the Port ID
829 * field is assigned, it is a fabric topology; otherwise, it is a
830 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
831 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
832 * specific topology completion conditions.
833 **/
dea31012005-04-17 16:05:31 -0500834static void
James Smart329f9bc2007-04-25 09:53:01 -0400835lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
836 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500837{
James Smart2e0fef82007-06-17 19:56:36 -0500838 struct lpfc_vport *vport = cmdiocb->vport;
839 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500840 IOCB_t *irsp = &rspiocb->iocb;
841 struct lpfc_nodelist *ndlp = cmdiocb->context1;
842 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
843 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500844 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500845 int rc;
846
847 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500848 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500849 /* One additional decrement on node reference count to
850 * trigger the release of the node
851 */
James Smart329f9bc2007-04-25 09:53:01 -0400852 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500853 goto out;
854 }
855
James Smart858c9f62007-06-17 19:56:39 -0500856 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
857 "FLOGI cmpl: status:x%x/x%x state:x%x",
858 irsp->ulpStatus, irsp->un.ulpWord[4],
859 vport->port_state);
860
dea31012005-04-17 16:05:31 -0500861 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500862 /*
James Smarta93ff372010-10-22 11:06:08 -0400863 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500864 * due to new FCF discovery
865 */
866 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smartdbb6b3a2010-06-08 18:31:37 -0400867 (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
James Smart9589b062011-04-16 11:03:17 -0400868 !((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
869 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500870 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400871 "2611 FLOGI failed on FCF (x%x), "
872 "status:x%x/x%x, tmo:x%x, perform "
873 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -0400874 phba->fcf.current_rec.fcf_indx,
875 irsp->ulpStatus, irsp->un.ulpWord[4],
876 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -0400877 lpfc_sli4_set_fcf_flogi_fail(phba,
878 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500879 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -0400880 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
881 if (rc)
882 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500883 }
884
James Smart38b92ef2010-08-04 16:11:39 -0400885 /* FLOGI failure */
886 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
887 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
888 irsp->ulpStatus, irsp->un.ulpWord[4],
889 irsp->ulpTimeout);
890
dea31012005-04-17 16:05:31 -0500891 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500892 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500893 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500894
James Smart76a95d72010-11-20 23:11:48 -0500895 /* FLOGI failure */
896 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
897 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
898 irsp->ulpStatus, irsp->un.ulpWord[4],
899 irsp->ulpTimeout);
900
dea31012005-04-17 16:05:31 -0500901 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500902 spin_lock_irq(shost->host_lock);
903 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
904 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500905
James Smart329f9bc2007-04-25 09:53:01 -0400906 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500907 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
908 * alpa map would take too long otherwise.
909 */
910 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400911 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -0500912 }
913 if ((phba->sli_rev == LPFC_SLI_REV4) &&
914 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
915 (vport->fc_prevDID != vport->fc_myDID))) {
916 if (vport->fc_flag & FC_VFI_REGISTERED)
917 lpfc_sli4_unreg_all_rpis(vport);
918 lpfc_issue_reg_vfi(vport);
919 lpfc_nlp_put(ndlp);
920 goto out;
dea31012005-04-17 16:05:31 -0500921 }
dea31012005-04-17 16:05:31 -0500922 goto flogifail;
923 }
James Smart695a8142010-01-26 23:08:03 -0500924 spin_lock_irq(shost->host_lock);
925 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400926 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500927 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500928
929 /*
930 * The FLogI succeeded. Sync the data for the CPU before
931 * accessing it.
932 */
933 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
934
935 sp = prsp->virt + sizeof(uint32_t);
936
937 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400938 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200939 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400940 "Data: x%x x%x x%x x%x\n",
941 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
942 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500943
James Smart2e0fef82007-06-17 19:56:36 -0500944 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500945 /*
946 * If Common Service Parameters indicate Nport
947 * we are point to point, if Fport we are Fabric.
948 */
949 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500950 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -0500951 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -0500952 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400953 else {
954 lpfc_printf_vlog(vport, KERN_ERR,
955 LOG_FIP | LOG_ELS,
956 "2831 FLOGI response with cleared Fabric "
957 "bit fcf_index 0x%x "
958 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
959 "Fabric Name "
960 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
961 phba->fcf.current_rec.fcf_indx,
962 phba->fcf.current_rec.switch_name[0],
963 phba->fcf.current_rec.switch_name[1],
964 phba->fcf.current_rec.switch_name[2],
965 phba->fcf.current_rec.switch_name[3],
966 phba->fcf.current_rec.switch_name[4],
967 phba->fcf.current_rec.switch_name[5],
968 phba->fcf.current_rec.switch_name[6],
969 phba->fcf.current_rec.switch_name[7],
970 phba->fcf.current_rec.fabric_name[0],
971 phba->fcf.current_rec.fabric_name[1],
972 phba->fcf.current_rec.fabric_name[2],
973 phba->fcf.current_rec.fabric_name[3],
974 phba->fcf.current_rec.fabric_name[4],
975 phba->fcf.current_rec.fabric_name[5],
976 phba->fcf.current_rec.fabric_name[6],
977 phba->fcf.current_rec.fabric_name[7]);
978 lpfc_nlp_put(ndlp);
979 spin_lock_irq(&phba->hbalock);
980 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400981 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -0400982 spin_unlock_irq(&phba->hbalock);
983 goto out;
984 }
James Smart0c9ab6f2010-02-26 14:15:57 -0500985 if (!rc) {
986 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400987 if (phba->hba_flag & HBA_FIP_SUPPORT)
988 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
989 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400990 "2769 FLOGI to FCF (x%x) "
991 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -0400992 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500993 spin_lock_irq(&phba->hbalock);
994 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400995 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -0500996 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500997 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500998 }
dea31012005-04-17 16:05:31 -0500999 }
1000
1001flogifail:
James Smart329f9bc2007-04-25 09:53:01 -04001002 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001003
James Smart858c9f62007-06-17 19:56:39 -05001004 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001005 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001006 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001007
1008 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001009 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001010 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1011 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
1012 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
1013 (phba->link_state != LPFC_CLEAR_LA)) {
1014 /* If FLOGI failed enable link interrupt. */
1015 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001016 }
dea31012005-04-17 16:05:31 -05001017out:
1018 lpfc_els_free_iocb(phba, cmdiocb);
1019}
1020
James Smarte59058c2008-08-24 21:49:00 -04001021/**
James Smart3621a712009-04-06 18:47:14 -04001022 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001023 * @vport: pointer to a host virtual N_Port data structure.
1024 * @ndlp: pointer to a node-list data structure.
1025 * @retry: number of retries to the command IOCB.
1026 *
1027 * This routine issues a Fabric Login (FLOGI) Request ELS command
1028 * for a @vport. The initiator service parameters are put into the payload
1029 * of the FLOGI Request IOCB and the top-level callback function pointer
1030 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1031 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1032 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1033 *
1034 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1035 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1036 * will be stored into the context1 field of the IOCB for the completion
1037 * callback function to the FLOGI ELS command.
1038 *
1039 * Return code
1040 * 0 - successfully issued flogi iocb for @vport
1041 * 1 - failed to issue flogi iocb for @vport
1042 **/
dea31012005-04-17 16:05:31 -05001043static int
James Smart2e0fef82007-06-17 19:56:36 -05001044lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001045 uint8_t retry)
1046{
James Smart2e0fef82007-06-17 19:56:36 -05001047 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001048 struct serv_parm *sp;
1049 IOCB_t *icmd;
1050 struct lpfc_iocbq *elsiocb;
1051 struct lpfc_sli_ring *pring;
1052 uint8_t *pcmd;
1053 uint16_t cmdsize;
1054 uint32_t tmo;
1055 int rc;
1056
1057 pring = &phba->sli.ring[LPFC_ELS_RING];
1058
James Smart92d7f7b2007-06-17 19:56:38 -05001059 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001060 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1061 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001062
James Smart488d1462006-03-07 15:02:37 -05001063 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001064 return 1;
dea31012005-04-17 16:05:31 -05001065
1066 icmd = &elsiocb->iocb;
1067 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1068
1069 /* For FLOGI request, remainder of payload is service parameters */
1070 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001071 pcmd += sizeof(uint32_t);
1072 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001073 sp = (struct serv_parm *) pcmd;
1074
1075 /* Setup CSPs accordingly for Fabric */
1076 sp->cmn.e_d_tov = 0;
1077 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001078 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001079 sp->cls1.classValid = 0;
1080 sp->cls2.seqDelivery = 1;
1081 sp->cls3.seqDelivery = 1;
1082 if (sp->cmn.fcphLow < FC_PH3)
1083 sp->cmn.fcphLow = FC_PH3;
1084 if (sp->cmn.fcphHigh < FC_PH3)
1085 sp->cmn.fcphHigh = FC_PH3;
1086
James Smartc31098c2011-04-16 11:03:33 -04001087 if (phba->sli_rev == LPFC_SLI_REV4) {
1088 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1089 LPFC_SLI_INTF_IF_TYPE_0) {
1090 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1091 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1092 /* FLOGI needs to be 3 for WQE FCFI */
1093 /* Set the fcfi to the fcfi we registered with */
1094 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1095 }
James Smart5248a742011-07-22 18:37:06 -04001096 } else {
1097 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1098 sp->cmn.request_multiple_Nport = 1;
1099 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1100 icmd->ulpCt_h = 1;
1101 icmd->ulpCt_l = 0;
1102 } else
1103 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001104 }
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 Smartdf9e1b52011-12-13 13:22:17 -05003070 if ((cmd == ELS_CMD_FLOGI) &&
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 Smartdf9e1b52011-12-13 13:22:17 -05003075 /* retry FLOGI forever */
James Smart6669f9b2009-10-02 15:16:45 -04003076 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;
James Smartdf9e1b52011-12-13 13:22:17 -05003081 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3082 /* retry FDISCs every second up to devloss */
3083 retry = 1;
3084 maxretry = vport->cfg_devloss_tmo;
3085 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04003086 }
3087
James Smart6669f9b2009-10-02 15:16:45 -04003088 cmdiocb->retry++;
3089 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003090 phba->fc_stat.elsRetryExceeded++;
3091 retry = 0;
3092 }
3093
James Smarted957682007-06-17 19:56:37 -05003094 if ((vport->load_flag & FC_UNLOADING) != 0)
3095 retry = 0;
3096
dea31012005-04-17 16:05:31 -05003097 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003098 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3099 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3100 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3101 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3102 "2849 Stop retry ELS command "
3103 "x%x to remote NPORT x%x, "
3104 "Data: x%x x%x\n", cmd, did,
3105 cmdiocb->retry, delay);
3106 return 0;
3107 }
3108 }
dea31012005-04-17 16:05:31 -05003109
3110 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003111 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3112 "0107 Retry ELS command x%x to remote "
3113 "NPORT x%x Data: x%x x%x\n",
3114 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003115
James Smart858c9f62007-06-17 19:56:39 -05003116 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3117 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3118 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
3119 /* Don't reset timer for no resources */
3120
dea31012005-04-17 16:05:31 -05003121 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003122 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003123 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003124 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003125 }
3126
3127 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003128 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003129 phba->fc_stat.elsDelayRetry++;
3130 ndlp->nlp_retry = cmdiocb->retry;
3131
James Smart92d7f7b2007-06-17 19:56:38 -05003132 /* delay is specified in milliseconds */
3133 mod_timer(&ndlp->nlp_delayfunc,
3134 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003135 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003136 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003137 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003138
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003139 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003140 if (cmd == ELS_CMD_PRLI)
3141 lpfc_nlp_set_state(vport, ndlp,
3142 NLP_STE_REG_LOGIN_ISSUE);
3143 else
3144 lpfc_nlp_set_state(vport, ndlp,
3145 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003146 ndlp->nlp_last_elscmd = cmd;
3147
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003148 return 1;
dea31012005-04-17 16:05:31 -05003149 }
3150 switch (cmd) {
3151 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003152 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003153 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003154 case ELS_CMD_FDISC:
3155 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3156 return 1;
dea31012005-04-17 16:05:31 -05003157 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003158 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003159 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003160 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003161 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003162 }
James Smart2e0fef82007-06-17 19:56:36 -05003163 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003164 return 1;
dea31012005-04-17 16:05:31 -05003165 case ELS_CMD_ADISC:
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_ADISC_ISSUE);
3168 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003169 return 1;
dea31012005-04-17 16:05:31 -05003170 case ELS_CMD_PRLI:
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_PRLI_ISSUE);
3173 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003174 return 1;
dea31012005-04-17 16:05:31 -05003175 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003176 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003177 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3178 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003179 return 1;
dea31012005-04-17 16:05:31 -05003180 }
3181 }
dea31012005-04-17 16:05:31 -05003182 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003183 if (logerr) {
3184 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3185 "0137 No retry ELS command x%x to remote "
3186 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3187 cmd, did, irsp->ulpStatus,
3188 irsp->un.ulpWord[4]);
3189 }
3190 else {
3191 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003192 "0108 No retry ELS command x%x to remote "
3193 "NPORT x%x Retried:%d Error:x%x/%x\n",
3194 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3195 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003196 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003197 return 0;
dea31012005-04-17 16:05:31 -05003198}
3199
James Smarte59058c2008-08-24 21:49:00 -04003200/**
James Smart3621a712009-04-06 18:47:14 -04003201 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003202 * @phba: pointer to lpfc hba data structure.
3203 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3204 *
3205 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3206 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3207 * checks to see whether there is a lpfc DMA buffer associated with the
3208 * response of the command IOCB. If so, it will be released before releasing
3209 * the lpfc DMA buffer associated with the IOCB itself.
3210 *
3211 * Return code
3212 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3213 **/
James Smart09372822008-01-11 01:52:54 -05003214static int
James Smart87af33f2007-10-27 13:37:43 -04003215lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3216{
3217 struct lpfc_dmabuf *buf_ptr;
3218
James Smarte59058c2008-08-24 21:49:00 -04003219 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003220 if (!list_empty(&buf_ptr1->list)) {
3221 list_remove_head(&buf_ptr1->list, buf_ptr,
3222 struct lpfc_dmabuf,
3223 list);
3224 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3225 kfree(buf_ptr);
3226 }
3227 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3228 kfree(buf_ptr1);
3229 return 0;
3230}
3231
James Smarte59058c2008-08-24 21:49:00 -04003232/**
James Smart3621a712009-04-06 18:47:14 -04003233 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003234 * @phba: pointer to lpfc hba data structure.
3235 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3236 *
3237 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3238 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3239 * pool.
3240 *
3241 * Return code
3242 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3243 **/
James Smart09372822008-01-11 01:52:54 -05003244static int
James Smart87af33f2007-10-27 13:37:43 -04003245lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3246{
3247 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3248 kfree(buf_ptr);
3249 return 0;
3250}
3251
James Smarte59058c2008-08-24 21:49:00 -04003252/**
James Smart3621a712009-04-06 18:47:14 -04003253 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003254 * @phba: pointer to lpfc hba data structure.
3255 * @elsiocb: pointer to lpfc els command iocb data structure.
3256 *
3257 * This routine frees a command IOCB and its associated resources. The
3258 * command IOCB data structure contains the reference to various associated
3259 * resources, these fields must be set to NULL if the associated reference
3260 * not present:
3261 * context1 - reference to ndlp
3262 * context2 - reference to cmd
3263 * context2->next - reference to rsp
3264 * context3 - reference to bpl
3265 *
3266 * It first properly decrements the reference count held on ndlp for the
3267 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3268 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3269 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3270 * adds the DMA buffer the @phba data structure for the delayed release.
3271 * If reference to the Buffer Pointer List (BPL) is present, the
3272 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3273 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3274 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3275 *
3276 * Return code
3277 * 0 - Success (currently, always return 0)
3278 **/
James Smart87af33f2007-10-27 13:37:43 -04003279int
James Smart329f9bc2007-04-25 09:53:01 -04003280lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003281{
3282 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003283 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003284
James Smarta8adb832007-10-27 13:37:53 -04003285 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3286 if (ndlp) {
3287 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3288 lpfc_nlp_put(ndlp);
3289
3290 /* If the ndlp is not being used by another discovery
3291 * thread, free it.
3292 */
3293 if (!lpfc_nlp_not_used(ndlp)) {
3294 /* If ndlp is being used by another discovery
3295 * thread, just clear NLP_DEFER_RM
3296 */
3297 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3298 }
3299 }
3300 else
3301 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003302 elsiocb->context1 = NULL;
3303 }
dea31012005-04-17 16:05:31 -05003304 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3305 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003306 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3307 /* Firmware could still be in progress of DMAing
3308 * payload, so don't free data buffer till after
3309 * a hbeat.
3310 */
3311 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3312 buf_ptr = elsiocb->context2;
3313 elsiocb->context2 = NULL;
3314 if (buf_ptr) {
3315 buf_ptr1 = NULL;
3316 spin_lock_irq(&phba->hbalock);
3317 if (!list_empty(&buf_ptr->list)) {
3318 list_remove_head(&buf_ptr->list,
3319 buf_ptr1, struct lpfc_dmabuf,
3320 list);
3321 INIT_LIST_HEAD(&buf_ptr1->list);
3322 list_add_tail(&buf_ptr1->list,
3323 &phba->elsbuf);
3324 phba->elsbuf_cnt++;
3325 }
3326 INIT_LIST_HEAD(&buf_ptr->list);
3327 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3328 phba->elsbuf_cnt++;
3329 spin_unlock_irq(&phba->hbalock);
3330 }
3331 } else {
3332 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3333 lpfc_els_free_data(phba, buf_ptr1);
3334 }
dea31012005-04-17 16:05:31 -05003335 }
3336
3337 if (elsiocb->context3) {
3338 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003339 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003340 }
James Bottomley604a3e32005-10-29 10:28:33 -05003341 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003342 return 0;
3343}
3344
James Smarte59058c2008-08-24 21:49:00 -04003345/**
James Smart3621a712009-04-06 18:47:14 -04003346 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003347 * @phba: pointer to lpfc hba data structure.
3348 * @cmdiocb: pointer to lpfc command iocb data structure.
3349 * @rspiocb: pointer to lpfc response iocb data structure.
3350 *
3351 * This routine is the completion callback function to the Logout (LOGO)
3352 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3353 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3354 * release the ndlp if it has the last reference remaining (reference count
3355 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3356 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3357 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3358 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3359 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3360 * IOCB data structure.
3361 **/
dea31012005-04-17 16:05:31 -05003362static void
James Smart2e0fef82007-06-17 19:56:36 -05003363lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3364 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003365{
James Smart2e0fef82007-06-17 19:56:36 -05003366 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3367 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003368 IOCB_t *irsp;
3369
3370 irsp = &rspiocb->iocb;
3371 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3372 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3373 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003374 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003375 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3376 "0109 ACC to LOGO completes to NPort x%x "
3377 "Data: x%x x%x x%x\n",
3378 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3379 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003380
3381 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3382 /* NPort Recovery mode or node is just allocated */
3383 if (!lpfc_nlp_not_used(ndlp)) {
3384 /* If the ndlp is being used by another discovery
3385 * thread, just unregister the RPI.
3386 */
3387 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003388 } else {
3389 /* Indicate the node has already released, should
3390 * not reference to it from within lpfc_els_free_iocb.
3391 */
3392 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003393 }
dea31012005-04-17 16:05:31 -05003394 }
James Smart73d91e52011-10-10 21:32:10 -04003395
3396 /*
3397 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05003398 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04003399 */
dea31012005-04-17 16:05:31 -05003400 lpfc_els_free_iocb(phba, cmdiocb);
James Smartdf9e1b52011-12-13 13:22:17 -05003401
3402 /*
3403 * Remove the ndlp reference if it's a fabric node that has
3404 * sent us an unsolicted LOGO.
3405 */
3406 if (ndlp->nlp_type & NLP_FABRIC)
3407 lpfc_nlp_put(ndlp);
3408
dea31012005-04-17 16:05:31 -05003409 return;
3410}
3411
James Smarte59058c2008-08-24 21:49:00 -04003412/**
James Smart3621a712009-04-06 18:47:14 -04003413 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003414 * @phba: pointer to lpfc hba data structure.
3415 * @pmb: pointer to the driver internal queue element for mailbox command.
3416 *
3417 * This routine is the completion callback function for unregister default
3418 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3419 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3420 * decrements the ndlp reference count held for this completion callback
3421 * function. After that, it invokes the lpfc_nlp_not_used() to check
3422 * whether there is only one reference left on the ndlp. If so, it will
3423 * perform one more decrement and trigger the release of the ndlp.
3424 **/
James Smart858c9f62007-06-17 19:56:39 -05003425void
3426lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3427{
3428 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3429 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3430
3431 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003432 pmb->context2 = NULL;
3433
James Smart858c9f62007-06-17 19:56:39 -05003434 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3435 kfree(mp);
3436 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003437 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003438 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003439 /* This is the end of the default RPI cleanup logic for this
3440 * ndlp. If no other discovery threads are using this ndlp.
3441 * we should free all resources associated with it.
3442 */
3443 lpfc_nlp_not_used(ndlp);
3444 }
James Smart3772a992009-05-22 14:50:54 -04003445
James Smart858c9f62007-06-17 19:56:39 -05003446 return;
3447}
3448
James Smarte59058c2008-08-24 21:49:00 -04003449/**
James Smart3621a712009-04-06 18:47:14 -04003450 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003451 * @phba: pointer to lpfc hba data structure.
3452 * @cmdiocb: pointer to lpfc command iocb data structure.
3453 * @rspiocb: pointer to lpfc response iocb data structure.
3454 *
3455 * This routine is the completion callback function for ELS Response IOCB
3456 * command. In normal case, this callback function just properly sets the
3457 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3458 * field in the command IOCB is not NULL, the referred mailbox command will
3459 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3460 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3461 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3462 * routine shall be invoked trying to release the ndlp if no other threads
3463 * are currently referring it.
3464 **/
dea31012005-04-17 16:05:31 -05003465static void
James Smart858c9f62007-06-17 19:56:39 -05003466lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003467 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003468{
James Smart2e0fef82007-06-17 19:56:36 -05003469 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3470 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3471 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003472 IOCB_t *irsp;
3473 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003474 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003475 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003476 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003477
James Smart33ccf8d2006-08-17 11:57:58 -04003478 irsp = &rspiocb->iocb;
3479
dea31012005-04-17 16:05:31 -05003480 if (cmdiocb->context_un.mbox)
3481 mbox = cmdiocb->context_un.mbox;
3482
James Smartfa4066b2008-01-11 01:53:27 -05003483 /* First determine if this is a LS_RJT cmpl. Note, this callback
3484 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3485 */
James Smart87af33f2007-10-27 13:37:43 -04003486 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003487 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3488 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003489 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003490 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003491 */
3492 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3493 ls_rjt = 1;
3494 }
3495
dea31012005-04-17 16:05:31 -05003496 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003497 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003498 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003499 mp = (struct lpfc_dmabuf *) mbox->context1;
3500 if (mp) {
3501 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3502 kfree(mp);
3503 }
James Smart329f9bc2007-04-25 09:53:01 -04003504 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003505 }
James Smart58da1ff2008-04-07 10:15:56 -04003506 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3507 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003508 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003509 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003510 /* Indicate the node has already released,
3511 * should not reference to it from within
3512 * the routine lpfc_els_free_iocb.
3513 */
3514 cmdiocb->context1 = NULL;
3515 }
dea31012005-04-17 16:05:31 -05003516 goto out;
3517 }
3518
James Smart858c9f62007-06-17 19:56:39 -05003519 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003520 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003521 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003522 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003523 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003524 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3525 "0110 ELS response tag x%x completes "
3526 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3527 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3528 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3529 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3530 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003531 if (mbox) {
3532 if ((rspiocb->iocb.ulpStatus == 0)
3533 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003534 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003535 /* Increment reference count to ndlp to hold the
3536 * reference to ndlp for the callback function.
3537 */
James Smart329f9bc2007-04-25 09:53:01 -04003538 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003539 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003540 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3541 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3542 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3543 }
3544 else {
3545 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3546 ndlp->nlp_prev_state = ndlp->nlp_state;
3547 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003548 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003549 }
James Smart0b727fe2007-10-27 13:37:25 -04003550 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003551 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003552 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003553 else
3554 /* Decrement the ndlp reference count we
3555 * set for this failed mailbox command.
3556 */
3557 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003558
3559 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3560 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3561 "0138 ELS rsp: Cannot issue reg_login for x%x "
3562 "Data: x%x x%x x%x\n",
3563 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3564 ndlp->nlp_rpi);
3565
James Smartfa4066b2008-01-11 01:53:27 -05003566 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003567 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003568 /* Indicate node has already been released,
3569 * should not reference to it from within
3570 * the routine lpfc_els_free_iocb.
3571 */
3572 cmdiocb->context1 = NULL;
3573 }
dea31012005-04-17 16:05:31 -05003574 } else {
James Smart858c9f62007-06-17 19:56:39 -05003575 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3576 if (!lpfc_error_lost_link(irsp) &&
3577 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003578 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003579 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003580 /* Indicate node has already been
3581 * released, should not reference
3582 * to it from within the routine
3583 * lpfc_els_free_iocb.
3584 */
3585 cmdiocb->context1 = NULL;
3586 }
dea31012005-04-17 16:05:31 -05003587 }
3588 }
James Smart14691152006-12-02 13:34:28 -05003589 mp = (struct lpfc_dmabuf *) mbox->context1;
3590 if (mp) {
3591 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3592 kfree(mp);
3593 }
3594 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003595 }
3596out:
James Smart58da1ff2008-04-07 10:15:56 -04003597 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003598 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003599 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003600 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003601
3602 /* If the node is not being used by another discovery thread,
3603 * and we are sending a reject, we are done with it.
3604 * Release driver reference count here and free associated
3605 * resources.
3606 */
3607 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003608 if (lpfc_nlp_not_used(ndlp))
3609 /* Indicate node has already been released,
3610 * should not reference to it from within
3611 * the routine lpfc_els_free_iocb.
3612 */
3613 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003614 }
James Smart87af33f2007-10-27 13:37:43 -04003615
dea31012005-04-17 16:05:31 -05003616 lpfc_els_free_iocb(phba, cmdiocb);
3617 return;
3618}
3619
James Smarte59058c2008-08-24 21:49:00 -04003620/**
James Smart3621a712009-04-06 18:47:14 -04003621 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003622 * @vport: pointer to a host virtual N_Port data structure.
3623 * @flag: the els command code to be accepted.
3624 * @oldiocb: pointer to the original lpfc command iocb data structure.
3625 * @ndlp: pointer to a node-list data structure.
3626 * @mbox: pointer to the driver internal queue element for mailbox command.
3627 *
3628 * This routine prepares and issues an Accept (ACC) response IOCB
3629 * command. It uses the @flag to properly set up the IOCB field for the
3630 * specific ACC response command to be issued and invokes the
3631 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3632 * @mbox pointer is passed in, it will be put into the context_un.mbox
3633 * field of the IOCB for the completion callback function to issue the
3634 * mailbox command to the HBA later when callback is invoked.
3635 *
3636 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3637 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3638 * will be stored into the context1 field of the IOCB for the completion
3639 * callback function to the corresponding response ELS IOCB command.
3640 *
3641 * Return code
3642 * 0 - Successfully issued acc response
3643 * 1 - Failed to issue acc response
3644 **/
dea31012005-04-17 16:05:31 -05003645int
James Smart2e0fef82007-06-17 19:56:36 -05003646lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3647 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003648 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003649{
James Smart2e0fef82007-06-17 19:56:36 -05003650 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3651 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003652 IOCB_t *icmd;
3653 IOCB_t *oldcmd;
3654 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003655 struct lpfc_sli *psli;
3656 uint8_t *pcmd;
3657 uint16_t cmdsize;
3658 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003659 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003660
3661 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003662 oldcmd = &oldiocb->iocb;
3663
3664 switch (flag) {
3665 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003666 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003667 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3668 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003669 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003670 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003671 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003672 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003673 return 1;
dea31012005-04-17 16:05:31 -05003674 }
James Smart2e0fef82007-06-17 19:56:36 -05003675
dea31012005-04-17 16:05:31 -05003676 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003677 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3678 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003679 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3680 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003681 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003682
3683 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3684 "Issue ACC: did:x%x flg:x%x",
3685 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003686 break;
3687 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003688 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003689 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3690 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003691 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003692 return 1;
James Smart488d1462006-03-07 15:02:37 -05003693
dea31012005-04-17 16:05:31 -05003694 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003695 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3696 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003697 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3698
3699 if (mbox)
3700 elsiocb->context_un.mbox = mbox;
3701
3702 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003703 pcmd += sizeof(uint32_t);
3704 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003705
3706 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3707 "Issue ACC PLOGI: did:x%x flg:x%x",
3708 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003709 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003710 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003711 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003712 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003713 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3714 if (!elsiocb)
3715 return 1;
3716
3717 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003718 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3719 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04003720 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3721
3722 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003723 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003724 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3725 els_pkt_ptr = (ELS_PKT *) pcmd;
3726 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003727
3728 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3729 "Issue ACC PRLO: did:x%x flg:x%x",
3730 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003731 break;
dea31012005-04-17 16:05:31 -05003732 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003733 return 1;
dea31012005-04-17 16:05:31 -05003734 }
dea31012005-04-17 16:05:31 -05003735 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003736 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3737 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3738 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3739 elsiocb->iotag, elsiocb->iocb.ulpContext,
3740 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3741 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003742 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003743 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003744 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003745 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003746 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3747 } else {
James Smart858c9f62007-06-17 19:56:39 -05003748 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003749 }
3750
3751 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003752 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003753 if (rc == IOCB_ERROR) {
3754 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003755 return 1;
dea31012005-04-17 16:05:31 -05003756 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003757 return 0;
dea31012005-04-17 16:05:31 -05003758}
3759
James Smarte59058c2008-08-24 21:49:00 -04003760/**
James Smart3621a712009-04-06 18:47:14 -04003761 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003762 * @vport: pointer to a virtual N_Port data structure.
3763 * @rejectError:
3764 * @oldiocb: pointer to the original lpfc command iocb data structure.
3765 * @ndlp: pointer to a node-list data structure.
3766 * @mbox: pointer to the driver internal queue element for mailbox command.
3767 *
3768 * This routine prepares and issue an Reject (RJT) response IOCB
3769 * command. If a @mbox pointer is passed in, it will be put into the
3770 * context_un.mbox field of the IOCB for the completion callback function
3771 * to issue to the HBA later.
3772 *
3773 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3774 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3775 * will be stored into the context1 field of the IOCB for the completion
3776 * callback function to the reject response ELS IOCB command.
3777 *
3778 * Return code
3779 * 0 - Successfully issued reject response
3780 * 1 - Failed to issue reject response
3781 **/
dea31012005-04-17 16:05:31 -05003782int
James Smart2e0fef82007-06-17 19:56:36 -05003783lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003784 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3785 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003786{
James Smart2e0fef82007-06-17 19:56:36 -05003787 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003788 IOCB_t *icmd;
3789 IOCB_t *oldcmd;
3790 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003791 struct lpfc_sli *psli;
3792 uint8_t *pcmd;
3793 uint16_t cmdsize;
3794 int rc;
3795
3796 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003797 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003798 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3799 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003800 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003801 return 1;
dea31012005-04-17 16:05:31 -05003802
3803 icmd = &elsiocb->iocb;
3804 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003805 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3806 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003807 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3808
3809 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003810 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003811 *((uint32_t *) (pcmd)) = rejectError;
3812
James Smart51ef4c22007-08-02 11:10:31 -04003813 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003814 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003815
dea31012005-04-17 16:05:31 -05003816 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003817 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3818 "0129 Xmit ELS RJT x%x response tag x%x "
3819 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3820 "rpi x%x\n",
3821 rejectError, elsiocb->iotag,
3822 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3823 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003824 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3825 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3826 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3827
dea31012005-04-17 16:05:31 -05003828 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003829 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003830 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003831
dea31012005-04-17 16:05:31 -05003832 if (rc == IOCB_ERROR) {
3833 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003834 return 1;
dea31012005-04-17 16:05:31 -05003835 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003836 return 0;
dea31012005-04-17 16:05:31 -05003837}
3838
James Smarte59058c2008-08-24 21:49:00 -04003839/**
James Smart3621a712009-04-06 18:47:14 -04003840 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003841 * @vport: pointer to a virtual N_Port data structure.
3842 * @oldiocb: pointer to the original lpfc command iocb data structure.
3843 * @ndlp: pointer to a node-list data structure.
3844 *
3845 * This routine prepares and issues an Accept (ACC) response to Address
3846 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3847 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3848 *
3849 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3850 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3851 * will be stored into the context1 field of the IOCB for the completion
3852 * callback function to the ADISC Accept response ELS IOCB command.
3853 *
3854 * Return code
3855 * 0 - Successfully issued acc adisc response
3856 * 1 - Failed to issue adisc acc response
3857 **/
dea31012005-04-17 16:05:31 -05003858int
James Smart2e0fef82007-06-17 19:56:36 -05003859lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3860 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003861{
James Smart2e0fef82007-06-17 19:56:36 -05003862 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003863 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003864 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003865 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003866 uint8_t *pcmd;
3867 uint16_t cmdsize;
3868 int rc;
3869
James Smart92d7f7b2007-06-17 19:56:38 -05003870 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003871 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3872 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003873 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003874 return 1;
dea31012005-04-17 16:05:31 -05003875
dea31012005-04-17 16:05:31 -05003876 icmd = &elsiocb->iocb;
3877 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003878 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3879 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04003880
3881 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003882 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3883 "0130 Xmit ADISC ACC response iotag x%x xri: "
3884 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3885 elsiocb->iotag, elsiocb->iocb.ulpContext,
3886 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3887 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003888 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3889
3890 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003891 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003892
3893 ap = (ADISC *) (pcmd);
3894 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003895 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3896 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003897 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003898
James Smart858c9f62007-06-17 19:56:39 -05003899 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3900 "Issue ACC ADISC: did:x%x flg:x%x",
3901 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3902
dea31012005-04-17 16:05:31 -05003903 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003904 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003905 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003906 if (rc == IOCB_ERROR) {
3907 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003908 return 1;
dea31012005-04-17 16:05:31 -05003909 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003910 return 0;
dea31012005-04-17 16:05:31 -05003911}
3912
James Smarte59058c2008-08-24 21:49:00 -04003913/**
James Smart3621a712009-04-06 18:47:14 -04003914 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003915 * @vport: pointer to a virtual N_Port data structure.
3916 * @oldiocb: pointer to the original lpfc command iocb data structure.
3917 * @ndlp: pointer to a node-list data structure.
3918 *
3919 * This routine prepares and issues an Accept (ACC) response to Process
3920 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3921 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3922 *
3923 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3924 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3925 * will be stored into the context1 field of the IOCB for the completion
3926 * callback function to the PRLI Accept response ELS IOCB command.
3927 *
3928 * Return code
3929 * 0 - Successfully issued acc prli response
3930 * 1 - Failed to issue acc prli response
3931 **/
dea31012005-04-17 16:05:31 -05003932int
James Smart2e0fef82007-06-17 19:56:36 -05003933lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003934 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003935{
James Smart2e0fef82007-06-17 19:56:36 -05003936 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003937 PRLI *npr;
3938 lpfc_vpd_t *vpd;
3939 IOCB_t *icmd;
3940 IOCB_t *oldcmd;
3941 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003942 struct lpfc_sli *psli;
3943 uint8_t *pcmd;
3944 uint16_t cmdsize;
3945 int rc;
3946
3947 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003948
James Smart92d7f7b2007-06-17 19:56:38 -05003949 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003950 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003951 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003952 if (!elsiocb)
3953 return 1;
dea31012005-04-17 16:05:31 -05003954
dea31012005-04-17 16:05:31 -05003955 icmd = &elsiocb->iocb;
3956 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003957 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3958 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
3959
James Smart5b8bd0c2007-04-25 09:52:49 -04003960 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003961 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3962 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3963 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3964 elsiocb->iotag, elsiocb->iocb.ulpContext,
3965 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3966 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003967 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3968
3969 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003970 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003971
3972 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003973 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003974
3975 npr = (PRLI *) pcmd;
3976 vpd = &phba->vpd;
3977 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003978 * If the remote port is a target and our firmware version is 3.20 or
3979 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003980 */
James Smart0d2b6b82008-06-14 22:52:47 -04003981 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3982 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003983 npr->ConfmComplAllowed = 1;
3984 npr->Retry = 1;
3985 npr->TaskRetryIdReq = 1;
3986 }
3987
3988 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3989 npr->estabImagePair = 1;
3990 npr->readXferRdyDis = 1;
3991 npr->ConfmComplAllowed = 1;
3992
3993 npr->prliType = PRLI_FCP_TYPE;
3994 npr->initiatorFunc = 1;
3995
James Smart858c9f62007-06-17 19:56:39 -05003996 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3997 "Issue ACC PRLI: did:x%x flg:x%x",
3998 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3999
dea31012005-04-17 16:05:31 -05004000 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004001 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004002
James Smart3772a992009-05-22 14:50:54 -04004003 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004004 if (rc == IOCB_ERROR) {
4005 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004006 return 1;
dea31012005-04-17 16:05:31 -05004007 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004008 return 0;
dea31012005-04-17 16:05:31 -05004009}
4010
James Smarte59058c2008-08-24 21:49:00 -04004011/**
James Smart3621a712009-04-06 18:47:14 -04004012 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004013 * @vport: pointer to a virtual N_Port data structure.
4014 * @format: rnid command format.
4015 * @oldiocb: pointer to the original lpfc command iocb data structure.
4016 * @ndlp: pointer to a node-list data structure.
4017 *
4018 * This routine issues a Request Node Identification Data (RNID) Accept
4019 * (ACC) response. It constructs the RNID ACC response command according to
4020 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4021 * issue the response. Note that this command does not need to hold the ndlp
4022 * reference count for the callback. So, the ndlp reference count taken by
4023 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4024 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4025 * there is no ndlp reference available.
4026 *
4027 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4028 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4029 * will be stored into the context1 field of the IOCB for the completion
4030 * callback function. However, for the RNID Accept Response ELS command,
4031 * this is undone later by this routine after the IOCB is allocated.
4032 *
4033 * Return code
4034 * 0 - Successfully issued acc rnid response
4035 * 1 - Failed to issue acc rnid response
4036 **/
dea31012005-04-17 16:05:31 -05004037static int
James Smart2e0fef82007-06-17 19:56:36 -05004038lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004039 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004040{
James Smart2e0fef82007-06-17 19:56:36 -05004041 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004042 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004043 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004044 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004045 struct lpfc_sli *psli;
4046 uint8_t *pcmd;
4047 uint16_t cmdsize;
4048 int rc;
4049
4050 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004051 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4052 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004053 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004054 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004055
James Smart2e0fef82007-06-17 19:56:36 -05004056 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4057 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004058 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004059 return 1;
dea31012005-04-17 16:05:31 -05004060
dea31012005-04-17 16:05:31 -05004061 icmd = &elsiocb->iocb;
4062 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004063 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4064 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4065
James Smart5b8bd0c2007-04-25 09:52:49 -04004066 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004067 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4068 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4069 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004070 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004071 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004072 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004073
James Smart92d7f7b2007-06-17 19:56:38 -05004074 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004075 rn = (RNID *) (pcmd);
4076 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004077 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4078 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4079 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004080 switch (format) {
4081 case 0:
4082 rn->SpecificLen = 0;
4083 break;
4084 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004085 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004086 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004087 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004088 rn->un.topologyDisc.unitType = RNID_HBA;
4089 rn->un.topologyDisc.physPort = 0;
4090 rn->un.topologyDisc.attachedNodes = 0;
4091 break;
4092 default:
4093 rn->CommonLen = 0;
4094 rn->SpecificLen = 0;
4095 break;
4096 }
4097
James Smart858c9f62007-06-17 19:56:39 -05004098 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4099 "Issue ACC RNID: did:x%x flg:x%x",
4100 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4101
dea31012005-04-17 16:05:31 -05004102 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004103 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004104
James Smart3772a992009-05-22 14:50:54 -04004105 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004106 if (rc == IOCB_ERROR) {
4107 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004108 return 1;
dea31012005-04-17 16:05:31 -05004109 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004110 return 0;
dea31012005-04-17 16:05:31 -05004111}
4112
James Smarte59058c2008-08-24 21:49:00 -04004113/**
James Smart19ca7602010-11-20 23:11:55 -05004114 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4115 * @vport: pointer to a virtual N_Port data structure.
4116 * @iocb: pointer to the lpfc command iocb data structure.
4117 * @ndlp: pointer to a node-list data structure.
4118 *
4119 * Return
4120 **/
4121static void
4122lpfc_els_clear_rrq(struct lpfc_vport *vport,
4123 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4124{
4125 struct lpfc_hba *phba = vport->phba;
4126 uint8_t *pcmd;
4127 struct RRQ *rrq;
4128 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004129 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004130 struct lpfc_node_rrq *prrq;
4131
4132
4133 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4134 pcmd += sizeof(uint32_t);
4135 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004136 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b062011-04-16 11:03:17 -04004137 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004138
4139 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4140 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4141 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004142 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b062011-04-16 11:03:17 -04004143 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004144 rxid,
4145 iocb->iotag, iocb->iocb.ulpContext);
4146
4147 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4148 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4149 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004150 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b062011-04-16 11:03:17 -04004151 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004152 else
4153 xri = rxid;
4154 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004155 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004156 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004157 return;
4158}
4159
4160/**
James Smart12265f62010-10-22 11:05:53 -04004161 * lpfc_els_rsp_echo_acc - Issue echo acc response
4162 * @vport: pointer to a virtual N_Port data structure.
4163 * @data: pointer to echo data to return in the accept.
4164 * @oldiocb: pointer to the original lpfc command iocb data structure.
4165 * @ndlp: pointer to a node-list data structure.
4166 *
4167 * Return code
4168 * 0 - Successfully issued acc echo response
4169 * 1 - Failed to issue acc echo response
4170 **/
4171static int
4172lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4173 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4174{
4175 struct lpfc_hba *phba = vport->phba;
4176 struct lpfc_iocbq *elsiocb;
4177 struct lpfc_sli *psli;
4178 uint8_t *pcmd;
4179 uint16_t cmdsize;
4180 int rc;
4181
4182 psli = &phba->sli;
4183 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4184
James Smartbf086112011-08-21 21:48:13 -04004185 /* The accumulated length can exceed the BPL_SIZE. For
4186 * now, use this as the limit
4187 */
4188 if (cmdsize > LPFC_BPL_SIZE)
4189 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04004190 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4191 ndlp->nlp_DID, ELS_CMD_ACC);
4192 if (!elsiocb)
4193 return 1;
4194
James Smart7851fe22011-07-22 18:36:52 -04004195 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4196 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4197
James Smart12265f62010-10-22 11:05:53 -04004198 /* Xmit ECHO ACC response tag <ulpIoTag> */
4199 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4200 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4201 elsiocb->iotag, elsiocb->iocb.ulpContext);
4202 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4203 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4204 pcmd += sizeof(uint32_t);
4205 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4206
4207 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4208 "Issue ACC ECHO: did:x%x flg:x%x",
4209 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4210
4211 phba->fc_stat.elsXmitACC++;
4212 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04004213
4214 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4215 if (rc == IOCB_ERROR) {
4216 lpfc_els_free_iocb(phba, elsiocb);
4217 return 1;
4218 }
4219 return 0;
4220}
4221
4222/**
James Smart3621a712009-04-06 18:47:14 -04004223 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004224 * @vport: pointer to a host virtual N_Port data structure.
4225 *
4226 * This routine issues Address Discover (ADISC) ELS commands to those
4227 * N_Ports which are in node port recovery state and ADISC has not been issued
4228 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4229 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4230 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4231 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4232 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4233 * IOCBs quit for later pick up. On the other hand, after walking through
4234 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4235 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4236 * no more ADISC need to be sent.
4237 *
4238 * Return code
4239 * The number of N_Ports with adisc issued.
4240 **/
dea31012005-04-17 16:05:31 -05004241int
James Smart2e0fef82007-06-17 19:56:36 -05004242lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004243{
James Smart2e0fef82007-06-17 19:56:36 -05004244 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004245 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004246 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004247
James Smart685f0bf2007-04-25 09:53:08 -04004248 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004249 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004250 if (!NLP_CHK_NODE_ACT(ndlp))
4251 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004252 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4253 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4254 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004255 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004256 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004257 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004258 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004259 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4260 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004261 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004262 vport->num_disc_nodes++;
4263 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004264 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004265 spin_lock_irq(shost->host_lock);
4266 vport->fc_flag |= FC_NLP_MORE;
4267 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004268 break;
dea31012005-04-17 16:05:31 -05004269 }
4270 }
4271 }
4272 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004273 spin_lock_irq(shost->host_lock);
4274 vport->fc_flag &= ~FC_NLP_MORE;
4275 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004276 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004277 return sentadisc;
dea31012005-04-17 16:05:31 -05004278}
4279
James Smarte59058c2008-08-24 21:49:00 -04004280/**
James Smart3621a712009-04-06 18:47:14 -04004281 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004282 * @vport: pointer to a host virtual N_Port data structure.
4283 *
4284 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4285 * which are in node port recovery state, with a @vport. Each time an ELS
4286 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4287 * the per @vport number of discover count (num_disc_nodes) shall be
4288 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4289 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4290 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4291 * later pick up. On the other hand, after walking through all the ndlps with
4292 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4293 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4294 * PLOGI need to be sent.
4295 *
4296 * Return code
4297 * The number of N_Ports with plogi issued.
4298 **/
dea31012005-04-17 16:05:31 -05004299int
James Smart2e0fef82007-06-17 19:56:36 -05004300lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004301{
James Smart2e0fef82007-06-17 19:56:36 -05004302 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004303 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004304 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004305
James Smart2e0fef82007-06-17 19:56:36 -05004306 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4307 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004308 if (!NLP_CHK_NODE_ACT(ndlp))
4309 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004310 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4311 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4312 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4313 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4314 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004315 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4316 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004317 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004318 vport->num_disc_nodes++;
4319 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004320 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004321 spin_lock_irq(shost->host_lock);
4322 vport->fc_flag |= FC_NLP_MORE;
4323 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004324 break;
dea31012005-04-17 16:05:31 -05004325 }
4326 }
4327 }
James Smart87af33f2007-10-27 13:37:43 -04004328 if (sentplogi) {
4329 lpfc_set_disctmo(vport);
4330 }
4331 else {
James Smart2e0fef82007-06-17 19:56:36 -05004332 spin_lock_irq(shost->host_lock);
4333 vport->fc_flag &= ~FC_NLP_MORE;
4334 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004335 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004336 return sentplogi;
dea31012005-04-17 16:05:31 -05004337}
4338
James Smarte59058c2008-08-24 21:49:00 -04004339/**
James Smart3621a712009-04-06 18:47:14 -04004340 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004341 * @vport: pointer to a host virtual N_Port data structure.
4342 *
4343 * This routine cleans up any Registration State Change Notification
4344 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4345 * @vport together with the host_lock is used to prevent multiple thread
4346 * trying to access the RSCN array on a same @vport at the same time.
4347 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004348void
James Smart2e0fef82007-06-17 19:56:36 -05004349lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004350{
James Smart2e0fef82007-06-17 19:56:36 -05004351 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4352 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004353 int i;
4354
James Smart7f5f3d02008-02-08 18:50:14 -05004355 spin_lock_irq(shost->host_lock);
4356 if (vport->fc_rscn_flush) {
4357 /* Another thread is walking fc_rscn_id_list on this vport */
4358 spin_unlock_irq(shost->host_lock);
4359 return;
4360 }
4361 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4362 vport->fc_rscn_flush = 1;
4363 spin_unlock_irq(shost->host_lock);
4364
James Smart2e0fef82007-06-17 19:56:36 -05004365 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004366 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004367 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004368 }
James Smart2e0fef82007-06-17 19:56:36 -05004369 spin_lock_irq(shost->host_lock);
4370 vport->fc_rscn_id_cnt = 0;
4371 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4372 spin_unlock_irq(shost->host_lock);
4373 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004374 /* Indicate we are done walking this fc_rscn_id_list */
4375 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004376}
4377
James Smarte59058c2008-08-24 21:49:00 -04004378/**
James Smart3621a712009-04-06 18:47:14 -04004379 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004380 * @vport: pointer to a host virtual N_Port data structure.
4381 * @did: remote destination port identifier.
4382 *
4383 * This routine checks whether there is any pending Registration State
4384 * Configuration Notification (RSCN) to a @did on @vport.
4385 *
4386 * Return code
4387 * None zero - The @did matched with a pending rscn
4388 * 0 - not able to match @did with a pending rscn
4389 **/
dea31012005-04-17 16:05:31 -05004390int
James Smart2e0fef82007-06-17 19:56:36 -05004391lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004392{
4393 D_ID ns_did;
4394 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004395 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004396 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004397 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004398
4399 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004400
4401 /* Never match fabric nodes for RSCNs */
4402 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004403 return 0;
dea31012005-04-17 16:05:31 -05004404
4405 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004406 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004407 return did;
dea31012005-04-17 16:05:31 -05004408
James Smart7f5f3d02008-02-08 18:50:14 -05004409 spin_lock_irq(shost->host_lock);
4410 if (vport->fc_rscn_flush) {
4411 /* Another thread is walking fc_rscn_id_list on this vport */
4412 spin_unlock_irq(shost->host_lock);
4413 return 0;
4414 }
4415 /* Indicate we are walking fc_rscn_id_list on this vport */
4416 vport->fc_rscn_flush = 1;
4417 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004418 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004419 lp = vport->fc_rscn_id_list[i]->virt;
4420 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4421 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004422 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004423 rscn_did.un.word = be32_to_cpu(*lp++);
4424 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004425 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4426 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004427 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4428 && (ns_did.un.b.area == rscn_did.un.b.area)
4429 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004430 goto return_did_out;
dea31012005-04-17 16:05:31 -05004431 break;
James Smarteaf15d52008-12-04 22:39:29 -05004432 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004433 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4434 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004435 goto return_did_out;
dea31012005-04-17 16:05:31 -05004436 break;
James Smarteaf15d52008-12-04 22:39:29 -05004437 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004438 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004439 goto return_did_out;
dea31012005-04-17 16:05:31 -05004440 break;
James Smarteaf15d52008-12-04 22:39:29 -05004441 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004442 goto return_did_out;
dea31012005-04-17 16:05:31 -05004443 }
4444 }
James Smart92d7f7b2007-06-17 19:56:38 -05004445 }
James Smart7f5f3d02008-02-08 18:50:14 -05004446 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4447 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004448 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004449return_did_out:
4450 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4451 vport->fc_rscn_flush = 0;
4452 return did;
dea31012005-04-17 16:05:31 -05004453}
4454
James Smarte59058c2008-08-24 21:49:00 -04004455/**
James Smart3621a712009-04-06 18:47:14 -04004456 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004457 * @vport: pointer to a host virtual N_Port data structure.
4458 *
4459 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4460 * state machine for a @vport's nodes that are with pending RSCN (Registration
4461 * State Change Notification).
4462 *
4463 * Return code
4464 * 0 - Successful (currently alway return 0)
4465 **/
dea31012005-04-17 16:05:31 -05004466static int
James Smart2e0fef82007-06-17 19:56:36 -05004467lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004468{
James Smart685f0bf2007-04-25 09:53:08 -04004469 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004470
James Smart0d2b6b82008-06-14 22:52:47 -04004471 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004472 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004473 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004474 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4475 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004476 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004477 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004478 NLP_EVT_DEVICE_RECOVERY);
4479 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004480 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004481 return 0;
dea31012005-04-17 16:05:31 -05004482}
4483
James Smarte59058c2008-08-24 21:49:00 -04004484/**
James Smart3621a712009-04-06 18:47:14 -04004485 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004486 * @vport: pointer to a host virtual N_Port data structure.
4487 * @cmdiocb: pointer to lpfc command iocb data structure.
4488 *
4489 * lpfc_send_rscn_event sends an RSCN netlink event to management
4490 * applications.
4491 */
4492static void
4493lpfc_send_rscn_event(struct lpfc_vport *vport,
4494 struct lpfc_iocbq *cmdiocb)
4495{
4496 struct lpfc_dmabuf *pcmd;
4497 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4498 uint32_t *payload_ptr;
4499 uint32_t payload_len;
4500 struct lpfc_rscn_event_header *rscn_event_data;
4501
4502 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4503 payload_ptr = (uint32_t *) pcmd->virt;
4504 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4505
4506 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4507 payload_len, GFP_KERNEL);
4508 if (!rscn_event_data) {
4509 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4510 "0147 Failed to allocate memory for RSCN event\n");
4511 return;
4512 }
4513 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4514 rscn_event_data->payload_length = payload_len;
4515 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4516 payload_len);
4517
4518 fc_host_post_vendor_event(shost,
4519 fc_get_event_number(),
4520 sizeof(struct lpfc_els_event_header) + payload_len,
4521 (char *)rscn_event_data,
4522 LPFC_NL_VENDOR_ID);
4523
4524 kfree(rscn_event_data);
4525}
4526
4527/**
James Smart3621a712009-04-06 18:47:14 -04004528 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004529 * @vport: pointer to a host virtual N_Port data structure.
4530 * @cmdiocb: pointer to lpfc command iocb data structure.
4531 * @ndlp: pointer to a node-list data structure.
4532 *
4533 * This routine processes an unsolicited RSCN (Registration State Change
4534 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4535 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4536 * discover state machine is about to begin discovery, it just accepts the
4537 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4538 * contains N_Port IDs for other vports on this HBA, it just accepts the
4539 * RSCN and ignore processing it. If the state machine is in the recovery
4540 * state, the fc_rscn_id_list of this @vport is walked and the
4541 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4542 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4543 * routine is invoked to handle the RSCN event.
4544 *
4545 * Return code
4546 * 0 - Just sent the acc response
4547 * 1 - Sent the acc response and waited for name server completion
4548 **/
dea31012005-04-17 16:05:31 -05004549static int
James Smart2e0fef82007-06-17 19:56:36 -05004550lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004551 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004552{
James Smart2e0fef82007-06-17 19:56:36 -05004553 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4554 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004555 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004556 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004557 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004558 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004559 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004560 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004561 int i;
dea31012005-04-17 16:05:31 -05004562
4563 icmd = &cmdiocb->iocb;
4564 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4565 lp = (uint32_t *) pcmd->virt;
4566
James Smart92d7f7b2007-06-17 19:56:38 -05004567 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4568 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004569 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004570 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4571 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004572 vport->fc_flag, payload_len, *lp,
4573 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004574
4575 /* Send an RSCN event to the management application */
4576 lpfc_send_rscn_event(vport, cmdiocb);
4577
James Smartd2873e42006-08-18 17:46:43 -04004578 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004579 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004580 FCH_EVT_RSCN, lp[i]);
4581
dea31012005-04-17 16:05:31 -05004582 /* If we are about to begin discovery, just ACC the RSCN.
4583 * Discovery processing will satisfy it.
4584 */
James Smart2e0fef82007-06-17 19:56:36 -05004585 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004586 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4587 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4588 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4589
James Smart51ef4c22007-08-02 11:10:31 -04004590 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004591 return 0;
dea31012005-04-17 16:05:31 -05004592 }
4593
James Smart92d7f7b2007-06-17 19:56:38 -05004594 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4595 * just ACC and ignore it.
4596 */
4597 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004598 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004599 i = payload_len;
4600 datap = lp;
4601 while (i > 0) {
4602 nportid = *datap++;
4603 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4604 i -= sizeof(uint32_t);
4605 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004606 if (lpfc_find_vport_by_did(phba, nportid))
4607 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004608 }
4609 if (rscn_id == hba_id) {
4610 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004611 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004612 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004613 "Data: x%x x%x x%x x%x\n",
4614 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004615 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004616 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4617 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4618 ndlp->nlp_DID, vport->port_state,
4619 ndlp->nlp_flag);
4620
James Smart92d7f7b2007-06-17 19:56:38 -05004621 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004622 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004623 return 0;
4624 }
4625 }
4626
James Smart7f5f3d02008-02-08 18:50:14 -05004627 spin_lock_irq(shost->host_lock);
4628 if (vport->fc_rscn_flush) {
4629 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004630 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004631 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004632 /* Send back ACC */
4633 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004634 return 0;
4635 }
4636 /* Indicate we are walking fc_rscn_id_list on this vport */
4637 vport->fc_rscn_flush = 1;
4638 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004639 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004640 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004641 /* If we are already processing an RSCN, save the received
4642 * RSCN payload buffer, cmdiocb->context2 to process later.
4643 */
James Smart2e0fef82007-06-17 19:56:36 -05004644 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004645 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4646 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4647 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4648
James Smart09372822008-01-11 01:52:54 -05004649 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004650 vport->fc_flag |= FC_RSCN_DEFERRED;
4651 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004652 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004653 vport->fc_flag |= FC_RSCN_MODE;
4654 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004655 if (rscn_cnt) {
4656 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4657 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4658 }
4659 if ((rscn_cnt) &&
4660 (payload_len + length <= LPFC_BPL_SIZE)) {
4661 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004662 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004663 memcpy(((uint8_t *)cmd) + length, lp,
4664 payload_len);
4665 } else {
4666 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4667 vport->fc_rscn_id_cnt++;
4668 /* If we zero, cmdiocb->context2, the calling
4669 * routine will not try to free it.
4670 */
4671 cmdiocb->context2 = NULL;
4672 }
dea31012005-04-17 16:05:31 -05004673 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004674 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4675 "0235 Deferred RSCN "
4676 "Data: x%x x%x x%x\n",
4677 vport->fc_rscn_id_cnt, vport->fc_flag,
4678 vport->port_state);
dea31012005-04-17 16:05:31 -05004679 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004680 vport->fc_flag |= FC_RSCN_DISCOVERY;
4681 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004682 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004683 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4684 "0234 ReDiscovery RSCN "
4685 "Data: x%x x%x x%x\n",
4686 vport->fc_rscn_id_cnt, vport->fc_flag,
4687 vport->port_state);
dea31012005-04-17 16:05:31 -05004688 }
James Smart7f5f3d02008-02-08 18:50:14 -05004689 /* Indicate we are done walking fc_rscn_id_list on this vport */
4690 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004691 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004692 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004693 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004694 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004695 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004696 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004697 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004698 return 0;
dea31012005-04-17 16:05:31 -05004699 }
James Smart858c9f62007-06-17 19:56:39 -05004700 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4701 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4702 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4703
James Smart2e0fef82007-06-17 19:56:36 -05004704 spin_lock_irq(shost->host_lock);
4705 vport->fc_flag |= FC_RSCN_MODE;
4706 spin_unlock_irq(shost->host_lock);
4707 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004708 /* Indicate we are done walking fc_rscn_id_list on this vport */
4709 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004710 /*
4711 * If we zero, cmdiocb->context2, the calling routine will
4712 * not try to free it.
4713 */
4714 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004715 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004716 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004717 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004718 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004719 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004720 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004721}
4722
James Smarte59058c2008-08-24 21:49:00 -04004723/**
James Smart3621a712009-04-06 18:47:14 -04004724 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004725 * @vport: pointer to a host virtual N_Port data structure.
4726 *
4727 * This routine handles the Registration State Configuration Notification
4728 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4729 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4730 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4731 * NameServer shall be issued. If CT command to the NameServer fails to be
4732 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4733 * RSCN activities with the @vport.
4734 *
4735 * Return code
4736 * 0 - Cleaned up rscn on the @vport
4737 * 1 - Wait for plogi to name server before proceed
4738 **/
dea31012005-04-17 16:05:31 -05004739int
James Smart2e0fef82007-06-17 19:56:36 -05004740lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004741{
4742 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004743 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004744
James Smart92d7f7b2007-06-17 19:56:38 -05004745 /* Ignore RSCN if the port is being torn down. */
4746 if (vport->load_flag & FC_UNLOADING) {
4747 lpfc_els_flush_rscn(vport);
4748 return 0;
4749 }
4750
dea31012005-04-17 16:05:31 -05004751 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004752 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004753
4754 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004755 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4756 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4757 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4758 vport->port_state);
dea31012005-04-17 16:05:31 -05004759
4760 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004761 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004762 vport->num_disc_nodes = 0;
4763
James Smart2e0fef82007-06-17 19:56:36 -05004764 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004765 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4766 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004767 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004768 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004769 /* Wait for NameServer query cmpl before we can
4770 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004771 return 1;
dea31012005-04-17 16:05:31 -05004772 } else {
4773 /* If login to NameServer does not exist, issue one */
4774 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004775 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004776 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004777 /* Wait for NameServer login cmpl before we can
4778 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004779 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004780
James Smarte47c9092008-02-08 18:49:26 -05004781 if (ndlp) {
4782 ndlp = lpfc_enable_node(vport, ndlp,
4783 NLP_STE_PLOGI_ISSUE);
4784 if (!ndlp) {
4785 lpfc_els_flush_rscn(vport);
4786 return 0;
4787 }
4788 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004789 } else {
James Smarte47c9092008-02-08 18:49:26 -05004790 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4791 if (!ndlp) {
4792 lpfc_els_flush_rscn(vport);
4793 return 0;
4794 }
James Smart2e0fef82007-06-17 19:56:36 -05004795 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004796 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004797 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004798 }
James Smarte47c9092008-02-08 18:49:26 -05004799 ndlp->nlp_type |= NLP_FABRIC;
4800 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4801 /* Wait for NameServer login cmpl before we can
4802 * continue
4803 */
4804 return 1;
dea31012005-04-17 16:05:31 -05004805 }
4806
James Smart2e0fef82007-06-17 19:56:36 -05004807 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004808 return 0;
dea31012005-04-17 16:05:31 -05004809}
4810
James Smarte59058c2008-08-24 21:49:00 -04004811/**
James Smart3621a712009-04-06 18:47:14 -04004812 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004813 * @vport: pointer to a host virtual N_Port data structure.
4814 * @cmdiocb: pointer to lpfc command iocb data structure.
4815 * @ndlp: pointer to a node-list data structure.
4816 *
4817 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4818 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4819 * point topology. As an unsolicited FLOGI should not be received in a loop
4820 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4821 * lpfc_check_sparm() routine is invoked to check the parameters in the
4822 * unsolicited FLOGI. If parameters validation failed, the routine
4823 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4824 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4825 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4826 * will initiate PLOGI. The higher lexicographical value party shall has
4827 * higher priority (as the winning port) and will initiate PLOGI and
4828 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4829 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4830 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4831 *
4832 * Return code
4833 * 0 - Successfully processed the unsolicited flogi
4834 * 1 - Failed to process the unsolicited flogi
4835 **/
dea31012005-04-17 16:05:31 -05004836static int
James Smart2e0fef82007-06-17 19:56:36 -05004837lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004838 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004839{
James Smart2e0fef82007-06-17 19:56:36 -05004840 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4841 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004842 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4843 uint32_t *lp = (uint32_t *) pcmd->virt;
4844 IOCB_t *icmd = &cmdiocb->iocb;
4845 struct serv_parm *sp;
4846 LPFC_MBOXQ_t *mbox;
4847 struct ls_rjt stat;
4848 uint32_t cmd, did;
4849 int rc;
4850
4851 cmd = *lp++;
4852 sp = (struct serv_parm *) lp;
4853
4854 /* FLOGI received */
4855
James Smart2e0fef82007-06-17 19:56:36 -05004856 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004857
James Smart76a95d72010-11-20 23:11:48 -05004858 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004859 /* We should never receive a FLOGI in loop mode, ignore it */
4860 did = icmd->un.elsreq64.remoteID;
4861
4862 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4863 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004864 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4865 "0113 An FLOGI ELS command x%x was "
4866 "received from DID x%x in Loop Mode\n",
4867 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004868 return 1;
dea31012005-04-17 16:05:31 -05004869 }
4870
4871 did = Fabric_DID;
4872
James Smart341af102010-01-26 23:07:37 -05004873 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004874 /* For a FLOGI we accept, then if our portname is greater
4875 * then the remote portname we initiate Nport login.
4876 */
4877
James Smart2e0fef82007-06-17 19:56:36 -05004878 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004879 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004880
4881 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004882 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4883 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004884 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004885
dea31012005-04-17 16:05:31 -05004886 lpfc_linkdown(phba);
4887 lpfc_init_link(phba, mbox,
4888 phba->cfg_topology,
4889 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004890 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004891 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004892 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004893 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004894 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004895 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004896 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004897 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004898 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004899 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004900 spin_lock_irq(shost->host_lock);
4901 vport->fc_flag |= FC_PT2PT_PLOGI;
4902 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004903 }
James Smart2e0fef82007-06-17 19:56:36 -05004904 spin_lock_irq(shost->host_lock);
4905 vport->fc_flag |= FC_PT2PT;
4906 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4907 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004908 } else {
4909 /* Reject this request because invalid parameters */
4910 stat.un.b.lsRjtRsvd0 = 0;
4911 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4912 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4913 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004914 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4915 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004916 return 1;
dea31012005-04-17 16:05:31 -05004917 }
4918
4919 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004920 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004921
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004922 return 0;
dea31012005-04-17 16:05:31 -05004923}
4924
James Smarte59058c2008-08-24 21:49:00 -04004925/**
James Smart3621a712009-04-06 18:47:14 -04004926 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004927 * @vport: pointer to a host virtual N_Port data structure.
4928 * @cmdiocb: pointer to lpfc command iocb data structure.
4929 * @ndlp: pointer to a node-list data structure.
4930 *
4931 * This routine processes Request Node Identification Data (RNID) IOCB
4932 * received as an ELS unsolicited event. Only when the RNID specified format
4933 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4934 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4935 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4936 * rejected by invoking the lpfc_els_rsp_reject() routine.
4937 *
4938 * Return code
4939 * 0 - Successfully processed rnid iocb (currently always return 0)
4940 **/
dea31012005-04-17 16:05:31 -05004941static int
James Smart2e0fef82007-06-17 19:56:36 -05004942lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4943 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004944{
4945 struct lpfc_dmabuf *pcmd;
4946 uint32_t *lp;
4947 IOCB_t *icmd;
4948 RNID *rn;
4949 struct ls_rjt stat;
4950 uint32_t cmd, did;
4951
4952 icmd = &cmdiocb->iocb;
4953 did = icmd->un.elsreq64.remoteID;
4954 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4955 lp = (uint32_t *) pcmd->virt;
4956
4957 cmd = *lp++;
4958 rn = (RNID *) lp;
4959
4960 /* RNID received */
4961
4962 switch (rn->Format) {
4963 case 0:
4964 case RNID_TOPOLOGY_DISC:
4965 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004966 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004967 break;
4968 default:
4969 /* Reject this request because format not supported */
4970 stat.un.b.lsRjtRsvd0 = 0;
4971 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4972 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4973 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004974 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4975 NULL);
dea31012005-04-17 16:05:31 -05004976 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004977 return 0;
dea31012005-04-17 16:05:31 -05004978}
4979
James Smarte59058c2008-08-24 21:49:00 -04004980/**
James Smart12265f62010-10-22 11:05:53 -04004981 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4982 * @vport: pointer to a host virtual N_Port data structure.
4983 * @cmdiocb: pointer to lpfc command iocb data structure.
4984 * @ndlp: pointer to a node-list data structure.
4985 *
4986 * Return code
4987 * 0 - Successfully processed echo iocb (currently always return 0)
4988 **/
4989static int
4990lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4991 struct lpfc_nodelist *ndlp)
4992{
4993 uint8_t *pcmd;
4994
4995 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4996
4997 /* skip over first word of echo command to find echo data */
4998 pcmd += sizeof(uint32_t);
4999
5000 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
5001 return 0;
5002}
5003
5004/**
James Smart3621a712009-04-06 18:47:14 -04005005 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04005006 * @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 Link Incident Report Registration(LIRR) IOCB
5011 * received as an ELS unsolicited event. Currently, this function just invokes
5012 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
5013 *
5014 * Return code
5015 * 0 - Successfully processed lirr iocb (currently always return 0)
5016 **/
dea31012005-04-17 16:05:31 -05005017static int
James Smart2e0fef82007-06-17 19:56:36 -05005018lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5019 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005020{
5021 struct ls_rjt stat;
5022
5023 /* For now, unconditionally reject this command */
5024 stat.un.b.lsRjtRsvd0 = 0;
5025 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5026 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5027 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005028 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005029 return 0;
5030}
5031
James Smarte59058c2008-08-24 21:49:00 -04005032/**
James Smart5ffc2662009-11-18 15:39:44 -05005033 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5034 * @vport: pointer to a host virtual N_Port data structure.
5035 * @cmdiocb: pointer to lpfc command iocb data structure.
5036 * @ndlp: pointer to a node-list data structure.
5037 *
5038 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5039 * received as an ELS unsolicited event. A request to RRQ shall only
5040 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5041 * Nx_Port N_Port_ID of the target Exchange is the same as the
5042 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5043 * not accepted, an LS_RJT with reason code "Unable to perform
5044 * command request" and reason code explanation "Invalid Originator
5045 * S_ID" shall be returned. For now, we just unconditionally accept
5046 * RRQ from the target.
5047 **/
5048static void
5049lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5050 struct lpfc_nodelist *ndlp)
5051{
5052 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05005053 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5054 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05005055}
5056
5057/**
James Smart12265f62010-10-22 11:05:53 -04005058 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5059 * @phba: pointer to lpfc hba data structure.
5060 * @pmb: pointer to the driver internal queue element for mailbox command.
5061 *
5062 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5063 * mailbox command. This callback function is to actually send the Accept
5064 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5065 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5066 * mailbox command, constructs the RPS response with the link statistics
5067 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5068 * response to the RPS.
5069 *
5070 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5071 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5072 * will be stored into the context1 field of the IOCB for the completion
5073 * callback function to the RPS Accept Response ELS IOCB command.
5074 *
5075 **/
5076static void
5077lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5078{
5079 MAILBOX_t *mb;
5080 IOCB_t *icmd;
5081 struct RLS_RSP *rls_rsp;
5082 uint8_t *pcmd;
5083 struct lpfc_iocbq *elsiocb;
5084 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005085 uint16_t oxid;
5086 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04005087 uint32_t cmdsize;
5088
5089 mb = &pmb->u.mb;
5090
5091 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005092 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5093 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04005094 pmb->context1 = NULL;
5095 pmb->context2 = NULL;
5096
5097 if (mb->mbxStatus) {
5098 mempool_free(pmb, phba->mbox_mem_pool);
5099 return;
5100 }
5101
5102 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
5103 mempool_free(pmb, phba->mbox_mem_pool);
5104 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5105 lpfc_max_els_tries, ndlp,
5106 ndlp->nlp_DID, ELS_CMD_ACC);
5107
5108 /* Decrement the ndlp reference count from previous mbox command */
5109 lpfc_nlp_put(ndlp);
5110
5111 if (!elsiocb)
5112 return;
5113
5114 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005115 icmd->ulpContext = rxid;
5116 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04005117
5118 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5119 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5120 pcmd += sizeof(uint32_t); /* Skip past command */
5121 rls_rsp = (struct RLS_RSP *)pcmd;
5122
5123 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5124 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5125 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5126 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5127 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5128 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
5129
5130 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5131 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5132 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5133 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5134 elsiocb->iotag, elsiocb->iocb.ulpContext,
5135 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5136 ndlp->nlp_rpi);
5137 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5138 phba->fc_stat.elsXmitACC++;
5139 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5140 lpfc_els_free_iocb(phba, elsiocb);
5141}
5142
5143/**
James Smart3621a712009-04-06 18:47:14 -04005144 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005145 * @phba: pointer to lpfc hba data structure.
5146 * @pmb: pointer to the driver internal queue element for mailbox command.
5147 *
5148 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5149 * mailbox command. This callback function is to actually send the Accept
5150 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5151 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5152 * mailbox command, constructs the RPS response with the link statistics
5153 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5154 * response to the RPS.
5155 *
5156 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5157 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5158 * will be stored into the context1 field of the IOCB for the completion
5159 * callback function to the RPS Accept Response ELS IOCB command.
5160 *
5161 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005162static void
James Smart329f9bc2007-04-25 09:53:01 -04005163lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005164{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005165 MAILBOX_t *mb;
5166 IOCB_t *icmd;
5167 RPS_RSP *rps_rsp;
5168 uint8_t *pcmd;
5169 struct lpfc_iocbq *elsiocb;
5170 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005171 uint16_t status;
5172 uint16_t oxid;
5173 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005174 uint32_t cmdsize;
5175
James Smart04c68492009-05-22 14:52:52 -04005176 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005177
5178 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005179 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5180 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07005181 pmb->context1 = NULL;
5182 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005183
5184 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005185 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005186 return;
5187 }
5188
5189 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005190 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005191 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5192 lpfc_max_els_tries, ndlp,
5193 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005194
5195 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005196 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005197
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005198 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005199 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005200
5201 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005202 icmd->ulpContext = rxid;
5203 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005204
5205 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5206 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005207 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005208 rps_rsp = (RPS_RSP *)pcmd;
5209
James Smart76a95d72010-11-20 23:11:48 -05005210 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005211 status = 0x10;
5212 else
5213 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005214 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005215 status |= 0x4;
5216
5217 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005218 rps_rsp->portStatus = cpu_to_be16(status);
5219 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5220 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5221 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5222 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5223 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5224 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005225 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005226 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5227 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5228 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5229 elsiocb->iotag, elsiocb->iocb.ulpContext,
5230 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5231 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005232 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005233 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005234 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005235 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005236 return;
5237}
5238
James Smarte59058c2008-08-24 21:49:00 -04005239/**
James Smart12265f62010-10-22 11:05:53 -04005240 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5241 * @vport: pointer to a host virtual N_Port data structure.
5242 * @cmdiocb: pointer to lpfc command iocb data structure.
5243 * @ndlp: pointer to a node-list data structure.
5244 *
5245 * This routine processes Read Port Status (RPL) IOCB received as an
5246 * ELS unsolicited event. It first checks the remote port state. If the
5247 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5248 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5249 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5250 * for reading the HBA link statistics. It is for the callback function,
5251 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5252 * to actually sending out RPL Accept (ACC) response.
5253 *
5254 * Return codes
5255 * 0 - Successfully processed rls iocb (currently always return 0)
5256 **/
5257static int
5258lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5259 struct lpfc_nodelist *ndlp)
5260{
5261 struct lpfc_hba *phba = vport->phba;
5262 LPFC_MBOXQ_t *mbox;
5263 struct lpfc_dmabuf *pcmd;
5264 struct ls_rjt stat;
5265
5266 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5267 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5268 /* reject the unsolicited RPS request and done with it */
5269 goto reject_out;
5270
5271 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5272
5273 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5274 if (mbox) {
5275 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005276 mbox->context1 = (void *)((unsigned long)
5277 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5278 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04005279 mbox->context2 = lpfc_nlp_get(ndlp);
5280 mbox->vport = vport;
5281 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5282 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5283 != MBX_NOT_FINISHED)
5284 /* Mbox completion will send ELS Response */
5285 return 0;
5286 /* Decrement reference count used for the failed mbox
5287 * command.
5288 */
5289 lpfc_nlp_put(ndlp);
5290 mempool_free(mbox, phba->mbox_mem_pool);
5291 }
5292reject_out:
5293 /* issue rejection response */
5294 stat.un.b.lsRjtRsvd0 = 0;
5295 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5296 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5297 stat.un.b.vendorUnique = 0;
5298 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5299 return 0;
5300}
5301
5302/**
5303 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5304 * @vport: pointer to a host virtual N_Port data structure.
5305 * @cmdiocb: pointer to lpfc command iocb data structure.
5306 * @ndlp: pointer to a node-list data structure.
5307 *
5308 * This routine processes Read Timout Value (RTV) IOCB received as an
5309 * ELS unsolicited event. It first checks the remote port state. If the
5310 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5311 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5312 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5313 * Value (RTV) unsolicited IOCB event.
5314 *
5315 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5316 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5317 * will be stored into the context1 field of the IOCB for the completion
5318 * callback function to the RPS Accept Response ELS IOCB command.
5319 *
5320 * Return codes
5321 * 0 - Successfully processed rtv iocb (currently always return 0)
5322 **/
5323static int
5324lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5325 struct lpfc_nodelist *ndlp)
5326{
5327 struct lpfc_hba *phba = vport->phba;
5328 struct ls_rjt stat;
5329 struct RTV_RSP *rtv_rsp;
5330 uint8_t *pcmd;
5331 struct lpfc_iocbq *elsiocb;
5332 uint32_t cmdsize;
5333
5334
5335 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5336 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5337 /* reject the unsolicited RPS request and done with it */
5338 goto reject_out;
5339
5340 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5341 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5342 lpfc_max_els_tries, ndlp,
5343 ndlp->nlp_DID, ELS_CMD_ACC);
5344
5345 if (!elsiocb)
5346 return 1;
5347
5348 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5349 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5350 pcmd += sizeof(uint32_t); /* Skip past command */
5351
5352 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04005353 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
5354 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04005355
5356 rtv_rsp = (struct RTV_RSP *)pcmd;
5357
5358 /* populate RTV payload */
5359 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5360 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5361 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5362 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5363 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5364
5365 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5366 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5367 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5368 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5369 "Data: x%x x%x x%x\n",
5370 elsiocb->iotag, elsiocb->iocb.ulpContext,
5371 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5372 ndlp->nlp_rpi,
5373 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5374 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5375 phba->fc_stat.elsXmitACC++;
5376 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5377 lpfc_els_free_iocb(phba, elsiocb);
5378 return 0;
5379
5380reject_out:
5381 /* issue rejection response */
5382 stat.un.b.lsRjtRsvd0 = 0;
5383 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5384 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5385 stat.un.b.vendorUnique = 0;
5386 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5387 return 0;
5388}
5389
5390/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005391 * @vport: pointer to a host virtual N_Port data structure.
5392 * @cmdiocb: pointer to lpfc command iocb data structure.
5393 * @ndlp: pointer to a node-list data structure.
5394 *
5395 * This routine processes Read Port Status (RPS) IOCB received as an
5396 * ELS unsolicited event. It first checks the remote port state. If the
5397 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5398 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5399 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5400 * for reading the HBA link statistics. It is for the callback function,
5401 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5402 * to actually sending out RPS Accept (ACC) response.
5403 *
5404 * Return codes
5405 * 0 - Successfully processed rps iocb (currently always return 0)
5406 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005407static int
James Smart2e0fef82007-06-17 19:56:36 -05005408lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5409 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005410{
James Smart2e0fef82007-06-17 19:56:36 -05005411 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005412 uint32_t *lp;
5413 uint8_t flag;
5414 LPFC_MBOXQ_t *mbox;
5415 struct lpfc_dmabuf *pcmd;
5416 RPS *rps;
5417 struct ls_rjt stat;
5418
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005419 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005420 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5421 /* reject the unsolicited RPS request and done with it */
5422 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005423
5424 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5425 lp = (uint32_t *) pcmd->virt;
5426 flag = (be32_to_cpu(*lp++) & 0xf);
5427 rps = (RPS *) lp;
5428
5429 if ((flag == 0) ||
5430 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005431 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005432 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005433
James Smart92d7f7b2007-06-17 19:56:38 -05005434 printk("Fix me....\n");
5435 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005436 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5437 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005438 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005439 mbox->context1 = (void *)((unsigned long)
5440 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5441 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04005442 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005443 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005444 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005445 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005446 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005447 /* Mbox completion will send ELS Response */
5448 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005449 /* Decrement reference count used for the failed mbox
5450 * command.
5451 */
James Smart329f9bc2007-04-25 09:53:01 -04005452 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005453 mempool_free(mbox, phba->mbox_mem_pool);
5454 }
5455 }
James Smart90160e02008-08-24 21:49:45 -04005456
5457reject_out:
5458 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005459 stat.un.b.lsRjtRsvd0 = 0;
5460 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5461 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5462 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005463 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005464 return 0;
5465}
5466
James Smart19ca7602010-11-20 23:11:55 -05005467/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5468 * @vport: pointer to a host virtual N_Port data structure.
5469 * @ndlp: pointer to a node-list data structure.
5470 * @did: DID of the target.
5471 * @rrq: Pointer to the rrq struct.
5472 *
5473 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5474 * Successful the the completion handler will clear the RRQ.
5475 *
5476 * Return codes
5477 * 0 - Successfully sent rrq els iocb.
5478 * 1 - Failed to send rrq els iocb.
5479 **/
5480static int
5481lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5482 uint32_t did, struct lpfc_node_rrq *rrq)
5483{
5484 struct lpfc_hba *phba = vport->phba;
5485 struct RRQ *els_rrq;
5486 IOCB_t *icmd;
5487 struct lpfc_iocbq *elsiocb;
5488 uint8_t *pcmd;
5489 uint16_t cmdsize;
5490 int ret;
5491
5492
5493 if (ndlp != rrq->ndlp)
5494 ndlp = rrq->ndlp;
5495 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5496 return 1;
5497
5498 /* If ndlp is not NULL, we will bump the reference count on it */
5499 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5500 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5501 ELS_CMD_RRQ);
5502 if (!elsiocb)
5503 return 1;
5504
5505 icmd = &elsiocb->iocb;
5506 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5507
5508 /* For RRQ request, remainder of payload is Exchange IDs */
5509 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5510 pcmd += sizeof(uint32_t);
5511 els_rrq = (struct RRQ *) pcmd;
5512
5513 bf_set(rrq_oxid, els_rrq, rrq->xritag);
5514 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5515 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5516 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5517 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5518
5519
5520 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5521 "Issue RRQ: did:x%x",
5522 did, rrq->xritag, rrq->rxid);
5523 elsiocb->context_un.rrq = rrq;
5524 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5525 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5526
5527 if (ret == IOCB_ERROR) {
5528 lpfc_els_free_iocb(phba, elsiocb);
5529 return 1;
5530 }
5531 return 0;
5532}
5533
5534/**
5535 * lpfc_send_rrq - Sends ELS RRQ if needed.
5536 * @phba: pointer to lpfc hba data structure.
5537 * @rrq: pointer to the active rrq.
5538 *
5539 * This routine will call the lpfc_issue_els_rrq if the rrq is
5540 * still active for the xri. If this function returns a failure then
5541 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5542 *
5543 * Returns 0 Success.
5544 * 1 Failure.
5545 **/
5546int
5547lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5548{
5549 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5550 rrq->nlp_DID);
5551 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5552 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5553 rrq->nlp_DID, rrq);
5554 else
5555 return 1;
5556}
5557
James Smarte59058c2008-08-24 21:49:00 -04005558/**
James Smart3621a712009-04-06 18:47:14 -04005559 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005560 * @vport: pointer to a host virtual N_Port data structure.
5561 * @cmdsize: size of the ELS command.
5562 * @oldiocb: pointer to the original lpfc command iocb data structure.
5563 * @ndlp: pointer to a node-list data structure.
5564 *
5565 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5566 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5567 *
5568 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5569 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5570 * will be stored into the context1 field of the IOCB for the completion
5571 * callback function to the RPL Accept Response ELS command.
5572 *
5573 * Return code
5574 * 0 - Successfully issued ACC RPL ELS command
5575 * 1 - Failed to issue ACC RPL ELS command
5576 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005577static int
James Smart2e0fef82007-06-17 19:56:36 -05005578lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5579 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005580{
James Smart2e0fef82007-06-17 19:56:36 -05005581 struct lpfc_hba *phba = vport->phba;
5582 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005583 RPL_RSP rpl_rsp;
5584 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005585 uint8_t *pcmd;
5586
James Smart2e0fef82007-06-17 19:56:36 -05005587 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5588 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005589
James Smart488d1462006-03-07 15:02:37 -05005590 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005591 return 1;
James Smart488d1462006-03-07 15:02:37 -05005592
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005593 icmd = &elsiocb->iocb;
5594 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005595 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5596 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005597
5598 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5599 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005600 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005601 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5602 pcmd += sizeof(uint16_t);
5603
5604 /* Setup the RPL ACC payload */
5605 rpl_rsp.listLen = be32_to_cpu(1);
5606 rpl_rsp.index = 0;
5607 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005608 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5609 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005610 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005611 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005612 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005613 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5614 "0120 Xmit ELS RPL ACC response tag x%x "
5615 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5616 "rpi x%x\n",
5617 elsiocb->iotag, elsiocb->iocb.ulpContext,
5618 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5619 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005620 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005621 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005622 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5623 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005624 lpfc_els_free_iocb(phba, elsiocb);
5625 return 1;
5626 }
5627 return 0;
5628}
5629
James Smarte59058c2008-08-24 21:49:00 -04005630/**
James Smart3621a712009-04-06 18:47:14 -04005631 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005632 * @vport: pointer to a host virtual N_Port data structure.
5633 * @cmdiocb: pointer to lpfc command iocb data structure.
5634 * @ndlp: pointer to a node-list data structure.
5635 *
5636 * This routine processes Read Port List (RPL) IOCB received as an ELS
5637 * unsolicited event. It first checks the remote port state. If the remote
5638 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5639 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5640 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5641 * to accept the RPL.
5642 *
5643 * Return code
5644 * 0 - Successfully processed rpl iocb (currently always return 0)
5645 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005646static int
James Smart2e0fef82007-06-17 19:56:36 -05005647lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5648 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005649{
5650 struct lpfc_dmabuf *pcmd;
5651 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005652 uint32_t maxsize;
5653 uint16_t cmdsize;
5654 RPL *rpl;
5655 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005656
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005657 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5658 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005659 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005660 stat.un.b.lsRjtRsvd0 = 0;
5661 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5662 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5663 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005664 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5665 NULL);
James Smart90160e02008-08-24 21:49:45 -04005666 /* rejected the unsolicited RPL request and done with it */
5667 return 0;
dea31012005-04-17 16:05:31 -05005668 }
5669
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005670 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5671 lp = (uint32_t *) pcmd->virt;
5672 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005673 maxsize = be32_to_cpu(rpl->maxsize);
5674
5675 /* We support only one port */
5676 if ((rpl->index == 0) &&
5677 ((maxsize == 0) ||
5678 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5679 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005680 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005681 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5682 }
James Smart2e0fef82007-06-17 19:56:36 -05005683 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005684
5685 return 0;
5686}
5687
James Smarte59058c2008-08-24 21:49:00 -04005688/**
James Smart3621a712009-04-06 18:47:14 -04005689 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005690 * @vport: pointer to a virtual N_Port data structure.
5691 * @cmdiocb: pointer to lpfc command iocb data structure.
5692 * @ndlp: pointer to a node-list data structure.
5693 *
5694 * This routine processes Fibre Channel Address Resolution Protocol
5695 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5696 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5697 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5698 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5699 * remote PortName is compared against the FC PortName stored in the @vport
5700 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5701 * compared against the FC NodeName stored in the @vport data structure.
5702 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5703 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5704 * invoked to send out FARP Response to the remote node. Before sending the
5705 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5706 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5707 * routine is invoked to log into the remote port first.
5708 *
5709 * Return code
5710 * 0 - Either the FARP Match Mode not supported or successfully processed
5711 **/
dea31012005-04-17 16:05:31 -05005712static int
James Smart2e0fef82007-06-17 19:56:36 -05005713lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5714 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005715{
5716 struct lpfc_dmabuf *pcmd;
5717 uint32_t *lp;
5718 IOCB_t *icmd;
5719 FARP *fp;
5720 uint32_t cmd, cnt, did;
5721
5722 icmd = &cmdiocb->iocb;
5723 did = icmd->un.elsreq64.remoteID;
5724 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5725 lp = (uint32_t *) pcmd->virt;
5726
5727 cmd = *lp++;
5728 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005729 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005730 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5731 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005732 /* We will only support match on WWPN or WWNN */
5733 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005734 return 0;
dea31012005-04-17 16:05:31 -05005735 }
5736
5737 cnt = 0;
5738 /* If this FARP command is searching for my portname */
5739 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005740 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005741 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005742 cnt = 1;
5743 }
5744
5745 /* If this FARP command is searching for my nodename */
5746 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005747 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005748 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005749 cnt = 1;
5750 }
5751
5752 if (cnt) {
5753 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5754 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5755 /* Log back into the node before sending the FARP. */
5756 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005757 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005758 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005759 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005760 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005761 }
5762
5763 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005764 if (fp->Rflags & FARP_REQUEST_FARPR)
5765 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005766 }
5767 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005768 return 0;
dea31012005-04-17 16:05:31 -05005769}
5770
James Smarte59058c2008-08-24 21:49:00 -04005771/**
James Smart3621a712009-04-06 18:47:14 -04005772 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005773 * @vport: pointer to a host virtual N_Port data structure.
5774 * @cmdiocb: pointer to lpfc command iocb data structure.
5775 * @ndlp: pointer to a node-list data structure.
5776 *
5777 * This routine processes Fibre Channel Address Resolution Protocol
5778 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5779 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5780 * the FARP response request.
5781 *
5782 * Return code
5783 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5784 **/
dea31012005-04-17 16:05:31 -05005785static int
James Smart2e0fef82007-06-17 19:56:36 -05005786lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5787 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005788{
5789 struct lpfc_dmabuf *pcmd;
5790 uint32_t *lp;
5791 IOCB_t *icmd;
5792 uint32_t cmd, did;
5793
5794 icmd = &cmdiocb->iocb;
5795 did = icmd->un.elsreq64.remoteID;
5796 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5797 lp = (uint32_t *) pcmd->virt;
5798
5799 cmd = *lp++;
5800 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005801 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5802 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005803 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005804 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005805
5806 return 0;
5807}
5808
James Smarte59058c2008-08-24 21:49:00 -04005809/**
James Smart3621a712009-04-06 18:47:14 -04005810 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005811 * @vport: pointer to a host virtual N_Port data structure.
5812 * @cmdiocb: pointer to lpfc command iocb data structure.
5813 * @fan_ndlp: pointer to a node-list data structure.
5814 *
5815 * This routine processes a Fabric Address Notification (FAN) IOCB
5816 * command received as an ELS unsolicited event. The FAN ELS command will
5817 * only be processed on a physical port (i.e., the @vport represents the
5818 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5819 * compared against those in the phba data structure. If any of those is
5820 * different, the lpfc_initial_flogi() routine is invoked to initialize
5821 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5822 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5823 * is invoked to register login to the fabric.
5824 *
5825 * Return code
5826 * 0 - Successfully processed fan iocb (currently always return 0).
5827 **/
dea31012005-04-17 16:05:31 -05005828static int
James Smart2e0fef82007-06-17 19:56:36 -05005829lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5830 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005831{
James Smart2e0fef82007-06-17 19:56:36 -05005832 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005833 uint32_t *lp;
5834 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005835
James Smart0d2b6b82008-06-14 22:52:47 -04005836 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5837 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5838 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005839 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005840 if ((vport == phba->pport) &&
5841 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005842 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005843 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005844 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005845 sizeof(struct lpfc_name)))) {
5846 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05005847 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005848 } else {
5849 /* FAN verified - skip FLOGI */
5850 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005851 if (phba->sli_rev < LPFC_SLI_REV4)
5852 lpfc_issue_fabric_reglogin(vport);
5853 else
5854 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005855 }
dea31012005-04-17 16:05:31 -05005856 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005857 return 0;
dea31012005-04-17 16:05:31 -05005858}
5859
James Smarte59058c2008-08-24 21:49:00 -04005860/**
James Smart3621a712009-04-06 18:47:14 -04005861 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005862 * @ptr: holder for the timer function associated data.
5863 *
5864 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5865 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5866 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5867 * up the worker thread. It is for the worker thread to invoke the routine
5868 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5869 **/
dea31012005-04-17 16:05:31 -05005870void
5871lpfc_els_timeout(unsigned long ptr)
5872{
James Smart2e0fef82007-06-17 19:56:36 -05005873 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5874 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005875 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005876 unsigned long iflag;
5877
James Smart2e0fef82007-06-17 19:56:36 -05005878 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005879 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5880 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005881 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005882 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005883
James Smart5e9d9b82008-06-14 22:52:53 -04005884 if (!tmo_posted)
5885 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005886 return;
5887}
5888
James Smart2a9bf3d2010-06-07 15:24:45 -04005889
James Smarte59058c2008-08-24 21:49:00 -04005890/**
James Smart3621a712009-04-06 18:47:14 -04005891 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005892 * @vport: pointer to a virtual N_Port data structure.
5893 *
5894 * This routine is the actual handler function that processes an ELS timeout
5895 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5896 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5897 * invoking the lpfc_sli_issue_abort_iotag() routine.
5898 **/
dea31012005-04-17 16:05:31 -05005899void
James Smart2e0fef82007-06-17 19:56:36 -05005900lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005901{
James Smart2e0fef82007-06-17 19:56:36 -05005902 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005903 struct lpfc_sli_ring *pring;
5904 struct lpfc_iocbq *tmp_iocb, *piocb;
5905 IOCB_t *cmd = NULL;
5906 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005907 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005908 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005909 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005910 LIST_HEAD(txcmplq_completions);
5911 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005912
James Smart2a9bf3d2010-06-07 15:24:45 -04005913
dea31012005-04-17 16:05:31 -05005914 timeout = (uint32_t)(phba->fc_ratov << 1);
5915
5916 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005917
James Smart2a9bf3d2010-06-07 15:24:45 -04005918 spin_lock_irq(&phba->hbalock);
5919 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5920 spin_unlock_irq(&phba->hbalock);
5921
5922 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005923 cmd = &piocb->iocb;
5924
James Smart2e0fef82007-06-17 19:56:36 -05005925 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5926 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5927 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005928 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005929
5930 if (piocb->vport != vport)
5931 continue;
5932
dea31012005-04-17 16:05:31 -05005933 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005934 if (pcmd)
5935 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005936
James Smart92d7f7b2007-06-17 19:56:38 -05005937 if (els_command == ELS_CMD_FARP ||
5938 els_command == ELS_CMD_FARPR ||
5939 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005940 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005941
dea31012005-04-17 16:05:31 -05005942 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005943 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005944 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005945 else
dea31012005-04-17 16:05:31 -05005946 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005947 continue;
5948 }
5949
James Smart2e0fef82007-06-17 19:56:36 -05005950 remote_ID = 0xffffffff;
5951 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005952 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005953 else {
5954 struct lpfc_nodelist *ndlp;
5955 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005956 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005957 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005958 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005959 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05005960 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005961 spin_lock_irq(&phba->hbalock);
5962 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05005963 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005964
James Smart2a9bf3d2010-06-07 15:24:45 -04005965 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5966 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5967 "0127 ELS timeout Data: x%x x%x x%x "
5968 "x%x\n", els_command,
5969 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5970 spin_lock_irq(&phba->hbalock);
5971 list_del_init(&piocb->dlist);
5972 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5973 spin_unlock_irq(&phba->hbalock);
5974 }
5975
James Smart2e0fef82007-06-17 19:56:36 -05005976 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5977 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005978}
5979
James Smarte59058c2008-08-24 21:49:00 -04005980/**
James Smart3621a712009-04-06 18:47:14 -04005981 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005982 * @vport: pointer to a host virtual N_Port data structure.
5983 *
5984 * This routine is used to clean up all the outstanding ELS commands on a
5985 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5986 * routine. After that, it walks the ELS transmit queue to remove all the
5987 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5988 * the IOCBs with a non-NULL completion callback function, the callback
5989 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5990 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5991 * callback function, the IOCB will simply be released. Finally, it walks
5992 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5993 * completion queue IOCB that is associated with the @vport and is not
5994 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5995 * part of the discovery state machine) out to HBA by invoking the
5996 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5997 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5998 * the IOCBs are aborted when this function returns.
5999 **/
dea31012005-04-17 16:05:31 -05006000void
James Smart2e0fef82007-06-17 19:56:36 -05006001lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006002{
James Smart2534ba72007-04-25 09:52:20 -04006003 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05006004 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04006005 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006006 struct lpfc_iocbq *tmp_iocb, *piocb;
6007 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006008
6009 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05006010
James Smart2e0fef82007-06-17 19:56:36 -05006011 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006012 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6013 cmd = &piocb->iocb;
6014
6015 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6016 continue;
6017 }
6018
6019 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04006020 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6021 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6022 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6023 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05006024 continue;
dea31012005-04-17 16:05:31 -05006025
James Smart2e0fef82007-06-17 19:56:36 -05006026 if (piocb->vport != vport)
6027 continue;
6028
James Smart2534ba72007-04-25 09:52:20 -04006029 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04006030 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05006031 }
6032
6033 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05006034 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6035 continue;
6036 }
dea31012005-04-17 16:05:31 -05006037
James Smart2e0fef82007-06-17 19:56:36 -05006038 if (piocb->vport != vport)
6039 continue;
6040
James Smart07951072007-04-25 09:51:38 -04006041 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05006042 }
James Smart2e0fef82007-06-17 19:56:36 -05006043 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04006044
James Smarta257bf92009-04-06 18:48:10 -04006045 /* Cancell all the IOCBs from the completions list */
6046 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6047 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04006048
dea31012005-04-17 16:05:31 -05006049 return;
6050}
6051
James Smarte59058c2008-08-24 21:49:00 -04006052/**
James Smart3621a712009-04-06 18:47:14 -04006053 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04006054 * @phba: pointer to lpfc hba data structure.
6055 *
6056 * This routine is used to clean up all the outstanding ELS commands on a
6057 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6058 * routine. After that, it walks the ELS transmit queue to remove all the
6059 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6060 * the IOCBs with the completion callback function associated, the callback
6061 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6062 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6063 * callback function associated, the IOCB will simply be released. Finally,
6064 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6065 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6066 * management plane IOCBs that are not part of the discovery state machine)
6067 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6068 **/
James Smart549e55c2007-08-02 11:09:51 -04006069void
6070lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6071{
6072 LIST_HEAD(completions);
6073 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6074 struct lpfc_iocbq *tmp_iocb, *piocb;
6075 IOCB_t *cmd = NULL;
6076
6077 lpfc_fabric_abort_hba(phba);
6078 spin_lock_irq(&phba->hbalock);
6079 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6080 cmd = &piocb->iocb;
6081 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6082 continue;
6083 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6084 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6085 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6086 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6087 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6088 continue;
6089 list_move_tail(&piocb->list, &completions);
6090 pring->txq_cnt--;
6091 }
6092 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6093 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6094 continue;
6095 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6096 }
6097 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04006098
6099 /* Cancel all the IOCBs from the completions list */
6100 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6101 IOERR_SLI_ABORTED);
6102
James Smart549e55c2007-08-02 11:09:51 -04006103 return;
6104}
6105
James Smarte59058c2008-08-24 21:49:00 -04006106/**
James Smart3621a712009-04-06 18:47:14 -04006107 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04006108 * @phba: Pointer to hba context object.
6109 * @cmdiocbp: Pointer to command iocb which reported error.
6110 * @rspiocbp: Pointer to response iocb which reported error.
6111 *
6112 * This function sends an event when there is an ELS command
6113 * failure.
6114 **/
6115void
6116lpfc_send_els_failure_event(struct lpfc_hba *phba,
6117 struct lpfc_iocbq *cmdiocbp,
6118 struct lpfc_iocbq *rspiocbp)
6119{
6120 struct lpfc_vport *vport = cmdiocbp->vport;
6121 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6122 struct lpfc_lsrjt_event lsrjt_event;
6123 struct lpfc_fabric_event_header fabric_event;
6124 struct ls_rjt stat;
6125 struct lpfc_nodelist *ndlp;
6126 uint32_t *pcmd;
6127
6128 ndlp = cmdiocbp->context1;
6129 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6130 return;
6131
6132 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6133 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6134 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6135 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6136 sizeof(struct lpfc_name));
6137 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6138 sizeof(struct lpfc_name));
6139 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6140 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006141 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006142 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6143 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6144 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6145 fc_host_post_vendor_event(shost,
6146 fc_get_event_number(),
6147 sizeof(lsrjt_event),
6148 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006149 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006150 return;
6151 }
6152 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6153 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6154 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6155 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6156 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6157 else
6158 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6159 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6160 sizeof(struct lpfc_name));
6161 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6162 sizeof(struct lpfc_name));
6163 fc_host_post_vendor_event(shost,
6164 fc_get_event_number(),
6165 sizeof(fabric_event),
6166 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006167 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006168 return;
6169 }
6170
6171}
6172
6173/**
James Smart3621a712009-04-06 18:47:14 -04006174 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006175 * @vport: Pointer to vport object.
6176 * @ndlp: Pointer FC node object.
6177 * @cmd: ELS command code.
6178 *
6179 * This function posts an event when there is an incoming
6180 * unsolicited ELS command.
6181 **/
6182static void
6183lpfc_send_els_event(struct lpfc_vport *vport,
6184 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006185 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006186{
James Smartddcc50f2008-12-04 22:38:46 -05006187 struct lpfc_els_event_header *els_data = NULL;
6188 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006189 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6190
James Smartddcc50f2008-12-04 22:38:46 -05006191 if (*payload == ELS_CMD_LOGO) {
6192 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6193 if (!logo_data) {
6194 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6195 "0148 Failed to allocate memory "
6196 "for LOGO event\n");
6197 return;
6198 }
6199 els_data = &logo_data->header;
6200 } else {
6201 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6202 GFP_KERNEL);
6203 if (!els_data) {
6204 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6205 "0149 Failed to allocate memory "
6206 "for ELS event\n");
6207 return;
6208 }
6209 }
6210 els_data->event_type = FC_REG_ELS_EVENT;
6211 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006212 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006213 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006214 break;
6215 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006216 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006217 break;
6218 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006219 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6220 break;
6221 case ELS_CMD_LOGO:
6222 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6223 /* Copy the WWPN in the LOGO payload */
6224 memcpy(logo_data->logo_wwpn, &payload[2],
6225 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006226 break;
6227 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006228 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006229 return;
6230 }
James Smartddcc50f2008-12-04 22:38:46 -05006231 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6232 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6233 if (*payload == ELS_CMD_LOGO) {
6234 fc_host_post_vendor_event(shost,
6235 fc_get_event_number(),
6236 sizeof(struct lpfc_logo_event),
6237 (char *)logo_data,
6238 LPFC_NL_VENDOR_ID);
6239 kfree(logo_data);
6240 } else {
6241 fc_host_post_vendor_event(shost,
6242 fc_get_event_number(),
6243 sizeof(struct lpfc_els_event_header),
6244 (char *)els_data,
6245 LPFC_NL_VENDOR_ID);
6246 kfree(els_data);
6247 }
James Smartea2151b2008-09-07 11:52:10 -04006248
6249 return;
6250}
6251
6252
6253/**
James Smart3621a712009-04-06 18:47:14 -04006254 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006255 * @phba: pointer to lpfc hba data structure.
6256 * @pring: pointer to a SLI ring.
6257 * @vport: pointer to a host virtual N_Port data structure.
6258 * @elsiocb: pointer to lpfc els command iocb data structure.
6259 *
6260 * This routine is used for processing the IOCB associated with a unsolicited
6261 * event. It first determines whether there is an existing ndlp that matches
6262 * the DID from the unsolicited IOCB. If not, it will create a new one with
6263 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6264 * IOCB is then used to invoke the proper routine and to set up proper state
6265 * of the discovery state machine.
6266 **/
James Smarted957682007-06-17 19:56:37 -05006267static void
6268lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006269 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006270{
James Smart87af33f2007-10-27 13:37:43 -04006271 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006272 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006273 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006274 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05006275 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006276 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006277
James Smarte47c9092008-02-08 18:49:26 -05006278 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006279 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006280
dea31012005-04-17 16:05:31 -05006281 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006282 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6283 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006284 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006285 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006286
James Smart858c9f62007-06-17 19:56:39 -05006287 did = icmd->un.rcvels.remoteID;
6288 if (icmd->ulpStatus) {
6289 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6290 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6291 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006292 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006293 }
dea31012005-04-17 16:05:31 -05006294
6295 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006296 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006297 goto dropit;
dea31012005-04-17 16:05:31 -05006298
James Smartc8685952009-11-18 15:39:16 -05006299 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006300 if (vport->load_flag & FC_UNLOADING)
6301 goto dropit;
6302
James Smart92494142011-02-16 12:39:44 -05006303 /* If NPort discovery is delayed drop incoming ELS */
6304 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6305 (cmd != ELS_CMD_PLOGI))
6306 goto dropit;
6307
James Smart2e0fef82007-06-17 19:56:36 -05006308 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006309 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006310 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006311 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006312 if (!ndlp)
dea31012005-04-17 16:05:31 -05006313 goto dropit;
dea31012005-04-17 16:05:31 -05006314
James Smart2e0fef82007-06-17 19:56:36 -05006315 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006316 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006317 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006318 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006319 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006320 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6321 ndlp = lpfc_enable_node(vport, ndlp,
6322 NLP_STE_UNUSED_NODE);
6323 if (!ndlp)
6324 goto dropit;
6325 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6326 newnode = 1;
6327 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6328 ndlp->nlp_type |= NLP_FABRIC;
6329 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6330 /* This is similar to the new node path */
6331 ndlp = lpfc_nlp_get(ndlp);
6332 if (!ndlp)
6333 goto dropit;
6334 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6335 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006336 }
dea31012005-04-17 16:05:31 -05006337
6338 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006339
James Smart329f9bc2007-04-25 09:53:01 -04006340 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006341 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006342
6343 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6344 cmd &= ELS_CMD_MASK;
6345 }
6346 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006347 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6348 "0112 ELS command x%x received from NPORT x%x "
6349 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006350 switch (cmd) {
6351 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006352 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6353 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6354 did, vport->port_state, ndlp->nlp_flag);
6355
dea31012005-04-17 16:05:31 -05006356 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006357 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6358
James Smartddcc50f2008-12-04 22:38:46 -05006359 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05006360
6361 /* If Nport discovery is delayed, reject PLOGIs */
6362 if (vport->fc_flag & FC_DISC_DELAYED) {
6363 rjt_err = LSRJT_UNABLE_TPC;
6364 break;
6365 }
James Smart858c9f62007-06-17 19:56:39 -05006366 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006367 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6368 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6369 rjt_err = LSRJT_UNABLE_TPC;
6370 break;
6371 }
6372 /* We get here, and drop thru, if we are PT2PT with
6373 * another NPort and the other side has initiated
6374 * the PLOGI before responding to our FLOGI.
6375 */
dea31012005-04-17 16:05:31 -05006376 }
James Smart87af33f2007-10-27 13:37:43 -04006377
6378 shost = lpfc_shost_from_vport(vport);
6379 spin_lock_irq(shost->host_lock);
6380 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6381 spin_unlock_irq(shost->host_lock);
6382
James Smart2e0fef82007-06-17 19:56:36 -05006383 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6384 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006385
dea31012005-04-17 16:05:31 -05006386 break;
6387 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006388 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6389 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6390 did, vport->port_state, ndlp->nlp_flag);
6391
dea31012005-04-17 16:05:31 -05006392 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006393 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006394 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006395 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006396 break;
6397 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006398 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6399 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6400 did, vport->port_state, ndlp->nlp_flag);
6401
dea31012005-04-17 16:05:31 -05006402 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006403 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006404 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006405 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006406 break;
6407 }
James Smart2e0fef82007-06-17 19:56:36 -05006408 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006409 break;
6410 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006411 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6412 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6413 did, vport->port_state, ndlp->nlp_flag);
6414
dea31012005-04-17 16:05:31 -05006415 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006416 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006417 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006418 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006419 break;
6420 }
James Smart2e0fef82007-06-17 19:56:36 -05006421 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006422 break;
6423 case ELS_CMD_RSCN:
6424 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006425 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006426 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006427 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006428 break;
6429 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006430 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6431 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6432 did, vport->port_state, ndlp->nlp_flag);
6433
James Smartddcc50f2008-12-04 22:38:46 -05006434 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006435 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006436 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006437 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006438 break;
6439 }
James Smart2e0fef82007-06-17 19:56:36 -05006440 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6441 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006442 break;
6443 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006444 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6445 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6446 did, vport->port_state, ndlp->nlp_flag);
6447
dea31012005-04-17 16:05:31 -05006448 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006449 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006450 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006451 break;
6452 }
James Smart2e0fef82007-06-17 19:56:36 -05006453 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6454 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006455 break;
6456 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006457 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6458 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6459 did, vport->port_state, ndlp->nlp_flag);
6460
dea31012005-04-17 16:05:31 -05006461 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006462 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006463 break;
6464 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006465 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6466 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6467 did, vport->port_state, ndlp->nlp_flag);
6468
dea31012005-04-17 16:05:31 -05006469 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006470 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006471 break;
6472 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006473 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6474 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6475 did, vport->port_state, ndlp->nlp_flag);
6476
dea31012005-04-17 16:05:31 -05006477 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006478 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006479 break;
dea31012005-04-17 16:05:31 -05006480 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006481 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6482 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6483 did, vport->port_state, ndlp->nlp_flag);
6484
dea31012005-04-17 16:05:31 -05006485 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006486 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006487 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006488 break;
6489 }
James Smart2e0fef82007-06-17 19:56:36 -05006490 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006491 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006492 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006493 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6494 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6495 did, vport->port_state, ndlp->nlp_flag);
6496
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006497 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006498 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006499 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006500 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006501 break;
James Smart12265f62010-10-22 11:05:53 -04006502 case ELS_CMD_RLS:
6503 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6504 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6505 did, vport->port_state, ndlp->nlp_flag);
6506
6507 phba->fc_stat.elsRcvRLS++;
6508 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6509 if (newnode)
6510 lpfc_nlp_put(ndlp);
6511 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006512 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006513 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6514 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6515 did, vport->port_state, ndlp->nlp_flag);
6516
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006517 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006518 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006519 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006520 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006521 break;
6522 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006523 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6524 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6525 did, vport->port_state, ndlp->nlp_flag);
6526
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006527 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006528 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006529 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006530 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006531 break;
dea31012005-04-17 16:05:31 -05006532 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006533 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6534 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6535 did, vport->port_state, ndlp->nlp_flag);
6536
dea31012005-04-17 16:05:31 -05006537 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006538 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006539 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006540 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006541 break;
James Smart12265f62010-10-22 11:05:53 -04006542 case ELS_CMD_RTV:
6543 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6544 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6545 did, vport->port_state, ndlp->nlp_flag);
6546 phba->fc_stat.elsRcvRTV++;
6547 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6548 if (newnode)
6549 lpfc_nlp_put(ndlp);
6550 break;
James Smart5ffc2662009-11-18 15:39:44 -05006551 case ELS_CMD_RRQ:
6552 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6553 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6554 did, vport->port_state, ndlp->nlp_flag);
6555
6556 phba->fc_stat.elsRcvRRQ++;
6557 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6558 if (newnode)
6559 lpfc_nlp_put(ndlp);
6560 break;
James Smart12265f62010-10-22 11:05:53 -04006561 case ELS_CMD_ECHO:
6562 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6563 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6564 did, vport->port_state, ndlp->nlp_flag);
6565
6566 phba->fc_stat.elsRcvECHO++;
6567 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6568 if (newnode)
6569 lpfc_nlp_put(ndlp);
6570 break;
dea31012005-04-17 16:05:31 -05006571 default:
James Smart858c9f62007-06-17 19:56:39 -05006572 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6573 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6574 cmd, did, vport->port_state);
6575
dea31012005-04-17 16:05:31 -05006576 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006577 rjt_err = LSRJT_CMD_UNSUPPORTED;
dea31012005-04-17 16:05:31 -05006578
6579 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006580 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6581 "0115 Unknown ELS command x%x "
6582 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006583 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006584 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006585 break;
6586 }
6587
6588 /* check if need to LS_RJT received ELS cmd */
6589 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006590 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006591 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006592 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006593 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6594 NULL);
dea31012005-04-17 16:05:31 -05006595 }
6596
James Smartd7c255b2008-08-24 21:50:00 -04006597 lpfc_nlp_put(elsiocb->context1);
6598 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006599 return;
6600
6601dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006602 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006603 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6604 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006605 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006606 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006607 phba->fc_stat.elsRcvDrop++;
6608}
6609
James Smarte59058c2008-08-24 21:49:00 -04006610/**
James Smart3621a712009-04-06 18:47:14 -04006611 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006612 * @phba: pointer to lpfc hba data structure.
6613 * @pring: pointer to a SLI ring.
6614 * @elsiocb: pointer to lpfc els iocb data structure.
6615 *
6616 * This routine is used to process an unsolicited event received from a SLI
6617 * (Service Level Interface) ring. The actual processing of the data buffer
6618 * associated with the unsolicited event is done by invoking the routine
6619 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6620 * SLI ring on which the unsolicited event was received.
6621 **/
James Smarted957682007-06-17 19:56:37 -05006622void
6623lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6624 struct lpfc_iocbq *elsiocb)
6625{
6626 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006627 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006628 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006629 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6630 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006631
James Smartd7c255b2008-08-24 21:50:00 -04006632 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006633 elsiocb->context2 = NULL;
6634 elsiocb->context3 = NULL;
6635
6636 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6637 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6638 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6639 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006640 phba->fc_stat.NoRcvBuf++;
6641 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006642 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006643 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006644 return;
6645 }
6646
James Smart92d7f7b2007-06-17 19:56:38 -05006647 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6648 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6649 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6650 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6651 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006652 else
6653 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04006654 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05006655 }
James Smart6d368e52011-05-24 11:44:12 -04006656
James Smart7f5f3d02008-02-08 18:50:14 -05006657 /* If there are no BDEs associated
6658 * with this IOCB, there is nothing to do.
6659 */
James Smarted957682007-06-17 19:56:37 -05006660 if (icmd->ulpBdeCount == 0)
6661 return;
6662
James Smart7f5f3d02008-02-08 18:50:14 -05006663 /* type of ELS cmd is first 32bit word
6664 * in packet
6665 */
James Smarted957682007-06-17 19:56:37 -05006666 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006667 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006668 } else {
6669 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6670 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006671 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6672 paddr);
James Smarted957682007-06-17 19:56:37 -05006673 }
6674
James Smart92d7f7b2007-06-17 19:56:38 -05006675 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6676 /*
6677 * The different unsolicited event handlers would tell us
6678 * if they are done with "mp" by setting context2 to NULL.
6679 */
dea31012005-04-17 16:05:31 -05006680 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006681 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6682 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006683 }
James Smarted957682007-06-17 19:56:37 -05006684
6685 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006686 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006687 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006688 elsiocb->context2 = bdeBuf2;
6689 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006690 /* free mp if we are done with it */
6691 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006692 lpfc_in_buf_free(phba, elsiocb->context2);
6693 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006694 }
dea31012005-04-17 16:05:31 -05006695 }
dea31012005-04-17 16:05:31 -05006696}
James Smart92d7f7b2007-06-17 19:56:38 -05006697
James Smarte59058c2008-08-24 21:49:00 -04006698/**
James Smart3621a712009-04-06 18:47:14 -04006699 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006700 * @phba: pointer to lpfc hba data structure.
6701 * @vport: pointer to a virtual N_Port data structure.
6702 *
6703 * This routine issues a Port Login (PLOGI) to the Name Server with
6704 * State Change Request (SCR) for a @vport. This routine will create an
6705 * ndlp for the Name Server associated to the @vport if such node does
6706 * not already exist. The PLOGI to Name Server is issued by invoking the
6707 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6708 * (FDMI) is configured to the @vport, a FDMI node will be created and
6709 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6710 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006711void
6712lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6713{
6714 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05006715 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6716
6717 /*
6718 * If lpfc_delay_discovery parameter is set and the clean address
6719 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6720 * discovery.
6721 */
6722 spin_lock_irq(shost->host_lock);
6723 if (vport->fc_flag & FC_DISC_DELAYED) {
6724 spin_unlock_irq(shost->host_lock);
6725 mod_timer(&vport->delayed_disc_tmo,
6726 jiffies + HZ * phba->fc_ratov);
6727 return;
6728 }
6729 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006730
6731 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6732 if (!ndlp) {
6733 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6734 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006735 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05006736 lpfc_disc_start(vport);
6737 return;
6738 }
6739 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006740 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6741 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006742 return;
6743 }
6744 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006745 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6746 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6747 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006748 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05006749 lpfc_disc_start(vport);
6750 return;
6751 }
6752 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6753 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6754 "0348 NameServer login: node freed\n");
6755 return;
6756 }
James Smart92d7f7b2007-06-17 19:56:38 -05006757 }
James Smart58da1ff2008-04-07 10:15:56 -04006758 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006759
6760 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6761
6762 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6763 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006764 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6765 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006766 return;
6767 }
6768
James Smart3de2a652007-08-02 11:09:59 -04006769 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05006770 /* If this is the first time, allocate an ndlp and initialize
6771 * it. Otherwise, make sure the node is enabled and then do the
6772 * login.
6773 */
6774 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
6775 if (!ndlp_fdmi) {
6776 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6777 GFP_KERNEL);
6778 if (ndlp_fdmi) {
6779 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6780 ndlp_fdmi->nlp_type |= NLP_FABRIC;
6781 } else
6782 return;
6783 }
6784 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
6785 ndlp_fdmi = lpfc_enable_node(vport,
6786 ndlp_fdmi,
6787 NLP_STE_NPR_NODE);
6788
James Smart92d7f7b2007-06-17 19:56:38 -05006789 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04006790 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05006791 NLP_STE_PLOGI_ISSUE);
6792 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006793 }
6794 }
James Smart92d7f7b2007-06-17 19:56:38 -05006795}
6796
James Smarte59058c2008-08-24 21:49:00 -04006797/**
James Smart3621a712009-04-06 18:47:14 -04006798 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006799 * @phba: pointer to lpfc hba data structure.
6800 * @pmb: pointer to the driver internal queue element for mailbox command.
6801 *
6802 * This routine is the completion callback function to register new vport
6803 * mailbox command. If the new vport mailbox command completes successfully,
6804 * the fabric registration login shall be performed on physical port (the
6805 * new vport created is actually a physical port, with VPI 0) or the port
6806 * login to Name Server for State Change Request (SCR) will be performed
6807 * on virtual port (real virtual port, with VPI greater than 0).
6808 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006809static void
6810lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6811{
6812 struct lpfc_vport *vport = pmb->vport;
6813 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6814 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006815 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006816 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006817
James Smart09372822008-01-11 01:52:54 -05006818 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006819 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006820 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006821
6822 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006823 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006824 "0915 Register VPI failed : Status: x%x"
6825 " upd bit: x%x \n", mb->mbxStatus,
6826 mb->un.varRegVpi.upd);
6827 if (phba->sli_rev == LPFC_SLI_REV4 &&
6828 mb->un.varRegVpi.upd)
6829 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006830
6831 switch (mb->mbxStatus) {
6832 case 0x11: /* unsupported feature */
6833 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006834 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006835 /* giving up on vport registration */
6836 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6837 spin_lock_irq(shost->host_lock);
6838 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6839 spin_unlock_irq(shost->host_lock);
6840 lpfc_can_disctmo(vport);
6841 break;
James Smart695a8142010-01-26 23:08:03 -05006842 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6843 case 0x20:
6844 spin_lock_irq(shost->host_lock);
6845 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6846 spin_unlock_irq(shost->host_lock);
6847 lpfc_init_vpi(phba, pmb, vport->vpi);
6848 pmb->vport = vport;
6849 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6850 rc = lpfc_sli_issue_mbox(phba, pmb,
6851 MBX_NOWAIT);
6852 if (rc == MBX_NOT_FINISHED) {
6853 lpfc_printf_vlog(vport,
6854 KERN_ERR, LOG_MBOX,
6855 "2732 Failed to issue INIT_VPI"
6856 " mailbox command\n");
6857 } else {
6858 lpfc_nlp_put(ndlp);
6859 return;
6860 }
6861
James Smart92d7f7b2007-06-17 19:56:38 -05006862 default:
6863 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04006864 if (phba->sli_rev == LPFC_SLI_REV4)
6865 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006866 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006867 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006868 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006869 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006870 if (vport->port_type == LPFC_PHYSICAL_PORT
6871 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05006872 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05006873 else
6874 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006875 break;
6876 }
James Smart92d7f7b2007-06-17 19:56:38 -05006877 } else {
James Smart695a8142010-01-26 23:08:03 -05006878 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006879 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006880 spin_unlock_irq(shost->host_lock);
6881 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006882 if (phba->sli_rev < LPFC_SLI_REV4)
6883 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006884 else {
James Smartfc2b9892010-02-26 14:15:29 -05006885 /*
6886 * If the physical port is instantiated using
6887 * FDISC, do not start vport discovery.
6888 */
6889 if (vport->port_state != LPFC_FDISC)
6890 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006891 lpfc_do_scr_ns_plogi(phba, vport);
6892 }
6893 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006894 lpfc_do_scr_ns_plogi(phba, vport);
6895 }
James Smart38b92ef2010-08-04 16:11:39 -04006896mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05006897 /* Now, we decrement the ndlp reference count held for this
6898 * callback function
6899 */
6900 lpfc_nlp_put(ndlp);
6901
James Smart92d7f7b2007-06-17 19:56:38 -05006902 mempool_free(pmb, phba->mbox_mem_pool);
6903 return;
6904}
6905
James Smarte59058c2008-08-24 21:49:00 -04006906/**
James Smart3621a712009-04-06 18:47:14 -04006907 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006908 * @phba: pointer to lpfc hba data structure.
6909 * @vport: pointer to a host virtual N_Port data structure.
6910 * @ndlp: pointer to a node-list data structure.
6911 *
6912 * This routine registers the @vport as a new virtual port with a HBA.
6913 * It is done through a registering vpi mailbox command.
6914 **/
James Smart695a8142010-01-26 23:08:03 -05006915void
James Smart92d7f7b2007-06-17 19:56:38 -05006916lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6917 struct lpfc_nodelist *ndlp)
6918{
James Smart09372822008-01-11 01:52:54 -05006919 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006920 LPFC_MBOXQ_t *mbox;
6921
6922 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6923 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006924 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006925 mbox->vport = vport;
6926 mbox->context2 = lpfc_nlp_get(ndlp);
6927 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006928 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006929 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006930 /* mailbox command not success, decrement ndlp
6931 * reference count for this command
6932 */
6933 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006934 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006935
James Smarte8b62012007-08-02 11:10:09 -04006936 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6937 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006938 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006939 }
6940 } else {
James Smarte8b62012007-08-02 11:10:09 -04006941 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6942 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006943 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006944 }
James Smartfa4066b2008-01-11 01:53:27 -05006945 return;
6946
6947mbox_err_exit:
6948 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6949 spin_lock_irq(shost->host_lock);
6950 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6951 spin_unlock_irq(shost->host_lock);
6952 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006953}
6954
James Smarte59058c2008-08-24 21:49:00 -04006955/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006956 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006957 * @phba: pointer to lpfc hba data structure.
6958 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006959 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006960 **/
6961void
James Smart0c9ab6f2010-02-26 14:15:57 -05006962lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006963{
6964 struct lpfc_vport **vports;
6965 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006966 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006967 int i;
James Smart695a8142010-01-26 23:08:03 -05006968
6969 /* Treat this failure as linkdown for all vports */
6970 link_state = phba->link_state;
6971 lpfc_linkdown(phba);
6972 phba->link_state = link_state;
6973
6974 vports = lpfc_create_vport_work_array(phba);
6975
6976 if (vports) {
6977 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6978 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6979 if (ndlp)
6980 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6981 lpfc_els_flush_cmd(vports[i]);
6982 }
6983 lpfc_destroy_vport_work_array(phba, vports);
6984 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006985}
6986
6987/**
6988 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6989 * @phba: pointer to lpfc hba data structure.
6990 *
6991 * This routine abort all pending discovery commands and
6992 * start a timer to retry FLOGI for the physical port
6993 * discovery.
6994 **/
6995void
6996lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6997{
6998 struct lpfc_nodelist *ndlp;
6999 struct Scsi_Host *shost;
7000
7001 /* Cancel the all vports retry delay retry timers */
7002 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05007003
7004 /* If fabric require FLOGI, then re-instantiate physical login */
7005 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
7006 if (!ndlp)
7007 return;
7008
James Smart695a8142010-01-26 23:08:03 -05007009 shost = lpfc_shost_from_vport(phba->pport);
7010 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
7011 spin_lock_irq(shost->host_lock);
7012 ndlp->nlp_flag |= NLP_DELAY_TMO;
7013 spin_unlock_irq(shost->host_lock);
7014 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7015 phba->pport->port_state = LPFC_FLOGI;
7016 return;
7017}
7018
7019/**
7020 * lpfc_fabric_login_reqd - Check if FLOGI required.
7021 * @phba: pointer to lpfc hba data structure.
7022 * @cmdiocb: pointer to FDISC command iocb.
7023 * @rspiocb: pointer to FDISC response iocb.
7024 *
7025 * This routine checks if a FLOGI is reguired for FDISC
7026 * to succeed.
7027 **/
7028static int
7029lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7030 struct lpfc_iocbq *cmdiocb,
7031 struct lpfc_iocbq *rspiocb)
7032{
7033
7034 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7035 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7036 return 0;
7037 else
7038 return 1;
7039}
7040
7041/**
James Smart3621a712009-04-06 18:47:14 -04007042 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007043 * @phba: pointer to lpfc hba data structure.
7044 * @cmdiocb: pointer to lpfc command iocb data structure.
7045 * @rspiocb: pointer to lpfc response iocb data structure.
7046 *
7047 * This routine is the completion callback function to a Fabric Discover
7048 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7049 * single threaded, each FDISC completion callback function will reset
7050 * the discovery timer for all vports such that the timers will not get
7051 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7052 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7053 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7054 * assigned to the vport has been changed with the completion of the FDISC
7055 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7056 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7057 * routine is invoked to register new vport with the HBA. Otherwise, the
7058 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7059 * Server for State Change Request (SCR).
7060 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007061static void
7062lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7063 struct lpfc_iocbq *rspiocb)
7064{
7065 struct lpfc_vport *vport = cmdiocb->vport;
7066 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7067 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7068 struct lpfc_nodelist *np;
7069 struct lpfc_nodelist *next_np;
7070 IOCB_t *irsp = &rspiocb->iocb;
7071 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05007072 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7073 struct serv_parm *sp;
7074 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05007075
James Smarte8b62012007-08-02 11:10:09 -04007076 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7077 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7078 irsp->ulpStatus, irsp->un.ulpWord[4],
7079 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05007080 /* Since all FDISCs are being single threaded, we
7081 * must reset the discovery timer for ALL vports
7082 * waiting to send FDISC when one completes.
7083 */
7084 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7085 lpfc_set_disctmo(piocb->vport);
7086 }
7087
James Smart858c9f62007-06-17 19:56:39 -05007088 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7089 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7090 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7091
James Smart92d7f7b2007-06-17 19:56:38 -05007092 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05007093
7094 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7095 lpfc_retry_pport_discovery(phba);
7096 goto out;
7097 }
7098
James Smart92d7f7b2007-06-17 19:56:38 -05007099 /* Check for retry */
7100 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7101 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007102 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04007103 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04007104 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04007105 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04007106 goto fdisc_failed;
7107 }
James Smartd7c255b2008-08-24 21:50:00 -04007108 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05007109 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04007110 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04007111 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05007112 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04007113 vport->fc_flag |= FC_PUBLIC_LOOP;
7114 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007115
James Smartd7c255b2008-08-24 21:50:00 -04007116 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7117 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05007118 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7119 sp = prsp->virt + sizeof(uint32_t);
7120 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7121 memcpy(&vport->fabric_portname, &sp->portName,
7122 sizeof(struct lpfc_name));
7123 memcpy(&vport->fabric_nodename, &sp->nodeName,
7124 sizeof(struct lpfc_name));
7125 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04007126 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7127 /* If our NportID changed, we need to ensure all
7128 * remaining NPORTs get unreg_login'ed so we can
7129 * issue unreg_vpi.
7130 */
7131 list_for_each_entry_safe(np, next_np,
7132 &vport->fc_nodes, nlp_listp) {
7133 if (!NLP_CHK_NODE_ACT(ndlp) ||
7134 (np->nlp_state != NLP_STE_NPR_NODE) ||
7135 !(np->nlp_flag & NLP_NPR_ADISC))
7136 continue;
James Smart09372822008-01-11 01:52:54 -05007137 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007138 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007139 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007140 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007141 }
James Smart78730cf2010-04-06 15:06:30 -04007142 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007143
7144 if (phba->sli_rev == LPFC_SLI_REV4)
7145 lpfc_sli4_unreg_all_rpis(vport);
7146
James Smartd7c255b2008-08-24 21:50:00 -04007147 lpfc_mbx_unreg_vpi(vport);
7148 spin_lock_irq(shost->host_lock);
7149 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007150 if (phba->sli_rev == LPFC_SLI_REV4)
7151 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007152 else
7153 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007154 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007155 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7156 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7157 /*
7158 * Driver needs to re-reg VPI in order for f/w
7159 * to update the MAC address.
7160 */
7161 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007162 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007163 }
7164
James Smartecfd03c2010-02-12 14:41:27 -05007165 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7166 lpfc_issue_init_vpi(vport);
7167 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007168 lpfc_register_new_vport(phba, vport, ndlp);
7169 else
7170 lpfc_do_scr_ns_plogi(phba, vport);
7171 goto out;
7172fdisc_failed:
7173 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7174 /* Cancel discovery timer */
7175 lpfc_can_disctmo(vport);
7176 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007177out:
7178 lpfc_els_free_iocb(phba, cmdiocb);
7179}
7180
James Smarte59058c2008-08-24 21:49:00 -04007181/**
James Smart3621a712009-04-06 18:47:14 -04007182 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007183 * @vport: pointer to a virtual N_Port data structure.
7184 * @ndlp: pointer to a node-list data structure.
7185 * @retry: number of retries to the command IOCB.
7186 *
7187 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7188 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7189 * routine to issue the IOCB, which makes sure only one outstanding fabric
7190 * IOCB will be sent off HBA at any given time.
7191 *
7192 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7193 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7194 * will be stored into the context1 field of the IOCB for the completion
7195 * callback function to the FDISC ELS command.
7196 *
7197 * Return code
7198 * 0 - Successfully issued fdisc iocb command
7199 * 1 - Failed to issue fdisc iocb command
7200 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007201static int
James Smart92d7f7b2007-06-17 19:56:38 -05007202lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7203 uint8_t retry)
7204{
7205 struct lpfc_hba *phba = vport->phba;
7206 IOCB_t *icmd;
7207 struct lpfc_iocbq *elsiocb;
7208 struct serv_parm *sp;
7209 uint8_t *pcmd;
7210 uint16_t cmdsize;
7211 int did = ndlp->nlp_DID;
7212 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007213
James Smart5ffc2662009-11-18 15:39:44 -05007214 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05007215 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7216 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7217 ELS_CMD_FDISC);
7218 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007219 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007220 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7221 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007222 return 1;
7223 }
7224
7225 icmd = &elsiocb->iocb;
7226 icmd->un.elsreq64.myID = 0;
7227 icmd->un.elsreq64.fl = 1;
7228
James Smart73d91e52011-10-10 21:32:10 -04007229 /*
7230 * SLI3 ports require a different context type value than SLI4.
7231 * Catch SLI3 ports here and override the prep.
7232 */
7233 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04007234 icmd->ulpCt_h = 1;
7235 icmd->ulpCt_l = 0;
7236 }
James Smart92d7f7b2007-06-17 19:56:38 -05007237
7238 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7239 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7240 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7241 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7242 sp = (struct serv_parm *) pcmd;
7243 /* Setup CSPs accordingly for Fabric */
7244 sp->cmn.e_d_tov = 0;
7245 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05007246 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007247 sp->cls1.classValid = 0;
7248 sp->cls2.seqDelivery = 1;
7249 sp->cls3.seqDelivery = 1;
7250
7251 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7252 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7253 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7254 pcmd += sizeof(uint32_t); /* Port Name */
7255 memcpy(pcmd, &vport->fc_portname, 8);
7256 pcmd += sizeof(uint32_t); /* Node Name */
7257 pcmd += sizeof(uint32_t); /* Node Name */
7258 memcpy(pcmd, &vport->fc_nodename, 8);
7259
7260 lpfc_set_disctmo(vport);
7261
7262 phba->fc_stat.elsXmitFDISC++;
7263 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7264
James Smart858c9f62007-06-17 19:56:39 -05007265 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7266 "Issue FDISC: did:x%x",
7267 did, 0, 0);
7268
James Smart92d7f7b2007-06-17 19:56:38 -05007269 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7270 if (rc == IOCB_ERROR) {
7271 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007272 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007273 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7274 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007275 return 1;
7276 }
7277 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007278 return 0;
7279}
7280
James Smarte59058c2008-08-24 21:49:00 -04007281/**
James Smart3621a712009-04-06 18:47:14 -04007282 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007283 * @phba: pointer to lpfc hba data structure.
7284 * @cmdiocb: pointer to lpfc command iocb data structure.
7285 * @rspiocb: pointer to lpfc response iocb data structure.
7286 *
7287 * This routine is the completion callback function to the issuing of a LOGO
7288 * ELS command off a vport. It frees the command IOCB and then decrement the
7289 * reference count held on ndlp for this completion function, indicating that
7290 * the reference to the ndlp is no long needed. Note that the
7291 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7292 * callback function and an additional explicit ndlp reference decrementation
7293 * will trigger the actual release of the ndlp.
7294 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007295static void
7296lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7297 struct lpfc_iocbq *rspiocb)
7298{
7299 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007300 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007301 struct lpfc_nodelist *ndlp;
James Smart9589b062011-04-16 11:03:17 -04007302 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05007303
James Smart9589b062011-04-16 11:03:17 -04007304 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007305 irsp = &rspiocb->iocb;
7306 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7307 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7308 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007309
7310 lpfc_els_free_iocb(phba, cmdiocb);
7311 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007312
7313 /* Trigger the release of the ndlp after logo */
7314 lpfc_nlp_put(ndlp);
James Smart9589b062011-04-16 11:03:17 -04007315
7316 /* NPIV LOGO completes to NPort <nlp_DID> */
7317 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7318 "2928 NPIV LOGO completes to NPort x%x "
7319 "Data: x%x x%x x%x x%x\n",
7320 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
7321 irsp->ulpTimeout, vport->num_disc_nodes);
7322
7323 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
7324 spin_lock_irq(shost->host_lock);
7325 vport->fc_flag &= ~FC_FABRIC;
7326 spin_unlock_irq(shost->host_lock);
7327 }
James Smart92d7f7b2007-06-17 19:56:38 -05007328}
7329
James Smarte59058c2008-08-24 21:49:00 -04007330/**
James Smart3621a712009-04-06 18:47:14 -04007331 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007332 * @vport: pointer to a virtual N_Port data structure.
7333 * @ndlp: pointer to a node-list data structure.
7334 *
7335 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7336 *
7337 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7338 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7339 * will be stored into the context1 field of the IOCB for the completion
7340 * callback function to the LOGO ELS command.
7341 *
7342 * Return codes
7343 * 0 - Successfully issued logo off the @vport
7344 * 1 - Failed to issue logo off the @vport
7345 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007346int
7347lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7348{
7349 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7350 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007351 IOCB_t *icmd;
7352 struct lpfc_iocbq *elsiocb;
7353 uint8_t *pcmd;
7354 uint16_t cmdsize;
7355
7356 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7357 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7358 ELS_CMD_LOGO);
7359 if (!elsiocb)
7360 return 1;
7361
7362 icmd = &elsiocb->iocb;
7363 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7364 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7365 pcmd += sizeof(uint32_t);
7366
7367 /* Fill in LOGO payload */
7368 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7369 pcmd += sizeof(uint32_t);
7370 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7371
James Smart858c9f62007-06-17 19:56:39 -05007372 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7373 "Issue LOGO npiv did:x%x flg:x%x",
7374 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7375
James Smart92d7f7b2007-06-17 19:56:38 -05007376 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7377 spin_lock_irq(shost->host_lock);
7378 ndlp->nlp_flag |= NLP_LOGO_SND;
7379 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007380 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7381 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007382 spin_lock_irq(shost->host_lock);
7383 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7384 spin_unlock_irq(shost->host_lock);
7385 lpfc_els_free_iocb(phba, elsiocb);
7386 return 1;
7387 }
7388 return 0;
7389}
7390
James Smarte59058c2008-08-24 21:49:00 -04007391/**
James Smart3621a712009-04-06 18:47:14 -04007392 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007393 * @ptr: holder for the timer function associated data.
7394 *
7395 * This routine is invoked by the fabric iocb block timer after
7396 * timeout. It posts the fabric iocb block timeout event by setting the
7397 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7398 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7399 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7400 * posted event WORKER_FABRIC_BLOCK_TMO.
7401 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007402void
7403lpfc_fabric_block_timeout(unsigned long ptr)
7404{
7405 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7406 unsigned long iflags;
7407 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007408
James Smart92d7f7b2007-06-17 19:56:38 -05007409 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7410 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7411 if (!tmo_posted)
7412 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7413 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7414
James Smart5e9d9b82008-06-14 22:52:53 -04007415 if (!tmo_posted)
7416 lpfc_worker_wake_up(phba);
7417 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007418}
7419
James Smarte59058c2008-08-24 21:49:00 -04007420/**
James Smart3621a712009-04-06 18:47:14 -04007421 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007422 * @phba: pointer to lpfc hba data structure.
7423 *
7424 * This routine issues one fabric iocb from the driver internal list to
7425 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7426 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7427 * remove one pending fabric iocb from the driver internal list and invokes
7428 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7429 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007430static void
7431lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7432{
7433 struct lpfc_iocbq *iocb;
7434 unsigned long iflags;
7435 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007436 IOCB_t *cmd;
7437
7438repeat:
7439 iocb = NULL;
7440 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007441 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007442 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7443 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7444 list);
7445 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007446 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007447 atomic_inc(&phba->fabric_iocb_count);
7448 }
7449 spin_unlock_irqrestore(&phba->hbalock, iflags);
7450 if (iocb) {
7451 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7452 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7453 iocb->iocb_flag |= LPFC_IO_FABRIC;
7454
James Smart858c9f62007-06-17 19:56:39 -05007455 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7456 "Fabric sched1: ste:x%x",
7457 iocb->vport->port_state, 0, 0);
7458
James Smart3772a992009-05-22 14:50:54 -04007459 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007460
7461 if (ret == IOCB_ERROR) {
7462 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7463 iocb->fabric_iocb_cmpl = NULL;
7464 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7465 cmd = &iocb->iocb;
7466 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7467 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7468 iocb->iocb_cmpl(phba, iocb, iocb);
7469
7470 atomic_dec(&phba->fabric_iocb_count);
7471 goto repeat;
7472 }
7473 }
7474
7475 return;
7476}
7477
James Smarte59058c2008-08-24 21:49:00 -04007478/**
James Smart3621a712009-04-06 18:47:14 -04007479 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007480 * @phba: pointer to lpfc hba data structure.
7481 *
7482 * This routine unblocks the issuing fabric iocb command. The function
7483 * will clear the fabric iocb block bit and then invoke the routine
7484 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7485 * from the driver internal fabric iocb list.
7486 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007487void
7488lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7489{
7490 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7491
7492 lpfc_resume_fabric_iocbs(phba);
7493 return;
7494}
7495
James Smarte59058c2008-08-24 21:49:00 -04007496/**
James Smart3621a712009-04-06 18:47:14 -04007497 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007498 * @phba: pointer to lpfc hba data structure.
7499 *
7500 * This routine blocks the issuing fabric iocb for a specified amount of
7501 * time (currently 100 ms). This is done by set the fabric iocb block bit
7502 * and set up a timeout timer for 100ms. When the block bit is set, no more
7503 * fabric iocb will be issued out of the HBA.
7504 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007505static void
7506lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7507{
7508 int blocked;
7509
7510 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007511 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007512 if (!blocked)
7513 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7514
7515 return;
7516}
7517
James Smarte59058c2008-08-24 21:49:00 -04007518/**
James Smart3621a712009-04-06 18:47:14 -04007519 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007520 * @phba: pointer to lpfc hba data structure.
7521 * @cmdiocb: pointer to lpfc command iocb data structure.
7522 * @rspiocb: pointer to lpfc response iocb data structure.
7523 *
7524 * This routine is the callback function that is put to the fabric iocb's
7525 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7526 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7527 * function first restores and invokes the original iocb's callback function
7528 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7529 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7530 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007531static void
7532lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7533 struct lpfc_iocbq *rspiocb)
7534{
7535 struct ls_rjt stat;
7536
7537 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7538 BUG();
7539
7540 switch (rspiocb->iocb.ulpStatus) {
7541 case IOSTAT_NPORT_RJT:
7542 case IOSTAT_FABRIC_RJT:
7543 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7544 lpfc_block_fabric_iocbs(phba);
7545 }
7546 break;
7547
7548 case IOSTAT_NPORT_BSY:
7549 case IOSTAT_FABRIC_BSY:
7550 lpfc_block_fabric_iocbs(phba);
7551 break;
7552
7553 case IOSTAT_LS_RJT:
7554 stat.un.lsRjtError =
7555 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7556 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7557 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7558 lpfc_block_fabric_iocbs(phba);
7559 break;
7560 }
7561
7562 if (atomic_read(&phba->fabric_iocb_count) == 0)
7563 BUG();
7564
7565 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7566 cmdiocb->fabric_iocb_cmpl = NULL;
7567 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7568 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7569
7570 atomic_dec(&phba->fabric_iocb_count);
7571 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007572 /* Post any pending iocbs to HBA */
7573 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007574 }
7575}
7576
James Smarte59058c2008-08-24 21:49:00 -04007577/**
James Smart3621a712009-04-06 18:47:14 -04007578 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007579 * @phba: pointer to lpfc hba data structure.
7580 * @iocb: pointer to lpfc command iocb data structure.
7581 *
7582 * This routine is used as the top-level API for issuing a fabric iocb command
7583 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7584 * function makes sure that only one fabric bound iocb will be outstanding at
7585 * any given time. As such, this function will first check to see whether there
7586 * is already an outstanding fabric iocb on the wire. If so, it will put the
7587 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7588 * issued later. Otherwise, it will issue the iocb on the wire and update the
7589 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7590 *
7591 * Note, this implementation has a potential sending out fabric IOCBs out of
7592 * order. The problem is caused by the construction of the "ready" boolen does
7593 * not include the condition that the internal fabric IOCB list is empty. As
7594 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7595 * ahead of the fabric IOCBs in the internal list.
7596 *
7597 * Return code
7598 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7599 * IOCB_ERROR - failed to issue fabric iocb
7600 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007601static int
James Smart92d7f7b2007-06-17 19:56:38 -05007602lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7603{
7604 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007605 int ready;
7606 int ret;
7607
7608 if (atomic_read(&phba->fabric_iocb_count) > 1)
7609 BUG();
7610
7611 spin_lock_irqsave(&phba->hbalock, iflags);
7612 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7613 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7614
James Smart7f5f3d02008-02-08 18:50:14 -05007615 if (ready)
7616 /* Increment fabric iocb count to hold the position */
7617 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007618 spin_unlock_irqrestore(&phba->hbalock, iflags);
7619 if (ready) {
7620 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7621 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7622 iocb->iocb_flag |= LPFC_IO_FABRIC;
7623
James Smart858c9f62007-06-17 19:56:39 -05007624 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7625 "Fabric sched2: ste:x%x",
7626 iocb->vport->port_state, 0, 0);
7627
James Smart3772a992009-05-22 14:50:54 -04007628 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007629
7630 if (ret == IOCB_ERROR) {
7631 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7632 iocb->fabric_iocb_cmpl = NULL;
7633 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7634 atomic_dec(&phba->fabric_iocb_count);
7635 }
7636 } else {
7637 spin_lock_irqsave(&phba->hbalock, iflags);
7638 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7639 spin_unlock_irqrestore(&phba->hbalock, iflags);
7640 ret = IOCB_SUCCESS;
7641 }
7642 return ret;
7643}
7644
James Smarte59058c2008-08-24 21:49:00 -04007645/**
James Smart3621a712009-04-06 18:47:14 -04007646 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007647 * @vport: pointer to a virtual N_Port data structure.
7648 *
7649 * This routine aborts all the IOCBs associated with a @vport from the
7650 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7651 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7652 * list, removes each IOCB associated with the @vport off the list, set the
7653 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7654 * associated with the IOCB.
7655 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007656static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007657{
7658 LIST_HEAD(completions);
7659 struct lpfc_hba *phba = vport->phba;
7660 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007661
7662 spin_lock_irq(&phba->hbalock);
7663 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7664 list) {
7665
7666 if (piocb->vport != vport)
7667 continue;
7668
7669 list_move_tail(&piocb->list, &completions);
7670 }
7671 spin_unlock_irq(&phba->hbalock);
7672
James Smarta257bf92009-04-06 18:48:10 -04007673 /* Cancel all the IOCBs from the completions list */
7674 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7675 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007676}
7677
James Smarte59058c2008-08-24 21:49:00 -04007678/**
James Smart3621a712009-04-06 18:47:14 -04007679 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007680 * @ndlp: pointer to a node-list data structure.
7681 *
7682 * This routine aborts all the IOCBs associated with an @ndlp from the
7683 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7684 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7685 * list, removes each IOCB associated with the @ndlp off the list, set the
7686 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7687 * associated with the IOCB.
7688 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007689void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7690{
7691 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007692 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007693 struct lpfc_iocbq *tmp_iocb, *piocb;
7694 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007695
7696 spin_lock_irq(&phba->hbalock);
7697 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7698 list) {
7699 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7700
7701 list_move_tail(&piocb->list, &completions);
7702 }
7703 }
7704 spin_unlock_irq(&phba->hbalock);
7705
James Smarta257bf92009-04-06 18:48:10 -04007706 /* Cancel all the IOCBs from the completions list */
7707 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7708 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007709}
7710
James Smarte59058c2008-08-24 21:49:00 -04007711/**
James Smart3621a712009-04-06 18:47:14 -04007712 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007713 * @phba: pointer to lpfc hba data structure.
7714 *
7715 * This routine aborts all the IOCBs currently on the driver internal
7716 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7717 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7718 * list, removes IOCBs off the list, set the status feild to
7719 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7720 * the IOCB.
7721 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007722void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7723{
7724 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007725
7726 spin_lock_irq(&phba->hbalock);
7727 list_splice_init(&phba->fabric_iocb_list, &completions);
7728 spin_unlock_irq(&phba->hbalock);
7729
James Smarta257bf92009-04-06 18:48:10 -04007730 /* Cancel all the IOCBs from the completions list */
7731 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7732 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007733}
James Smart6fb120a2009-05-22 14:52:59 -04007734
7735/**
James Smart1151e3e2011-02-16 12:39:35 -05007736 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7737 * @vport: pointer to lpfc vport data structure.
7738 *
7739 * This routine is invoked by the vport cleanup for deletions and the cleanup
7740 * for an ndlp on removal.
7741 **/
7742void
7743lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
7744{
7745 struct lpfc_hba *phba = vport->phba;
7746 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7747 unsigned long iflag = 0;
7748
7749 spin_lock_irqsave(&phba->hbalock, iflag);
7750 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7751 list_for_each_entry_safe(sglq_entry, sglq_next,
7752 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7753 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
7754 sglq_entry->ndlp = NULL;
7755 }
7756 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7757 spin_unlock_irqrestore(&phba->hbalock, iflag);
7758 return;
7759}
7760
7761/**
James Smart6fb120a2009-05-22 14:52:59 -04007762 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7763 * @phba: pointer to lpfc hba data structure.
7764 * @axri: pointer to the els xri abort wcqe structure.
7765 *
7766 * This routine is invoked by the worker thread to process a SLI4 slow-path
7767 * ELS aborted xri.
7768 **/
7769void
7770lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7771 struct sli4_wcqe_xri_aborted *axri)
7772{
7773 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05007774 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04007775 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05007776
James Smart6fb120a2009-05-22 14:52:59 -04007777 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7778 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05007779 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04007780 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007781
James Smart0f65ff62010-02-26 14:14:23 -05007782 spin_lock_irqsave(&phba->hbalock, iflag);
7783 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007784 list_for_each_entry_safe(sglq_entry, sglq_next,
7785 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7786 if (sglq_entry->sli4_xritag == xri) {
7787 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05007788 ndlp = sglq_entry->ndlp;
7789 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04007790 list_add_tail(&sglq_entry->list,
7791 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007792 sglq_entry->state = SGL_FREED;
7793 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007794 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart19ca7602010-11-20 23:11:55 -05007795 lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04007796
7797 /* Check if TXQ queue needs to be serviced */
7798 if (pring->txq_cnt)
7799 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007800 return;
7801 }
7802 }
James Smart0f65ff62010-02-26 14:14:23 -05007803 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04007804 lxri = lpfc_sli4_xri_inrange(phba, xri);
7805 if (lxri == NO_XRI) {
7806 spin_unlock_irqrestore(&phba->hbalock, iflag);
7807 return;
7808 }
7809 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05007810 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7811 spin_unlock_irqrestore(&phba->hbalock, iflag);
7812 return;
7813 }
7814 sglq_entry->state = SGL_XRI_ABORTED;
7815 spin_unlock_irqrestore(&phba->hbalock, iflag);
7816 return;
James Smart6fb120a2009-05-22 14:52:59 -04007817}