blob: 727c793422f2934058b733c18f34c95f6593c279 [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 Smart76a95d72010-11-20 23:11:48 -0500912 if ((phba->sli_rev == LPFC_SLI_REV4) &&
913 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
914 (vport->fc_prevDID != vport->fc_myDID))) {
915 if (vport->fc_flag & FC_VFI_REGISTERED)
916 lpfc_sli4_unreg_all_rpis(vport);
917 lpfc_issue_reg_vfi(vport);
918 lpfc_nlp_put(ndlp);
919 goto out;
920 }
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;
1078 sp->cls1.classValid = 0;
1079 sp->cls2.seqDelivery = 1;
1080 sp->cls3.seqDelivery = 1;
1081 if (sp->cmn.fcphLow < FC_PH3)
1082 sp->cmn.fcphLow = FC_PH3;
1083 if (sp->cmn.fcphHigh < FC_PH3)
1084 sp->cmn.fcphHigh = FC_PH3;
1085
James Smartc31098c2011-04-16 11:03:33 -04001086 if (phba->sli_rev == LPFC_SLI_REV4) {
1087 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1088 LPFC_SLI_INTF_IF_TYPE_0) {
1089 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1090 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1091 /* FLOGI needs to be 3 for WQE FCFI */
1092 /* Set the fcfi to the fcfi we registered with */
1093 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1094 }
James Smart5248a742011-07-22 18:37:06 -04001095 } else {
1096 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1097 sp->cmn.request_multiple_Nport = 1;
1098 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1099 icmd->ulpCt_h = 1;
1100 icmd->ulpCt_l = 0;
1101 } else
1102 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001103 }
1104
James Smart76a95d72010-11-20 23:11:48 -05001105 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001106 icmd->un.elsreq64.myID = 0;
1107 icmd->un.elsreq64.fl = 1;
1108 }
1109
dea31012005-04-17 16:05:31 -05001110 tmo = phba->fc_ratov;
1111 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001112 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001113 phba->fc_ratov = tmo;
1114
1115 phba->fc_stat.elsXmitFLOGI++;
1116 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001117
1118 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1119 "Issue FLOGI: opt:x%x",
1120 phba->sli3_options, 0, 0);
1121
James Smart92d7f7b2007-06-17 19:56:38 -05001122 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001123 if (rc == IOCB_ERROR) {
1124 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001125 return 1;
dea31012005-04-17 16:05:31 -05001126 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001127 return 0;
dea31012005-04-17 16:05:31 -05001128}
1129
James Smarte59058c2008-08-24 21:49:00 -04001130/**
James Smart3621a712009-04-06 18:47:14 -04001131 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001132 * @phba: pointer to lpfc hba data structure.
1133 *
1134 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1135 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1136 * list and issues an abort IOCB commond on each outstanding IOCB that
1137 * contains a active Fabric_DID ndlp. Note that this function is to issue
1138 * the abort IOCB command on all the outstanding IOCBs, thus when this
1139 * function returns, it does not guarantee all the IOCBs are actually aborted.
1140 *
1141 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001142 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001143 **/
dea31012005-04-17 16:05:31 -05001144int
James Smart2e0fef82007-06-17 19:56:36 -05001145lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001146{
1147 struct lpfc_sli_ring *pring;
1148 struct lpfc_iocbq *iocb, *next_iocb;
1149 struct lpfc_nodelist *ndlp;
1150 IOCB_t *icmd;
1151
1152 /* Abort outstanding I/O on NPort <nlp_DID> */
1153 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001154 "0201 Abort outstanding I/O on NPort x%x\n",
1155 Fabric_DID);
dea31012005-04-17 16:05:31 -05001156
1157 pring = &phba->sli.ring[LPFC_ELS_RING];
1158
1159 /*
1160 * Check the txcmplq for an iocb that matches the nport the driver is
1161 * searching for.
1162 */
James Smart2e0fef82007-06-17 19:56:36 -05001163 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001164 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1165 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001166 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1167 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001168 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001169 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1170 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001171 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001172 }
1173 }
James Smart2e0fef82007-06-17 19:56:36 -05001174 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001175
1176 return 0;
1177}
1178
James Smarte59058c2008-08-24 21:49:00 -04001179/**
James Smart3621a712009-04-06 18:47:14 -04001180 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001181 * @vport: pointer to a host virtual N_Port data structure.
1182 *
1183 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1184 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1185 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1186 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1187 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1188 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1189 * @vport.
1190 *
1191 * Return code
1192 * 0 - failed to issue initial flogi for @vport
1193 * 1 - successfully issued initial flogi for @vport
1194 **/
dea31012005-04-17 16:05:31 -05001195int
James Smart2e0fef82007-06-17 19:56:36 -05001196lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001197{
James Smart2e0fef82007-06-17 19:56:36 -05001198 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001199 struct lpfc_nodelist *ndlp;
1200
James Smart98c9ea52007-10-27 13:37:33 -04001201 vport->port_state = LPFC_FLOGI;
1202 lpfc_set_disctmo(vport);
1203
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001204 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001205 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001206 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001207 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001208 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1209 if (!ndlp)
1210 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001211 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001212 /* Set the node type */
1213 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001214 /* Put ndlp onto node list */
1215 lpfc_enqueue_node(vport, ndlp);
1216 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1217 /* re-setup ndlp without removing from node list */
1218 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1219 if (!ndlp)
1220 return 0;
dea31012005-04-17 16:05:31 -05001221 }
James Smart87af33f2007-10-27 13:37:43 -04001222
James Smart5ac6b302010-10-22 11:05:36 -04001223 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001224 /* This decrement of reference count to node shall kick off
1225 * the release of the node.
1226 */
James Smart329f9bc2007-04-25 09:53:01 -04001227 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001228 return 0;
1229 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001230 return 1;
dea31012005-04-17 16:05:31 -05001231}
1232
James Smarte59058c2008-08-24 21:49:00 -04001233/**
James Smart3621a712009-04-06 18:47:14 -04001234 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001235 * @vport: pointer to a host virtual N_Port data structure.
1236 *
1237 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1238 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1239 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1240 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1241 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1242 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1243 * @vport.
1244 *
1245 * Return code
1246 * 0 - failed to issue initial fdisc for @vport
1247 * 1 - successfully issued initial fdisc for @vport
1248 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001249int
1250lpfc_initial_fdisc(struct lpfc_vport *vport)
1251{
1252 struct lpfc_hba *phba = vport->phba;
1253 struct lpfc_nodelist *ndlp;
1254
1255 /* First look for the Fabric ndlp */
1256 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1257 if (!ndlp) {
1258 /* Cannot find existing Fabric ndlp, so allocate a new one */
1259 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1260 if (!ndlp)
1261 return 0;
1262 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001263 /* Put ndlp onto node list */
1264 lpfc_enqueue_node(vport, ndlp);
1265 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1266 /* re-setup ndlp without removing from node list */
1267 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1268 if (!ndlp)
1269 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001270 }
James Smarte47c9092008-02-08 18:49:26 -05001271
James Smart92d7f7b2007-06-17 19:56:38 -05001272 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001273 /* decrement node reference count to trigger the release of
1274 * the node.
1275 */
James Smart92d7f7b2007-06-17 19:56:38 -05001276 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001277 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001278 }
1279 return 1;
1280}
James Smart87af33f2007-10-27 13:37:43 -04001281
James Smarte59058c2008-08-24 21:49:00 -04001282/**
James Smart3621a712009-04-06 18:47:14 -04001283 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001284 * @vport: pointer to a host virtual N_Port data structure.
1285 *
1286 * This routine checks whether there are more remaining Port Logins
1287 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1288 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1289 * to issue ELS PLOGIs up to the configured discover threads with the
1290 * @vport (@vport->cfg_discovery_threads). The function also decrement
1291 * the @vport's num_disc_node by 1 if it is not already 0.
1292 **/
James Smart87af33f2007-10-27 13:37:43 -04001293void
James Smart2e0fef82007-06-17 19:56:36 -05001294lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001295{
1296 int sentplogi;
1297
James Smart2e0fef82007-06-17 19:56:36 -05001298 if (vport->num_disc_nodes)
1299 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001300
1301 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001302 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1303 "0232 Continue discovery with %d PLOGIs to go "
1304 "Data: x%x x%x x%x\n",
1305 vport->num_disc_nodes, vport->fc_plogi_cnt,
1306 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001307 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001308 if (vport->fc_flag & FC_NLP_MORE)
1309 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1310 sentplogi = lpfc_els_disc_plogi(vport);
1311
dea31012005-04-17 16:05:31 -05001312 return;
1313}
1314
James Smarte59058c2008-08-24 21:49:00 -04001315/**
James Smart3621a712009-04-06 18:47:14 -04001316 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001317 * @phba: pointer to lpfc hba data structure.
1318 * @prsp: pointer to response IOCB payload.
1319 * @ndlp: pointer to a node-list data structure.
1320 *
1321 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1322 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1323 * The following cases are considered N_Port confirmed:
1324 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1325 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1326 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1327 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1328 * 1) if there is a node on vport list other than the @ndlp with the same
1329 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1330 * on that node to release the RPI associated with the node; 2) if there is
1331 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1332 * into, a new node shall be allocated (or activated). In either case, the
1333 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1334 * be released and the new_ndlp shall be put on to the vport node list and
1335 * its pointer returned as the confirmed node.
1336 *
1337 * Note that before the @ndlp got "released", the keepDID from not-matching
1338 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1339 * of the @ndlp. This is because the release of @ndlp is actually to put it
1340 * into an inactive state on the vport node list and the vport node list
1341 * management algorithm does not allow two node with a same DID.
1342 *
1343 * Return code
1344 * pointer to the PLOGI N_Port @ndlp
1345 **/
James Smart488d1462006-03-07 15:02:37 -05001346static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001347lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001348 struct lpfc_nodelist *ndlp)
1349{
James Smart2e0fef82007-06-17 19:56:36 -05001350 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001351 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001352 struct lpfc_rport_data *rdata;
1353 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001354 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001355 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001356 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001357 int put_node;
1358 int put_rport;
James Smart19ca7602010-11-20 23:11:55 -05001359 struct lpfc_node_rrqs rrq;
James Smart488d1462006-03-07 15:02:37 -05001360
James Smart2fb9bd82006-12-02 13:33:57 -05001361 /* Fabric nodes can have the same WWPN so we don't bother searching
1362 * by WWPN. Just return the ndlp that was given to us.
1363 */
1364 if (ndlp->nlp_type & NLP_FABRIC)
1365 return ndlp;
1366
James Smart92d7f7b2007-06-17 19:56:38 -05001367 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001368 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001369
James Smart685f0bf2007-04-25 09:53:08 -04001370 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001371 * we have for that ndlp. If not, we have some work to do.
1372 */
James Smart2e0fef82007-06-17 19:56:36 -05001373 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001374
James Smarte47c9092008-02-08 18:49:26 -05001375 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001376 return ndlp;
James Smart19ca7602010-11-20 23:11:55 -05001377 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
James Smart488d1462006-03-07 15:02:37 -05001378
1379 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001380 rc = memcmp(&ndlp->nlp_portname, name,
1381 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001382 if (!rc)
1383 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001384 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1385 if (!new_ndlp)
1386 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001387 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001388 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001389 rc = memcmp(&ndlp->nlp_portname, name,
1390 sizeof(struct lpfc_name));
1391 if (!rc)
1392 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001393 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1394 NLP_STE_UNUSED_NODE);
1395 if (!new_ndlp)
1396 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001397 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001398 if (phba->sli_rev == LPFC_SLI_REV4)
1399 memcpy(&rrq.xri_bitmap,
1400 &new_ndlp->active_rrqs.xri_bitmap,
1401 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1402 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001403 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001404 if (phba->sli_rev == LPFC_SLI_REV4)
1405 memcpy(&rrq.xri_bitmap,
1406 &new_ndlp->active_rrqs.xri_bitmap,
1407 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1408 }
James Smart488d1462006-03-07 15:02:37 -05001409
James Smart2e0fef82007-06-17 19:56:36 -05001410 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001411 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001412 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001413 if (phba->sli_rev == LPFC_SLI_REV4)
1414 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1415 &ndlp->active_rrqs.xri_bitmap,
1416 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart0ff10d42008-01-11 01:52:36 -05001417
1418 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1419 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1420 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1421
James Smarte47c9092008-02-08 18:49:26 -05001422 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001423 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001424
James Smart2e0fef82007-06-17 19:56:36 -05001425 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001426 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1427 /* The new_ndlp is replacing ndlp totally, so we need
1428 * to put ndlp on UNUSED list and try to free it.
1429 */
James Smart0ff10d42008-01-11 01:52:36 -05001430
1431 /* Fix up the rport accordingly */
1432 rport = ndlp->rport;
1433 if (rport) {
1434 rdata = rport->dd_data;
1435 if (rdata->pnode == ndlp) {
1436 lpfc_nlp_put(ndlp);
1437 ndlp->rport = NULL;
1438 rdata->pnode = lpfc_nlp_get(new_ndlp);
1439 new_ndlp->rport = rport;
1440 }
1441 new_ndlp->nlp_type = ndlp->nlp_type;
1442 }
James Smart58da1ff2008-04-07 10:15:56 -04001443 /* We shall actually free the ndlp with both nlp_DID and
1444 * nlp_portname fields equals 0 to avoid any ndlp on the
1445 * nodelist never to be used.
1446 */
1447 if (ndlp->nlp_DID == 0) {
1448 spin_lock_irq(&phba->ndlp_lock);
1449 NLP_SET_FREE_REQ(ndlp);
1450 spin_unlock_irq(&phba->ndlp_lock);
1451 }
James Smart0ff10d42008-01-11 01:52:36 -05001452
James Smart58da1ff2008-04-07 10:15:56 -04001453 /* Two ndlps cannot have the same did on the nodelist */
1454 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001455 if (phba->sli_rev == LPFC_SLI_REV4)
1456 memcpy(&ndlp->active_rrqs.xri_bitmap,
1457 &rrq.xri_bitmap,
1458 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001459 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001460 }
James Smart92795652006-07-06 15:50:02 -04001461 else {
James Smart2e0fef82007-06-17 19:56:36 -05001462 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001463 /* Two ndlps cannot have the same did */
1464 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001465 if (phba->sli_rev == LPFC_SLI_REV4)
1466 memcpy(&ndlp->active_rrqs.xri_bitmap,
1467 &rrq.xri_bitmap,
1468 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001469 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart38b92ef2010-08-04 16:11:39 -04001470 /* Since we are swapping the ndlp passed in with the new one
1471 * and the did has already been swapped, copy over the
1472 * state and names.
1473 */
1474 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1475 sizeof(struct lpfc_name));
1476 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1477 sizeof(struct lpfc_name));
1478 new_ndlp->nlp_state = ndlp->nlp_state;
1479 /* Fix up the rport accordingly */
1480 rport = ndlp->rport;
1481 if (rport) {
1482 rdata = rport->dd_data;
1483 put_node = rdata->pnode != NULL;
1484 put_rport = ndlp->rport != NULL;
1485 rdata->pnode = NULL;
1486 ndlp->rport = NULL;
1487 if (put_node)
1488 lpfc_nlp_put(ndlp);
1489 if (put_rport)
1490 put_device(&rport->dev);
1491 }
James Smart92795652006-07-06 15:50:02 -04001492 }
James Smart488d1462006-03-07 15:02:37 -05001493 return new_ndlp;
1494}
1495
James Smarte59058c2008-08-24 21:49:00 -04001496/**
James Smart3621a712009-04-06 18:47:14 -04001497 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001498 * @vport: pointer to a host virtual N_Port data structure.
1499 *
1500 * This routine checks whether more Registration State Change
1501 * Notifications (RSCNs) came in while the discovery state machine was in
1502 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1503 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1504 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1505 * handling the RSCNs.
1506 **/
James Smart87af33f2007-10-27 13:37:43 -04001507void
1508lpfc_end_rscn(struct lpfc_vport *vport)
1509{
1510 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1511
1512 if (vport->fc_flag & FC_RSCN_MODE) {
1513 /*
1514 * Check to see if more RSCNs came in while we were
1515 * processing this one.
1516 */
1517 if (vport->fc_rscn_id_cnt ||
1518 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1519 lpfc_els_handle_rscn(vport);
1520 else {
1521 spin_lock_irq(shost->host_lock);
1522 vport->fc_flag &= ~FC_RSCN_MODE;
1523 spin_unlock_irq(shost->host_lock);
1524 }
1525 }
1526}
1527
James Smarte59058c2008-08-24 21:49:00 -04001528/**
James Smart19ca7602010-11-20 23:11:55 -05001529 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1530 * @phba: pointer to lpfc hba data structure.
1531 * @cmdiocb: pointer to lpfc command iocb data structure.
1532 * @rspiocb: pointer to lpfc response iocb data structure.
1533 *
1534 * This routine will call the clear rrq function to free the rrq and
1535 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1536 * exist then the clear_rrq is still called because the rrq needs to
1537 * be freed.
1538 **/
1539
1540static void
1541lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1542 struct lpfc_iocbq *rspiocb)
1543{
1544 struct lpfc_vport *vport = cmdiocb->vport;
1545 IOCB_t *irsp;
1546 struct lpfc_nodelist *ndlp;
1547 struct lpfc_node_rrq *rrq;
1548
1549 /* we pass cmdiocb to state machine which needs rspiocb as well */
1550 rrq = cmdiocb->context_un.rrq;
1551 cmdiocb->context_un.rsp_iocb = rspiocb;
1552
1553 irsp = &rspiocb->iocb;
1554 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1555 "RRQ cmpl: status:x%x/x%x did:x%x",
1556 irsp->ulpStatus, irsp->un.ulpWord[4],
1557 irsp->un.elsreq64.remoteID);
1558
1559 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1560 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1561 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1562 "2882 RRQ completes to NPort x%x "
1563 "with no ndlp. Data: x%x x%x x%x\n",
1564 irsp->un.elsreq64.remoteID,
1565 irsp->ulpStatus, irsp->un.ulpWord[4],
1566 irsp->ulpIoTag);
1567 goto out;
1568 }
1569
1570 /* rrq completes to NPort <nlp_DID> */
1571 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1572 "2880 RRQ completes to NPort x%x "
1573 "Data: x%x x%x x%x x%x x%x\n",
1574 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1575 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1576
1577 if (irsp->ulpStatus) {
1578 /* Check for retry */
1579 /* RRQ failed Don't print the vport to vport rjts */
1580 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1581 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1582 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1583 (phba)->pport->cfg_log_verbose & LOG_ELS)
1584 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1585 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1586 ndlp->nlp_DID, irsp->ulpStatus,
1587 irsp->un.ulpWord[4]);
1588 }
1589out:
1590 if (rrq)
1591 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1592 lpfc_els_free_iocb(phba, cmdiocb);
1593 return;
1594}
1595/**
James Smart3621a712009-04-06 18:47:14 -04001596 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001597 * @phba: pointer to lpfc hba data structure.
1598 * @cmdiocb: pointer to lpfc command iocb data structure.
1599 * @rspiocb: pointer to lpfc response iocb data structure.
1600 *
1601 * This routine is the completion callback function for issuing the Port
1602 * Login (PLOGI) command. For PLOGI completion, there must be an active
1603 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001604 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001605 * ignored and command IOCB released. The PLOGI response IOCB status is
1606 * checked for error conditons. If there is error status reported, PLOGI
1607 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1608 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1609 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1610 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1611 * there are additional N_Port nodes with the vport that need to perform
1612 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1613 * PLOGIs.
1614 **/
dea31012005-04-17 16:05:31 -05001615static void
James Smart2e0fef82007-06-17 19:56:36 -05001616lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1617 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001618{
James Smart2e0fef82007-06-17 19:56:36 -05001619 struct lpfc_vport *vport = cmdiocb->vport;
1620 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001621 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001622 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001623 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001624 int disc, rc, did, type;
1625
dea31012005-04-17 16:05:31 -05001626 /* we pass cmdiocb to state machine which needs rspiocb as well */
1627 cmdiocb->context_un.rsp_iocb = rspiocb;
1628
1629 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001630 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1631 "PLOGI cmpl: status:x%x/x%x did:x%x",
1632 irsp->ulpStatus, irsp->un.ulpWord[4],
1633 irsp->un.elsreq64.remoteID);
1634
James Smart2e0fef82007-06-17 19:56:36 -05001635 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001636 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001637 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1638 "0136 PLOGI completes to NPort x%x "
1639 "with no ndlp. Data: x%x x%x x%x\n",
1640 irsp->un.elsreq64.remoteID,
1641 irsp->ulpStatus, irsp->un.ulpWord[4],
1642 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001643 goto out;
James Smarted957682007-06-17 19:56:37 -05001644 }
dea31012005-04-17 16:05:31 -05001645
1646 /* Since ndlp can be freed in the disc state machine, note if this node
1647 * is being used during discovery.
1648 */
James Smart2e0fef82007-06-17 19:56:36 -05001649 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001650 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001651 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001652 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001653 rc = 0;
1654
1655 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001656 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1657 "0102 PLOGI completes to NPort x%x "
1658 "Data: x%x x%x x%x x%x x%x\n",
1659 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1660 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001661 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001662 if (lpfc_els_chk_latt(vport)) {
1663 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001664 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001665 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001666 goto out;
1667 }
1668
1669 /* ndlp could be freed in DSM, save these values now */
1670 type = ndlp->nlp_type;
1671 did = ndlp->nlp_DID;
1672
1673 if (irsp->ulpStatus) {
1674 /* Check for retry */
1675 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1676 /* ELS command is being retried */
1677 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001678 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001679 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001680 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001681 }
1682 goto out;
1683 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001684 /* PLOGI failed Don't print the vport to vport rjts */
1685 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1686 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1687 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1688 (phba)->pport->cfg_log_verbose & LOG_ELS)
1689 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001690 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1691 ndlp->nlp_DID, irsp->ulpStatus,
1692 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001693 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001694 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001695 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001696 else
James Smart2e0fef82007-06-17 19:56:36 -05001697 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001698 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001699 } else {
1700 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001701 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001702 cmdiocb->context2)->list.next,
1703 struct lpfc_dmabuf, list);
1704 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001705 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001706 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001707 }
1708
James Smart2e0fef82007-06-17 19:56:36 -05001709 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001710 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001711 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001712
James Smart2e0fef82007-06-17 19:56:36 -05001713 if (vport->num_disc_nodes == 0) {
1714 spin_lock_irq(shost->host_lock);
1715 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1716 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001717
James Smart2e0fef82007-06-17 19:56:36 -05001718 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001719 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001720 }
1721 }
1722
1723out:
1724 lpfc_els_free_iocb(phba, cmdiocb);
1725 return;
1726}
1727
James Smarte59058c2008-08-24 21:49:00 -04001728/**
James Smart3621a712009-04-06 18:47:14 -04001729 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001730 * @vport: pointer to a host virtual N_Port data structure.
1731 * @did: destination port identifier.
1732 * @retry: number of retries to the command IOCB.
1733 *
1734 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1735 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1736 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1737 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1738 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1739 *
1740 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1741 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1742 * will be stored into the context1 field of the IOCB for the completion
1743 * callback function to the PLOGI ELS command.
1744 *
1745 * Return code
1746 * 0 - Successfully issued a plogi for @vport
1747 * 1 - failed to issue a plogi for @vport
1748 **/
dea31012005-04-17 16:05:31 -05001749int
James Smart2e0fef82007-06-17 19:56:36 -05001750lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001751{
James Smart2e0fef82007-06-17 19:56:36 -05001752 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001753 struct serv_parm *sp;
1754 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001755 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001756 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001757 struct lpfc_sli *psli;
1758 uint8_t *pcmd;
1759 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001760 int ret;
dea31012005-04-17 16:05:31 -05001761
1762 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001763
James Smart98c9ea52007-10-27 13:37:33 -04001764 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001765 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1766 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001767
James Smarte47c9092008-02-08 18:49:26 -05001768 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001769 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001770 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001771 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001772 if (!elsiocb)
1773 return 1;
dea31012005-04-17 16:05:31 -05001774
1775 icmd = &elsiocb->iocb;
1776 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1777
1778 /* For PLOGI request, remainder of payload is service parameters */
1779 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001780 pcmd += sizeof(uint32_t);
1781 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001782 sp = (struct serv_parm *) pcmd;
1783
James Smart5ac6b302010-10-22 11:05:36 -04001784 /*
1785 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1786 * to device on remote loops work.
1787 */
1788 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1789 sp->cmn.altBbCredit = 1;
1790
dea31012005-04-17 16:05:31 -05001791 if (sp->cmn.fcphLow < FC_PH_4_3)
1792 sp->cmn.fcphLow = FC_PH_4_3;
1793
1794 if (sp->cmn.fcphHigh < FC_PH3)
1795 sp->cmn.fcphHigh = FC_PH3;
1796
James Smart858c9f62007-06-17 19:56:39 -05001797 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1798 "Issue PLOGI: did:x%x",
1799 did, 0, 0);
1800
dea31012005-04-17 16:05:31 -05001801 phba->fc_stat.elsXmitPLOGI++;
1802 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001803 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001804
1805 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001806 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001807 return 1;
dea31012005-04-17 16:05:31 -05001808 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001809 return 0;
dea31012005-04-17 16:05:31 -05001810}
1811
James Smarte59058c2008-08-24 21:49:00 -04001812/**
James Smart3621a712009-04-06 18:47:14 -04001813 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001814 * @phba: pointer to lpfc hba data structure.
1815 * @cmdiocb: pointer to lpfc command iocb data structure.
1816 * @rspiocb: pointer to lpfc response iocb data structure.
1817 *
1818 * This routine is the completion callback function for a Process Login
1819 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1820 * status. If there is error status reported, PRLI retry shall be attempted
1821 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1822 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1823 * ndlp to mark the PRLI completion.
1824 **/
dea31012005-04-17 16:05:31 -05001825static void
James Smart2e0fef82007-06-17 19:56:36 -05001826lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1827 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001828{
James Smart2e0fef82007-06-17 19:56:36 -05001829 struct lpfc_vport *vport = cmdiocb->vport;
1830 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001831 IOCB_t *irsp;
1832 struct lpfc_sli *psli;
1833 struct lpfc_nodelist *ndlp;
1834
1835 psli = &phba->sli;
1836 /* we pass cmdiocb to state machine which needs rspiocb as well */
1837 cmdiocb->context_un.rsp_iocb = rspiocb;
1838
1839 irsp = &(rspiocb->iocb);
1840 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001841 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001842 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001843 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001844
James Smart858c9f62007-06-17 19:56:39 -05001845 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1846 "PRLI cmpl: status:x%x/x%x did:x%x",
1847 irsp->ulpStatus, irsp->un.ulpWord[4],
1848 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001849 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001850 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1851 "0103 PRLI completes to NPort x%x "
1852 "Data: x%x x%x x%x x%x\n",
1853 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1854 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001855
James Smart2e0fef82007-06-17 19:56:36 -05001856 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001857 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001858 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001859 goto out;
1860
1861 if (irsp->ulpStatus) {
1862 /* Check for retry */
1863 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1864 /* ELS command is being retried */
1865 goto out;
1866 }
1867 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001868 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1869 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1870 ndlp->nlp_DID, irsp->ulpStatus,
1871 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001872 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001873 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001874 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001875 else
James Smart2e0fef82007-06-17 19:56:36 -05001876 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001877 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001878 } else
dea31012005-04-17 16:05:31 -05001879 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001880 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001881 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001882out:
1883 lpfc_els_free_iocb(phba, cmdiocb);
1884 return;
1885}
1886
James Smarte59058c2008-08-24 21:49:00 -04001887/**
James Smart3621a712009-04-06 18:47:14 -04001888 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001889 * @vport: pointer to a host virtual N_Port data structure.
1890 * @ndlp: pointer to a node-list data structure.
1891 * @retry: number of retries to the command IOCB.
1892 *
1893 * This routine issues a Process Login (PRLI) ELS command for the
1894 * @vport. The PRLI service parameters are set up in the payload of the
1895 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1896 * is put to the IOCB completion callback func field before invoking the
1897 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1898 *
1899 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1900 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1901 * will be stored into the context1 field of the IOCB for the completion
1902 * callback function to the PRLI ELS command.
1903 *
1904 * Return code
1905 * 0 - successfully issued prli iocb command for @vport
1906 * 1 - failed to issue prli iocb command for @vport
1907 **/
dea31012005-04-17 16:05:31 -05001908int
James Smart2e0fef82007-06-17 19:56:36 -05001909lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001910 uint8_t retry)
1911{
James Smart2e0fef82007-06-17 19:56:36 -05001912 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1913 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001914 PRLI *npr;
1915 IOCB_t *icmd;
1916 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001917 uint8_t *pcmd;
1918 uint16_t cmdsize;
1919
James Smart92d7f7b2007-06-17 19:56:38 -05001920 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001921 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1922 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001923 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001924 return 1;
dea31012005-04-17 16:05:31 -05001925
1926 icmd = &elsiocb->iocb;
1927 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1928
1929 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001930 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001931 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001932 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001933
1934 /* For PRLI, remainder of payload is PRLI parameter page */
1935 npr = (PRLI *) pcmd;
1936 /*
1937 * If our firmware version is 3.20 or later,
1938 * set the following bits for FC-TAPE support.
1939 */
1940 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1941 npr->ConfmComplAllowed = 1;
1942 npr->Retry = 1;
1943 npr->TaskRetryIdReq = 1;
1944 }
1945 npr->estabImagePair = 1;
1946 npr->readXferRdyDis = 1;
1947
1948 /* For FCP support */
1949 npr->prliType = PRLI_FCP_TYPE;
1950 npr->initiatorFunc = 1;
1951
James Smart858c9f62007-06-17 19:56:39 -05001952 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1953 "Issue PRLI: did:x%x",
1954 ndlp->nlp_DID, 0, 0);
1955
dea31012005-04-17 16:05:31 -05001956 phba->fc_stat.elsXmitPRLI++;
1957 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001958 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001959 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001960 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001961 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1962 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001963 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001964 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001965 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001966 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001967 return 1;
dea31012005-04-17 16:05:31 -05001968 }
James Smart2e0fef82007-06-17 19:56:36 -05001969 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001970 return 0;
dea31012005-04-17 16:05:31 -05001971}
1972
James Smarte59058c2008-08-24 21:49:00 -04001973/**
James Smart3621a712009-04-06 18:47:14 -04001974 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001975 * @vport: pointer to a host virtual N_Port data structure.
1976 *
1977 * This routine performs Registration State Change Notification (RSCN)
1978 * discovery for a @vport. If the @vport's node port recovery count is not
1979 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1980 * the nodes that need recovery. If none of the PLOGI were needed through
1981 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1982 * invoked to check and handle possible more RSCN came in during the period
1983 * of processing the current ones.
1984 **/
1985static void
1986lpfc_rscn_disc(struct lpfc_vport *vport)
1987{
1988 lpfc_can_disctmo(vport);
1989
1990 /* RSCN discovery */
1991 /* go thru NPR nodes and issue ELS PLOGIs */
1992 if (vport->fc_npr_cnt)
1993 if (lpfc_els_disc_plogi(vport))
1994 return;
1995
1996 lpfc_end_rscn(vport);
1997}
1998
1999/**
James Smart3621a712009-04-06 18:47:14 -04002000 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002001 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2002 *
2003 * This function is called when the final ADISC is completed during discovery.
2004 * This function handles clearing link attention or issuing reg_vpi depending
2005 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2006 * discovery.
2007 * This function is called with no locks held.
2008 **/
2009static void
2010lpfc_adisc_done(struct lpfc_vport *vport)
2011{
2012 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2013 struct lpfc_hba *phba = vport->phba;
2014
2015 /*
2016 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2017 * and continue discovery.
2018 */
2019 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002020 !(vport->fc_flag & FC_RSCN_MODE) &&
2021 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04002022 lpfc_issue_reg_vpi(phba, vport);
2023 return;
2024 }
2025 /*
2026 * For SLI2, we need to set port_state to READY
2027 * and continue discovery.
2028 */
2029 if (vport->port_state < LPFC_VPORT_READY) {
2030 /* If we get here, there is nothing to ADISC */
2031 if (vport->port_type == LPFC_PHYSICAL_PORT)
2032 lpfc_issue_clear_la(phba, vport);
2033 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2034 vport->num_disc_nodes = 0;
2035 /* go thru NPR list, issue ELS PLOGIs */
2036 if (vport->fc_npr_cnt)
2037 lpfc_els_disc_plogi(vport);
2038 if (!vport->num_disc_nodes) {
2039 spin_lock_irq(shost->host_lock);
2040 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2041 spin_unlock_irq(shost->host_lock);
2042 lpfc_can_disctmo(vport);
2043 lpfc_end_rscn(vport);
2044 }
2045 }
2046 vport->port_state = LPFC_VPORT_READY;
2047 } else
2048 lpfc_rscn_disc(vport);
2049}
2050
2051/**
James Smart3621a712009-04-06 18:47:14 -04002052 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002053 * @vport: pointer to a host virtual N_Port data structure.
2054 *
2055 * This routine determines whether there are more ndlps on a @vport
2056 * node list need to have Address Discover (ADISC) issued. If so, it will
2057 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2058 * remaining nodes which need to have ADISC sent.
2059 **/
James Smart0ff10d42008-01-11 01:52:36 -05002060void
James Smart2e0fef82007-06-17 19:56:36 -05002061lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002062{
2063 int sentadisc;
2064
James Smart2e0fef82007-06-17 19:56:36 -05002065 if (vport->num_disc_nodes)
2066 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002067 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002068 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2069 "0210 Continue discovery with %d ADISCs to go "
2070 "Data: x%x x%x x%x\n",
2071 vport->num_disc_nodes, vport->fc_adisc_cnt,
2072 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002073 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002074 if (vport->fc_flag & FC_NLP_MORE) {
2075 lpfc_set_disctmo(vport);
2076 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2077 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002078 }
James Smart90160e02008-08-24 21:49:45 -04002079 if (!vport->num_disc_nodes)
2080 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002081 return;
2082}
2083
James Smarte59058c2008-08-24 21:49:00 -04002084/**
James Smart3621a712009-04-06 18:47:14 -04002085 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002086 * @phba: pointer to lpfc hba data structure.
2087 * @cmdiocb: pointer to lpfc command iocb data structure.
2088 * @rspiocb: pointer to lpfc response iocb data structure.
2089 *
2090 * This routine is the completion function for issuing the Address Discover
2091 * (ADISC) command. It first checks to see whether link went down during
2092 * the discovery process. If so, the node will be marked as node port
2093 * recovery for issuing discover IOCB by the link attention handler and
2094 * exit. Otherwise, the response status is checked. If error was reported
2095 * in the response status, the ADISC command shall be retried by invoking
2096 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2097 * the response status, the state machine is invoked to set transition
2098 * with respect to NLP_EVT_CMPL_ADISC event.
2099 **/
dea31012005-04-17 16:05:31 -05002100static void
James Smart2e0fef82007-06-17 19:56:36 -05002101lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2102 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002103{
James Smart2e0fef82007-06-17 19:56:36 -05002104 struct lpfc_vport *vport = cmdiocb->vport;
2105 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002106 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002107 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002108 int disc;
dea31012005-04-17 16:05:31 -05002109
2110 /* we pass cmdiocb to state machine which needs rspiocb as well */
2111 cmdiocb->context_un.rsp_iocb = rspiocb;
2112
2113 irsp = &(rspiocb->iocb);
2114 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002115
James Smart858c9f62007-06-17 19:56:39 -05002116 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2117 "ADISC cmpl: status:x%x/x%x did:x%x",
2118 irsp->ulpStatus, irsp->un.ulpWord[4],
2119 ndlp->nlp_DID);
2120
dea31012005-04-17 16:05:31 -05002121 /* Since ndlp can be freed in the disc state machine, note if this node
2122 * is being used during discovery.
2123 */
James Smart2e0fef82007-06-17 19:56:36 -05002124 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002125 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002126 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002127 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002128 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002129 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2130 "0104 ADISC completes to NPort x%x "
2131 "Data: x%x x%x x%x x%x x%x\n",
2132 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2133 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002134 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002135 if (lpfc_els_chk_latt(vport)) {
2136 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002137 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002138 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002139 goto out;
2140 }
2141
2142 if (irsp->ulpStatus) {
2143 /* Check for retry */
2144 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2145 /* ELS command is being retried */
2146 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002147 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002148 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002149 spin_unlock_irq(shost->host_lock);
2150 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002151 }
2152 goto out;
2153 }
2154 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002155 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2156 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2157 ndlp->nlp_DID, irsp->ulpStatus,
2158 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002159 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002160 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002161 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002162 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002163 } else
dea31012005-04-17 16:05:31 -05002164 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002165 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002166 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002167
James Smart90160e02008-08-24 21:49:45 -04002168 /* Check to see if there are more ADISCs to be sent */
2169 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002170 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002171out:
2172 lpfc_els_free_iocb(phba, cmdiocb);
2173 return;
2174}
2175
James Smarte59058c2008-08-24 21:49:00 -04002176/**
James Smart3621a712009-04-06 18:47:14 -04002177 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002178 * @vport: pointer to a virtual N_Port data structure.
2179 * @ndlp: pointer to a node-list data structure.
2180 * @retry: number of retries to the command IOCB.
2181 *
2182 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2183 * @vport. It prepares the payload of the ADISC ELS command, updates the
2184 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2185 * to issue the ADISC ELS command.
2186 *
2187 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2188 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2189 * will be stored into the context1 field of the IOCB for the completion
2190 * callback function to the ADISC ELS command.
2191 *
2192 * Return code
2193 * 0 - successfully issued adisc
2194 * 1 - failed to issue adisc
2195 **/
dea31012005-04-17 16:05:31 -05002196int
James Smart2e0fef82007-06-17 19:56:36 -05002197lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002198 uint8_t retry)
2199{
James Smart2e0fef82007-06-17 19:56:36 -05002200 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2201 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002202 ADISC *ap;
2203 IOCB_t *icmd;
2204 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002205 uint8_t *pcmd;
2206 uint16_t cmdsize;
2207
James Smart92d7f7b2007-06-17 19:56:38 -05002208 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002209 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2210 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002211 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002212 return 1;
dea31012005-04-17 16:05:31 -05002213
2214 icmd = &elsiocb->iocb;
2215 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2216
2217 /* For ADISC request, remainder of payload is service parameters */
2218 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002219 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002220
2221 /* Fill in ADISC payload */
2222 ap = (ADISC *) pcmd;
2223 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002224 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2225 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002226 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002227
James Smart858c9f62007-06-17 19:56:39 -05002228 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2229 "Issue ADISC: did:x%x",
2230 ndlp->nlp_DID, 0, 0);
2231
dea31012005-04-17 16:05:31 -05002232 phba->fc_stat.elsXmitADISC++;
2233 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002234 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002235 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002236 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002237 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2238 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002239 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002240 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002241 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002242 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002243 return 1;
dea31012005-04-17 16:05:31 -05002244 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002245 return 0;
dea31012005-04-17 16:05:31 -05002246}
2247
James Smarte59058c2008-08-24 21:49:00 -04002248/**
James Smart3621a712009-04-06 18:47:14 -04002249 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002250 * @phba: pointer to lpfc hba data structure.
2251 * @cmdiocb: pointer to lpfc command iocb data structure.
2252 * @rspiocb: pointer to lpfc response iocb data structure.
2253 *
2254 * This routine is the completion function for issuing the ELS Logout (LOGO)
2255 * command. If no error status was reported from the LOGO response, the
2256 * state machine of the associated ndlp shall be invoked for transition with
2257 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2258 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2259 **/
dea31012005-04-17 16:05:31 -05002260static void
James Smart2e0fef82007-06-17 19:56:36 -05002261lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2262 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002263{
James Smart2e0fef82007-06-17 19:56:36 -05002264 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2265 struct lpfc_vport *vport = ndlp->vport;
2266 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002267 IOCB_t *irsp;
2268 struct lpfc_sli *psli;
James Smart92494142011-02-16 12:39:44 -05002269 struct lpfcMboxq *mbox;
dea31012005-04-17 16:05:31 -05002270
2271 psli = &phba->sli;
2272 /* we pass cmdiocb to state machine which needs rspiocb as well */
2273 cmdiocb->context_un.rsp_iocb = rspiocb;
2274
2275 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002276 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002277 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002278 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002279
James Smart858c9f62007-06-17 19:56:39 -05002280 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2281 "LOGO cmpl: status:x%x/x%x did:x%x",
2282 irsp->ulpStatus, irsp->un.ulpWord[4],
2283 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002284 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002285 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2286 "0105 LOGO completes to NPort x%x "
2287 "Data: x%x x%x x%x x%x\n",
2288 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2289 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002290 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002291 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002292 goto out;
2293
James Smart92d7f7b2007-06-17 19:56:38 -05002294 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2295 /* NLP_EVT_DEVICE_RM should unregister the RPI
2296 * which should abort all outstanding IOs.
2297 */
2298 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2299 NLP_EVT_DEVICE_RM);
2300 goto out;
2301 }
2302
dea31012005-04-17 16:05:31 -05002303 if (irsp->ulpStatus) {
2304 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002305 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002306 /* ELS command is being retried */
2307 goto out;
dea31012005-04-17 16:05:31 -05002308 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002309 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2310 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2311 ndlp->nlp_DID, irsp->ulpStatus,
2312 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002313 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002314 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002315 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002316 else
James Smart2e0fef82007-06-17 19:56:36 -05002317 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002318 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002319 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002320 /* Good status, call state machine.
2321 * This will unregister the rpi if needed.
2322 */
James Smart2e0fef82007-06-17 19:56:36 -05002323 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002324 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002325out:
2326 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002327 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2328 if ((vport->fc_flag & FC_PT2PT) &&
2329 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2330 phba->pport->fc_myDID = 0;
2331 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2332 if (mbox) {
2333 lpfc_config_link(phba, mbox);
2334 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2335 mbox->vport = vport;
2336 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2337 MBX_NOT_FINISHED) {
2338 mempool_free(mbox, phba->mbox_mem_pool);
2339 }
2340 }
2341 }
dea31012005-04-17 16:05:31 -05002342 return;
2343}
2344
James Smarte59058c2008-08-24 21:49:00 -04002345/**
James Smart3621a712009-04-06 18:47:14 -04002346 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002347 * @vport: pointer to a virtual N_Port data structure.
2348 * @ndlp: pointer to a node-list data structure.
2349 * @retry: number of retries to the command IOCB.
2350 *
2351 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2352 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2353 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2354 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2355 *
2356 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2357 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2358 * will be stored into the context1 field of the IOCB for the completion
2359 * callback function to the LOGO ELS command.
2360 *
2361 * Return code
2362 * 0 - successfully issued logo
2363 * 1 - failed to issue logo
2364 **/
dea31012005-04-17 16:05:31 -05002365int
James Smart2e0fef82007-06-17 19:56:36 -05002366lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002367 uint8_t retry)
2368{
James Smart2e0fef82007-06-17 19:56:36 -05002369 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2370 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002371 IOCB_t *icmd;
2372 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002373 uint8_t *pcmd;
2374 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002375 int rc;
dea31012005-04-17 16:05:31 -05002376
James Smart98c9ea52007-10-27 13:37:33 -04002377 spin_lock_irq(shost->host_lock);
2378 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2379 spin_unlock_irq(shost->host_lock);
2380 return 0;
2381 }
2382 spin_unlock_irq(shost->host_lock);
2383
James Smart92d7f7b2007-06-17 19:56:38 -05002384 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002385 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2386 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002387 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002388 return 1;
dea31012005-04-17 16:05:31 -05002389
2390 icmd = &elsiocb->iocb;
2391 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2392 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002393 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002394
2395 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002396 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002397 pcmd += sizeof(uint32_t);
2398 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002399
James Smart858c9f62007-06-17 19:56:39 -05002400 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2401 "Issue LOGO: did:x%x",
2402 ndlp->nlp_DID, 0, 0);
2403
dea31012005-04-17 16:05:31 -05002404 phba->fc_stat.elsXmitLOGO++;
2405 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002406 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002407 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002408 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002409 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002410
2411 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002412 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002413 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002414 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002415 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002416 return 1;
dea31012005-04-17 16:05:31 -05002417 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002418 return 0;
dea31012005-04-17 16:05:31 -05002419}
2420
James Smarte59058c2008-08-24 21:49:00 -04002421/**
James Smart3621a712009-04-06 18:47:14 -04002422 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002423 * @phba: pointer to lpfc hba data structure.
2424 * @cmdiocb: pointer to lpfc command iocb data structure.
2425 * @rspiocb: pointer to lpfc response iocb data structure.
2426 *
2427 * This routine is a generic completion callback function for ELS commands.
2428 * Specifically, it is the callback function which does not need to perform
2429 * any command specific operations. It is currently used by the ELS command
2430 * issuing routines for the ELS State Change Request (SCR),
2431 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2432 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2433 * certain debug loggings, this callback function simply invokes the
2434 * lpfc_els_chk_latt() routine to check whether link went down during the
2435 * discovery process.
2436 **/
dea31012005-04-17 16:05:31 -05002437static void
James Smart2e0fef82007-06-17 19:56:36 -05002438lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2439 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002440{
James Smart2e0fef82007-06-17 19:56:36 -05002441 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002442 IOCB_t *irsp;
2443
2444 irsp = &rspiocb->iocb;
2445
James Smart858c9f62007-06-17 19:56:39 -05002446 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2447 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2448 irsp->ulpStatus, irsp->un.ulpWord[4],
2449 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002450 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002451 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2452 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2453 irsp->ulpIoTag, irsp->ulpStatus,
2454 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002455 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002456 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002457 lpfc_els_free_iocb(phba, cmdiocb);
2458 return;
2459}
2460
James Smarte59058c2008-08-24 21:49:00 -04002461/**
James Smart3621a712009-04-06 18:47:14 -04002462 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002463 * @vport: pointer to a host virtual N_Port data structure.
2464 * @nportid: N_Port identifier to the remote node.
2465 * @retry: number of retries to the command IOCB.
2466 *
2467 * This routine issues a State Change Request (SCR) to a fabric node
2468 * on a @vport. The remote node @nportid is passed into the function. It
2469 * first search the @vport node list to find the matching ndlp. If no such
2470 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2471 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2472 * routine is invoked to send the SCR IOCB.
2473 *
2474 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2475 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2476 * will be stored into the context1 field of the IOCB for the completion
2477 * callback function to the SCR ELS command.
2478 *
2479 * Return code
2480 * 0 - Successfully issued scr command
2481 * 1 - Failed to issue scr command
2482 **/
dea31012005-04-17 16:05:31 -05002483int
James Smart2e0fef82007-06-17 19:56:36 -05002484lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002485{
James Smart2e0fef82007-06-17 19:56:36 -05002486 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002487 IOCB_t *icmd;
2488 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002489 struct lpfc_sli *psli;
2490 uint8_t *pcmd;
2491 uint16_t cmdsize;
2492 struct lpfc_nodelist *ndlp;
2493
2494 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002495 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002496
James Smarte47c9092008-02-08 18:49:26 -05002497 ndlp = lpfc_findnode_did(vport, nportid);
2498 if (!ndlp) {
2499 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2500 if (!ndlp)
2501 return 1;
2502 lpfc_nlp_init(vport, ndlp, nportid);
2503 lpfc_enqueue_node(vport, ndlp);
2504 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2505 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2506 if (!ndlp)
2507 return 1;
2508 }
dea31012005-04-17 16:05:31 -05002509
James Smart2e0fef82007-06-17 19:56:36 -05002510 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2511 ndlp->nlp_DID, ELS_CMD_SCR);
2512
James Smart488d1462006-03-07 15:02:37 -05002513 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002514 /* This will trigger the release of the node just
2515 * allocated
2516 */
James Smart329f9bc2007-04-25 09:53:01 -04002517 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002518 return 1;
dea31012005-04-17 16:05:31 -05002519 }
2520
2521 icmd = &elsiocb->iocb;
2522 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2523
2524 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002525 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002526
2527 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002528 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002529 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2530
James Smart858c9f62007-06-17 19:56:39 -05002531 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2532 "Issue SCR: did:x%x",
2533 ndlp->nlp_DID, 0, 0);
2534
dea31012005-04-17 16:05:31 -05002535 phba->fc_stat.elsXmitSCR++;
2536 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002537 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2538 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002539 /* The additional lpfc_nlp_put will cause the following
2540 * lpfc_els_free_iocb routine to trigger the rlease of
2541 * the node.
2542 */
James Smart329f9bc2007-04-25 09:53:01 -04002543 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002544 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002545 return 1;
dea31012005-04-17 16:05:31 -05002546 }
James Smartfa4066b2008-01-11 01:53:27 -05002547 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2548 * trigger the release of node.
2549 */
James Smart329f9bc2007-04-25 09:53:01 -04002550 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002551 return 0;
dea31012005-04-17 16:05:31 -05002552}
2553
James Smarte59058c2008-08-24 21:49:00 -04002554/**
James Smart3621a712009-04-06 18:47:14 -04002555 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002556 * @vport: pointer to a host virtual N_Port data structure.
2557 * @nportid: N_Port identifier to the remote node.
2558 * @retry: number of retries to the command IOCB.
2559 *
2560 * This routine issues a Fibre Channel Address Resolution Response
2561 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2562 * is passed into the function. It first search the @vport node list to find
2563 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2564 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2565 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2566 *
2567 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2568 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2569 * will be stored into the context1 field of the IOCB for the completion
2570 * callback function to the PARPR ELS command.
2571 *
2572 * Return code
2573 * 0 - Successfully issued farpr command
2574 * 1 - Failed to issue farpr command
2575 **/
dea31012005-04-17 16:05:31 -05002576static int
James Smart2e0fef82007-06-17 19:56:36 -05002577lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002578{
James Smart2e0fef82007-06-17 19:56:36 -05002579 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002580 IOCB_t *icmd;
2581 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002582 struct lpfc_sli *psli;
2583 FARP *fp;
2584 uint8_t *pcmd;
2585 uint32_t *lp;
2586 uint16_t cmdsize;
2587 struct lpfc_nodelist *ondlp;
2588 struct lpfc_nodelist *ndlp;
2589
2590 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002591 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002592
James Smarte47c9092008-02-08 18:49:26 -05002593 ndlp = lpfc_findnode_did(vport, nportid);
2594 if (!ndlp) {
2595 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2596 if (!ndlp)
2597 return 1;
2598 lpfc_nlp_init(vport, ndlp, nportid);
2599 lpfc_enqueue_node(vport, ndlp);
2600 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2601 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2602 if (!ndlp)
2603 return 1;
2604 }
James Smart2e0fef82007-06-17 19:56:36 -05002605
2606 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2607 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002608 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002609 /* This will trigger the release of the node just
2610 * allocated
2611 */
James Smart329f9bc2007-04-25 09:53:01 -04002612 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002613 return 1;
dea31012005-04-17 16:05:31 -05002614 }
2615
2616 icmd = &elsiocb->iocb;
2617 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2618
2619 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002620 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002621
2622 /* Fill in FARPR payload */
2623 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002624 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002625 lp = (uint32_t *) pcmd;
2626 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002627 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002628 fp->Rflags = 0;
2629 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2630
James Smart92d7f7b2007-06-17 19:56:38 -05002631 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2632 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002633 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002634 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002635 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002636 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002637 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002638 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002639 }
2640
James Smart858c9f62007-06-17 19:56:39 -05002641 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2642 "Issue FARPR: did:x%x",
2643 ndlp->nlp_DID, 0, 0);
2644
dea31012005-04-17 16:05:31 -05002645 phba->fc_stat.elsXmitFARPR++;
2646 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002647 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2648 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002649 /* The additional lpfc_nlp_put will cause the following
2650 * lpfc_els_free_iocb routine to trigger the release of
2651 * the node.
2652 */
James Smart329f9bc2007-04-25 09:53:01 -04002653 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002654 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002655 return 1;
dea31012005-04-17 16:05:31 -05002656 }
James Smartfa4066b2008-01-11 01:53:27 -05002657 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2658 * trigger the release of the node.
2659 */
James Smart329f9bc2007-04-25 09:53:01 -04002660 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002661 return 0;
dea31012005-04-17 16:05:31 -05002662}
2663
James Smarte59058c2008-08-24 21:49:00 -04002664/**
James Smart3621a712009-04-06 18:47:14 -04002665 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002666 * @vport: pointer to a host virtual N_Port data structure.
2667 * @nlp: pointer to a node-list data structure.
2668 *
2669 * This routine cancels the timer with a delayed IOCB-command retry for
2670 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2671 * removes the ELS retry event if it presents. In addition, if the
2672 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2673 * commands are sent for the @vport's nodes that require issuing discovery
2674 * ADISC.
2675 **/
dea31012005-04-17 16:05:31 -05002676void
James Smart2e0fef82007-06-17 19:56:36 -05002677lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002678{
James Smart2e0fef82007-06-17 19:56:36 -05002679 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002680 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002681
James Smart0d2b6b82008-06-14 22:52:47 -04002682 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2683 return;
James Smart2e0fef82007-06-17 19:56:36 -05002684 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002685 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002686 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002687 del_timer_sync(&nlp->nlp_delayfunc);
2688 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002689 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002690 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002691 /* Decrement nlp reference count held for the delayed retry */
2692 evtp = &nlp->els_retry_evt;
2693 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2694 }
James Smartfdcebe22006-03-07 15:04:01 -05002695 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002696 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002697 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002698 spin_unlock_irq(shost->host_lock);
2699 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002700 if (vport->port_state < LPFC_VPORT_READY) {
2701 /* Check if there are more ADISCs to be sent */
2702 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002703 } else {
2704 /* Check if there are more PLOGIs to be sent */
2705 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002706 if (vport->num_disc_nodes == 0) {
2707 spin_lock_irq(shost->host_lock);
2708 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2709 spin_unlock_irq(shost->host_lock);
2710 lpfc_can_disctmo(vport);
2711 lpfc_end_rscn(vport);
2712 }
James Smartfdcebe22006-03-07 15:04:01 -05002713 }
2714 }
2715 }
2716 return;
2717}
2718
James Smarte59058c2008-08-24 21:49:00 -04002719/**
James Smart3621a712009-04-06 18:47:14 -04002720 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002721 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2722 *
2723 * This routine is invoked by the ndlp delayed-function timer to check
2724 * whether there is any pending ELS retry event(s) with the node. If not, it
2725 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2726 * adds the delayed events to the HBA work list and invokes the
2727 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2728 * event. Note that lpfc_nlp_get() is called before posting the event to
2729 * the work list to hold reference count of ndlp so that it guarantees the
2730 * reference to ndlp will still be available when the worker thread gets
2731 * to the event associated with the ndlp.
2732 **/
James Smartfdcebe22006-03-07 15:04:01 -05002733void
dea31012005-04-17 16:05:31 -05002734lpfc_els_retry_delay(unsigned long ptr)
2735{
James Smart2e0fef82007-06-17 19:56:36 -05002736 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2737 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002738 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002739 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002740 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002741
James Smart92d7f7b2007-06-17 19:56:38 -05002742 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002743 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002744 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002745 return;
2746 }
2747
James Smartfa4066b2008-01-11 01:53:27 -05002748 /* We need to hold the node by incrementing the reference
2749 * count until the queued work is done
2750 */
2751 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002752 if (evtp->evt_arg1) {
2753 evtp->evt = LPFC_EVT_ELS_RETRY;
2754 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002755 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002756 }
James Smart92d7f7b2007-06-17 19:56:38 -05002757 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002758 return;
2759}
2760
James Smarte59058c2008-08-24 21:49:00 -04002761/**
James Smart3621a712009-04-06 18:47:14 -04002762 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002763 * @ndlp: pointer to a node-list data structure.
2764 *
2765 * This routine is the worker-thread handler for processing the @ndlp delayed
2766 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2767 * the last ELS command from the associated ndlp and invokes the proper ELS
2768 * function according to the delayed ELS command to retry the command.
2769 **/
dea31012005-04-17 16:05:31 -05002770void
2771lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2772{
James Smart2e0fef82007-06-17 19:56:36 -05002773 struct lpfc_vport *vport = ndlp->vport;
2774 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2775 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002776
James Smart2e0fef82007-06-17 19:56:36 -05002777 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002778 did = ndlp->nlp_DID;
2779 cmd = ndlp->nlp_last_elscmd;
2780 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002781
2782 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002783 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002784 return;
2785 }
2786
2787 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002788 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002789 /*
2790 * If a discovery event readded nlp_delayfunc after timer
2791 * firing and before processing the timer, cancel the
2792 * nlp_delayfunc.
2793 */
2794 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002795 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002796 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002797
2798 switch (cmd) {
2799 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002800 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002801 break;
2802 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002803 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002804 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002805 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002806 }
dea31012005-04-17 16:05:31 -05002807 break;
2808 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002809 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002810 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002811 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002812 }
dea31012005-04-17 16:05:31 -05002813 break;
2814 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002815 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002816 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002817 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002818 }
dea31012005-04-17 16:05:31 -05002819 break;
2820 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002821 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002822 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002823 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002824 }
dea31012005-04-17 16:05:31 -05002825 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002826 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05002827 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
2828 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05002829 break;
dea31012005-04-17 16:05:31 -05002830 }
2831 return;
2832}
2833
James Smarte59058c2008-08-24 21:49:00 -04002834/**
James Smart3621a712009-04-06 18:47:14 -04002835 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002836 * @phba: pointer to lpfc hba data structure.
2837 * @cmdiocb: pointer to lpfc command iocb data structure.
2838 * @rspiocb: pointer to lpfc response iocb data structure.
2839 *
2840 * This routine makes a retry decision on an ELS command IOCB, which has
2841 * failed. The following ELS IOCBs use this function for retrying the command
2842 * when previously issued command responsed with error status: FLOGI, PLOGI,
2843 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2844 * returned error status, it makes the decision whether a retry shall be
2845 * issued for the command, and whether a retry shall be made immediately or
2846 * delayed. In the former case, the corresponding ELS command issuing-function
2847 * is called to retry the command. In the later case, the ELS command shall
2848 * be posted to the ndlp delayed event and delayed function timer set to the
2849 * ndlp for the delayed command issusing.
2850 *
2851 * Return code
2852 * 0 - No retry of els command is made
2853 * 1 - Immediate or delayed retry of els command is made
2854 **/
dea31012005-04-17 16:05:31 -05002855static int
James Smart2e0fef82007-06-17 19:56:36 -05002856lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2857 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002858{
James Smart2e0fef82007-06-17 19:56:36 -05002859 struct lpfc_vport *vport = cmdiocb->vport;
2860 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2861 IOCB_t *irsp = &rspiocb->iocb;
2862 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2863 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002864 uint32_t *elscmd;
2865 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002866 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002867 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002868 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002869 uint32_t did;
dea31012005-04-17 16:05:31 -05002870
James Smart488d1462006-03-07 15:02:37 -05002871
dea31012005-04-17 16:05:31 -05002872 /* Note: context2 may be 0 for internal driver abort
2873 * of delays ELS command.
2874 */
2875
2876 if (pcmd && pcmd->virt) {
2877 elscmd = (uint32_t *) (pcmd->virt);
2878 cmd = *elscmd++;
2879 }
2880
James Smarte47c9092008-02-08 18:49:26 -05002881 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002882 did = ndlp->nlp_DID;
2883 else {
2884 /* We should only hit this case for retrying PLOGI */
2885 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002886 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002887 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2888 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002889 return 1;
2890 }
2891
James Smart858c9f62007-06-17 19:56:39 -05002892 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2893 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2894 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2895
dea31012005-04-17 16:05:31 -05002896 switch (irsp->ulpStatus) {
2897 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05002898 break;
James Smart1151e3e2011-02-16 12:39:35 -05002899 case IOSTAT_REMOTE_STOP:
2900 if (phba->sli_rev == LPFC_SLI_REV4) {
2901 /* This IO was aborted by the target, we don't
2902 * know the rxid and because we did not send the
2903 * ABTS we cannot generate and RRQ.
2904 */
2905 lpfc_set_rrq_active(phba, ndlp,
2906 cmdiocb->sli4_xritag, 0, 0);
2907 }
2908 break;
dea31012005-04-17 16:05:31 -05002909 case IOSTAT_LOCAL_REJECT:
2910 switch ((irsp->un.ulpWord[4] & 0xff)) {
2911 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002912 if (cmd == ELS_CMD_FLOGI) {
2913 if (PCI_DEVICE_ID_HORNET ==
2914 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05002915 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05002916 phba->pport->fc_myDID = 0;
2917 phba->alpa_map[0] = 0;
2918 phba->alpa_map[1] = 0;
2919 }
2920 }
James Smart2e0fef82007-06-17 19:56:36 -05002921 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002922 delay = 1000;
dea31012005-04-17 16:05:31 -05002923 retry = 1;
2924 break;
2925
James Smart92d7f7b2007-06-17 19:56:38 -05002926 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002927 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2928 "0124 Retry illegal cmd x%x "
2929 "retry:x%x delay:x%x\n",
2930 cmd, cmdiocb->retry, delay);
2931 retry = 1;
2932 /* All command's retry policy */
2933 maxretry = 8;
2934 if (cmdiocb->retry > 2)
2935 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002936 break;
2937
dea31012005-04-17 16:05:31 -05002938 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002939 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002940 retry = 1;
2941 if (cmdiocb->retry > 100)
2942 delay = 100;
2943 maxretry = 250;
2944 break;
2945
2946 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002947 delay = 100;
dea31012005-04-17 16:05:31 -05002948 retry = 1;
2949 break;
2950
James Smart858c9f62007-06-17 19:56:39 -05002951 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002952 case IOERR_INVALID_RPI:
2953 retry = 1;
2954 break;
2955 }
2956 break;
2957
2958 case IOSTAT_NPORT_RJT:
2959 case IOSTAT_FABRIC_RJT:
2960 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2961 retry = 1;
2962 break;
2963 }
2964 break;
2965
2966 case IOSTAT_NPORT_BSY:
2967 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002968 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002969 retry = 1;
2970 break;
2971
2972 case IOSTAT_LS_RJT:
2973 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2974 /* Added for Vendor specifc support
2975 * Just keep retrying for these Rsn / Exp codes
2976 */
2977 switch (stat.un.b.lsRjtRsnCode) {
2978 case LSRJT_UNABLE_TPC:
2979 if (stat.un.b.lsRjtRsnCodeExp ==
2980 LSEXP_CMD_IN_PROGRESS) {
2981 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002982 delay = 1000;
dea31012005-04-17 16:05:31 -05002983 maxretry = 48;
2984 }
2985 retry = 1;
2986 break;
2987 }
James Smartffc95492010-06-07 15:23:17 -04002988 if (stat.un.b.lsRjtRsnCodeExp ==
2989 LSEXP_CANT_GIVE_DATA) {
2990 if (cmd == ELS_CMD_PLOGI) {
2991 delay = 1000;
2992 maxretry = 48;
2993 }
2994 retry = 1;
2995 break;
2996 }
dea31012005-04-17 16:05:31 -05002997 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002998 delay = 1000;
dea31012005-04-17 16:05:31 -05002999 maxretry = lpfc_max_els_tries + 1;
3000 retry = 1;
3001 break;
3002 }
James Smart92d7f7b2007-06-17 19:56:38 -05003003 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3004 (cmd == ELS_CMD_FDISC) &&
3005 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003006 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3007 "0125 FDISC Failed (x%x). "
3008 "Fabric out of resources\n",
3009 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003010 lpfc_vport_set_state(vport,
3011 FC_VPORT_NO_FABRIC_RSCS);
3012 }
dea31012005-04-17 16:05:31 -05003013 break;
3014
3015 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003016 if ((cmd == ELS_CMD_PLOGI) ||
3017 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003018 delay = 1000;
dea31012005-04-17 16:05:31 -05003019 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003020 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003021 /* FDISC retry policy */
3022 maxretry = 48;
3023 if (cmdiocb->retry >= 32)
3024 delay = 1000;
dea31012005-04-17 16:05:31 -05003025 }
3026 retry = 1;
3027 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003028
3029 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003030 /* There are some cases where switches return this
3031 * error when they are not ready and should be returning
3032 * Logical Busy. We should delay every time.
3033 */
3034 if (cmd == ELS_CMD_FDISC &&
3035 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3036 maxretry = 3;
3037 delay = 1000;
3038 retry = 1;
3039 break;
3040 }
James Smart92d7f7b2007-06-17 19:56:38 -05003041 case LSRJT_PROTOCOL_ERR:
3042 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3043 (cmd == ELS_CMD_FDISC) &&
3044 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3045 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3046 ) {
James Smarte8b62012007-08-02 11:10:09 -04003047 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003048 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003049 "Fabric Detected Bad WWN\n",
3050 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003051 lpfc_vport_set_state(vport,
3052 FC_VPORT_FABRIC_REJ_WWN);
3053 }
3054 break;
dea31012005-04-17 16:05:31 -05003055 }
3056 break;
3057
3058 case IOSTAT_INTERMED_RSP:
3059 case IOSTAT_BA_RJT:
3060 break;
3061
3062 default:
3063 break;
3064 }
3065
James Smart488d1462006-03-07 15:02:37 -05003066 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003067 retry = 1;
dea31012005-04-17 16:05:31 -05003068
James Smart695a8142010-01-26 23:08:03 -05003069 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart76a95d72010-11-20 23:11:48 -05003070 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003071 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003072 /* FLOGI retry policy */
3073 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04003074 /* retry forever */
3075 maxretry = 0;
3076 if (cmdiocb->retry >= 100)
3077 delay = 5000;
3078 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003079 delay = 1000;
3080 }
3081
James Smart6669f9b2009-10-02 15:16:45 -04003082 cmdiocb->retry++;
3083 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003084 phba->fc_stat.elsRetryExceeded++;
3085 retry = 0;
3086 }
3087
James Smarted957682007-06-17 19:56:37 -05003088 if ((vport->load_flag & FC_UNLOADING) != 0)
3089 retry = 0;
3090
dea31012005-04-17 16:05:31 -05003091 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003092 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3093 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3094 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3095 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3096 "2849 Stop retry ELS command "
3097 "x%x to remote NPORT x%x, "
3098 "Data: x%x x%x\n", cmd, did,
3099 cmdiocb->retry, delay);
3100 return 0;
3101 }
3102 }
dea31012005-04-17 16:05:31 -05003103
3104 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003105 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3106 "0107 Retry ELS command x%x to remote "
3107 "NPORT x%x Data: x%x x%x\n",
3108 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003109
James Smart858c9f62007-06-17 19:56:39 -05003110 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3111 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3112 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
3113 /* Don't reset timer for no resources */
3114
dea31012005-04-17 16:05:31 -05003115 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003116 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003117 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003118 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003119 }
3120
3121 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003122 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003123 phba->fc_stat.elsDelayRetry++;
3124 ndlp->nlp_retry = cmdiocb->retry;
3125
James Smart92d7f7b2007-06-17 19:56:38 -05003126 /* delay is specified in milliseconds */
3127 mod_timer(&ndlp->nlp_delayfunc,
3128 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003129 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003130 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003131 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003132
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003133 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003134 if (cmd == ELS_CMD_PRLI)
3135 lpfc_nlp_set_state(vport, ndlp,
3136 NLP_STE_REG_LOGIN_ISSUE);
3137 else
3138 lpfc_nlp_set_state(vport, ndlp,
3139 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003140 ndlp->nlp_last_elscmd = cmd;
3141
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003142 return 1;
dea31012005-04-17 16:05:31 -05003143 }
3144 switch (cmd) {
3145 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003146 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003147 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003148 case ELS_CMD_FDISC:
3149 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3150 return 1;
dea31012005-04-17 16:05:31 -05003151 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003152 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003153 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003154 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003155 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003156 }
James Smart2e0fef82007-06-17 19:56:36 -05003157 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003158 return 1;
dea31012005-04-17 16:05:31 -05003159 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003160 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003161 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3162 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003163 return 1;
dea31012005-04-17 16:05:31 -05003164 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003165 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003166 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3167 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003168 return 1;
dea31012005-04-17 16:05:31 -05003169 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003170 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003171 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3172 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003173 return 1;
dea31012005-04-17 16:05:31 -05003174 }
3175 }
dea31012005-04-17 16:05:31 -05003176 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003177 if (logerr) {
3178 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3179 "0137 No retry ELS command x%x to remote "
3180 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3181 cmd, did, irsp->ulpStatus,
3182 irsp->un.ulpWord[4]);
3183 }
3184 else {
3185 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003186 "0108 No retry ELS command x%x to remote "
3187 "NPORT x%x Retried:%d Error:x%x/%x\n",
3188 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3189 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003190 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003191 return 0;
dea31012005-04-17 16:05:31 -05003192}
3193
James Smarte59058c2008-08-24 21:49:00 -04003194/**
James Smart3621a712009-04-06 18:47:14 -04003195 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003196 * @phba: pointer to lpfc hba data structure.
3197 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3198 *
3199 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3200 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3201 * checks to see whether there is a lpfc DMA buffer associated with the
3202 * response of the command IOCB. If so, it will be released before releasing
3203 * the lpfc DMA buffer associated with the IOCB itself.
3204 *
3205 * Return code
3206 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3207 **/
James Smart09372822008-01-11 01:52:54 -05003208static int
James Smart87af33f2007-10-27 13:37:43 -04003209lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3210{
3211 struct lpfc_dmabuf *buf_ptr;
3212
James Smarte59058c2008-08-24 21:49:00 -04003213 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003214 if (!list_empty(&buf_ptr1->list)) {
3215 list_remove_head(&buf_ptr1->list, buf_ptr,
3216 struct lpfc_dmabuf,
3217 list);
3218 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3219 kfree(buf_ptr);
3220 }
3221 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3222 kfree(buf_ptr1);
3223 return 0;
3224}
3225
James Smarte59058c2008-08-24 21:49:00 -04003226/**
James Smart3621a712009-04-06 18:47:14 -04003227 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003228 * @phba: pointer to lpfc hba data structure.
3229 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3230 *
3231 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3232 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3233 * pool.
3234 *
3235 * Return code
3236 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3237 **/
James Smart09372822008-01-11 01:52:54 -05003238static int
James Smart87af33f2007-10-27 13:37:43 -04003239lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3240{
3241 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3242 kfree(buf_ptr);
3243 return 0;
3244}
3245
James Smarte59058c2008-08-24 21:49:00 -04003246/**
James Smart3621a712009-04-06 18:47:14 -04003247 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003248 * @phba: pointer to lpfc hba data structure.
3249 * @elsiocb: pointer to lpfc els command iocb data structure.
3250 *
3251 * This routine frees a command IOCB and its associated resources. The
3252 * command IOCB data structure contains the reference to various associated
3253 * resources, these fields must be set to NULL if the associated reference
3254 * not present:
3255 * context1 - reference to ndlp
3256 * context2 - reference to cmd
3257 * context2->next - reference to rsp
3258 * context3 - reference to bpl
3259 *
3260 * It first properly decrements the reference count held on ndlp for the
3261 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3262 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3263 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3264 * adds the DMA buffer the @phba data structure for the delayed release.
3265 * If reference to the Buffer Pointer List (BPL) is present, the
3266 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3267 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3268 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3269 *
3270 * Return code
3271 * 0 - Success (currently, always return 0)
3272 **/
James Smart87af33f2007-10-27 13:37:43 -04003273int
James Smart329f9bc2007-04-25 09:53:01 -04003274lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003275{
3276 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003277 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003278
James Smarta8adb832007-10-27 13:37:53 -04003279 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3280 if (ndlp) {
3281 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3282 lpfc_nlp_put(ndlp);
3283
3284 /* If the ndlp is not being used by another discovery
3285 * thread, free it.
3286 */
3287 if (!lpfc_nlp_not_used(ndlp)) {
3288 /* If ndlp is being used by another discovery
3289 * thread, just clear NLP_DEFER_RM
3290 */
3291 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3292 }
3293 }
3294 else
3295 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003296 elsiocb->context1 = NULL;
3297 }
dea31012005-04-17 16:05:31 -05003298 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3299 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003300 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3301 /* Firmware could still be in progress of DMAing
3302 * payload, so don't free data buffer till after
3303 * a hbeat.
3304 */
3305 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3306 buf_ptr = elsiocb->context2;
3307 elsiocb->context2 = NULL;
3308 if (buf_ptr) {
3309 buf_ptr1 = NULL;
3310 spin_lock_irq(&phba->hbalock);
3311 if (!list_empty(&buf_ptr->list)) {
3312 list_remove_head(&buf_ptr->list,
3313 buf_ptr1, struct lpfc_dmabuf,
3314 list);
3315 INIT_LIST_HEAD(&buf_ptr1->list);
3316 list_add_tail(&buf_ptr1->list,
3317 &phba->elsbuf);
3318 phba->elsbuf_cnt++;
3319 }
3320 INIT_LIST_HEAD(&buf_ptr->list);
3321 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3322 phba->elsbuf_cnt++;
3323 spin_unlock_irq(&phba->hbalock);
3324 }
3325 } else {
3326 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3327 lpfc_els_free_data(phba, buf_ptr1);
3328 }
dea31012005-04-17 16:05:31 -05003329 }
3330
3331 if (elsiocb->context3) {
3332 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003333 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003334 }
James Bottomley604a3e32005-10-29 10:28:33 -05003335 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003336 return 0;
3337}
3338
James Smarte59058c2008-08-24 21:49:00 -04003339/**
James Smart3621a712009-04-06 18:47:14 -04003340 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003341 * @phba: pointer to lpfc hba data structure.
3342 * @cmdiocb: pointer to lpfc command iocb data structure.
3343 * @rspiocb: pointer to lpfc response iocb data structure.
3344 *
3345 * This routine is the completion callback function to the Logout (LOGO)
3346 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3347 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3348 * release the ndlp if it has the last reference remaining (reference count
3349 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3350 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3351 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3352 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3353 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3354 * IOCB data structure.
3355 **/
dea31012005-04-17 16:05:31 -05003356static void
James Smart2e0fef82007-06-17 19:56:36 -05003357lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3358 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003359{
James Smart2e0fef82007-06-17 19:56:36 -05003360 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3361 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003362 IOCB_t *irsp;
3363
3364 irsp = &rspiocb->iocb;
3365 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3366 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3367 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003368 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003369 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3370 "0109 ACC to LOGO completes to NPort x%x "
3371 "Data: x%x x%x x%x\n",
3372 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3373 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003374
3375 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3376 /* NPort Recovery mode or node is just allocated */
3377 if (!lpfc_nlp_not_used(ndlp)) {
3378 /* If the ndlp is being used by another discovery
3379 * thread, just unregister the RPI.
3380 */
3381 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003382 } else {
3383 /* Indicate the node has already released, should
3384 * not reference to it from within lpfc_els_free_iocb.
3385 */
3386 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003387 }
dea31012005-04-17 16:05:31 -05003388 }
3389 lpfc_els_free_iocb(phba, cmdiocb);
3390 return;
3391}
3392
James Smarte59058c2008-08-24 21:49:00 -04003393/**
James Smart3621a712009-04-06 18:47:14 -04003394 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003395 * @phba: pointer to lpfc hba data structure.
3396 * @pmb: pointer to the driver internal queue element for mailbox command.
3397 *
3398 * This routine is the completion callback function for unregister default
3399 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3400 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3401 * decrements the ndlp reference count held for this completion callback
3402 * function. After that, it invokes the lpfc_nlp_not_used() to check
3403 * whether there is only one reference left on the ndlp. If so, it will
3404 * perform one more decrement and trigger the release of the ndlp.
3405 **/
James Smart858c9f62007-06-17 19:56:39 -05003406void
3407lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3408{
3409 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3410 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3411
3412 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003413 pmb->context2 = NULL;
3414
James Smart858c9f62007-06-17 19:56:39 -05003415 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3416 kfree(mp);
3417 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003418 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003419 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003420 /* This is the end of the default RPI cleanup logic for this
3421 * ndlp. If no other discovery threads are using this ndlp.
3422 * we should free all resources associated with it.
3423 */
3424 lpfc_nlp_not_used(ndlp);
3425 }
James Smart3772a992009-05-22 14:50:54 -04003426
James Smart858c9f62007-06-17 19:56:39 -05003427 return;
3428}
3429
James Smarte59058c2008-08-24 21:49:00 -04003430/**
James Smart3621a712009-04-06 18:47:14 -04003431 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003432 * @phba: pointer to lpfc hba data structure.
3433 * @cmdiocb: pointer to lpfc command iocb data structure.
3434 * @rspiocb: pointer to lpfc response iocb data structure.
3435 *
3436 * This routine is the completion callback function for ELS Response IOCB
3437 * command. In normal case, this callback function just properly sets the
3438 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3439 * field in the command IOCB is not NULL, the referred mailbox command will
3440 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3441 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3442 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3443 * routine shall be invoked trying to release the ndlp if no other threads
3444 * are currently referring it.
3445 **/
dea31012005-04-17 16:05:31 -05003446static void
James Smart858c9f62007-06-17 19:56:39 -05003447lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003448 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003449{
James Smart2e0fef82007-06-17 19:56:36 -05003450 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3451 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3452 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003453 IOCB_t *irsp;
3454 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003455 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003456 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003457 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003458
James Smart33ccf8d2006-08-17 11:57:58 -04003459 irsp = &rspiocb->iocb;
3460
dea31012005-04-17 16:05:31 -05003461 if (cmdiocb->context_un.mbox)
3462 mbox = cmdiocb->context_un.mbox;
3463
James Smartfa4066b2008-01-11 01:53:27 -05003464 /* First determine if this is a LS_RJT cmpl. Note, this callback
3465 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3466 */
James Smart87af33f2007-10-27 13:37:43 -04003467 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003468 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3469 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003470 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003471 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003472 */
3473 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3474 ls_rjt = 1;
3475 }
3476
dea31012005-04-17 16:05:31 -05003477 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003478 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003479 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003480 mp = (struct lpfc_dmabuf *) mbox->context1;
3481 if (mp) {
3482 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3483 kfree(mp);
3484 }
James Smart329f9bc2007-04-25 09:53:01 -04003485 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003486 }
James Smart58da1ff2008-04-07 10:15:56 -04003487 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3488 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003489 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003490 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003491 /* Indicate the node has already released,
3492 * should not reference to it from within
3493 * the routine lpfc_els_free_iocb.
3494 */
3495 cmdiocb->context1 = NULL;
3496 }
dea31012005-04-17 16:05:31 -05003497 goto out;
3498 }
3499
James Smart858c9f62007-06-17 19:56:39 -05003500 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003501 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003502 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003503 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003504 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003505 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3506 "0110 ELS response tag x%x completes "
3507 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3508 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3509 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3510 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3511 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003512 if (mbox) {
3513 if ((rspiocb->iocb.ulpStatus == 0)
3514 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003515 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003516 /* Increment reference count to ndlp to hold the
3517 * reference to ndlp for the callback function.
3518 */
James Smart329f9bc2007-04-25 09:53:01 -04003519 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003520 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003521 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3522 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3523 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3524 }
3525 else {
3526 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3527 ndlp->nlp_prev_state = ndlp->nlp_state;
3528 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003529 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003530 }
James Smart0b727fe2007-10-27 13:37:25 -04003531 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003532 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003533 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003534 else
3535 /* Decrement the ndlp reference count we
3536 * set for this failed mailbox command.
3537 */
3538 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003539
3540 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3541 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3542 "0138 ELS rsp: Cannot issue reg_login for x%x "
3543 "Data: x%x x%x x%x\n",
3544 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3545 ndlp->nlp_rpi);
3546
James Smartfa4066b2008-01-11 01:53:27 -05003547 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003548 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003549 /* Indicate node has already been released,
3550 * should not reference to it from within
3551 * the routine lpfc_els_free_iocb.
3552 */
3553 cmdiocb->context1 = NULL;
3554 }
dea31012005-04-17 16:05:31 -05003555 } else {
James Smart858c9f62007-06-17 19:56:39 -05003556 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3557 if (!lpfc_error_lost_link(irsp) &&
3558 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003559 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003560 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003561 /* Indicate node has already been
3562 * released, should not reference
3563 * to it from within the routine
3564 * lpfc_els_free_iocb.
3565 */
3566 cmdiocb->context1 = NULL;
3567 }
dea31012005-04-17 16:05:31 -05003568 }
3569 }
James Smart14691152006-12-02 13:34:28 -05003570 mp = (struct lpfc_dmabuf *) mbox->context1;
3571 if (mp) {
3572 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3573 kfree(mp);
3574 }
3575 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003576 }
3577out:
James Smart58da1ff2008-04-07 10:15:56 -04003578 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003579 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003580 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003581 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003582
3583 /* If the node is not being used by another discovery thread,
3584 * and we are sending a reject, we are done with it.
3585 * Release driver reference count here and free associated
3586 * resources.
3587 */
3588 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003589 if (lpfc_nlp_not_used(ndlp))
3590 /* Indicate node has already been released,
3591 * should not reference to it from within
3592 * the routine lpfc_els_free_iocb.
3593 */
3594 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003595 }
James Smart87af33f2007-10-27 13:37:43 -04003596
dea31012005-04-17 16:05:31 -05003597 lpfc_els_free_iocb(phba, cmdiocb);
3598 return;
3599}
3600
James Smarte59058c2008-08-24 21:49:00 -04003601/**
James Smart3621a712009-04-06 18:47:14 -04003602 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003603 * @vport: pointer to a host virtual N_Port data structure.
3604 * @flag: the els command code to be accepted.
3605 * @oldiocb: pointer to the original lpfc command iocb data structure.
3606 * @ndlp: pointer to a node-list data structure.
3607 * @mbox: pointer to the driver internal queue element for mailbox command.
3608 *
3609 * This routine prepares and issues an Accept (ACC) response IOCB
3610 * command. It uses the @flag to properly set up the IOCB field for the
3611 * specific ACC response command to be issued and invokes the
3612 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3613 * @mbox pointer is passed in, it will be put into the context_un.mbox
3614 * field of the IOCB for the completion callback function to issue the
3615 * mailbox command to the HBA later when callback is invoked.
3616 *
3617 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3618 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3619 * will be stored into the context1 field of the IOCB for the completion
3620 * callback function to the corresponding response ELS IOCB command.
3621 *
3622 * Return code
3623 * 0 - Successfully issued acc response
3624 * 1 - Failed to issue acc response
3625 **/
dea31012005-04-17 16:05:31 -05003626int
James Smart2e0fef82007-06-17 19:56:36 -05003627lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3628 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003629 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003630{
James Smart2e0fef82007-06-17 19:56:36 -05003631 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3632 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003633 IOCB_t *icmd;
3634 IOCB_t *oldcmd;
3635 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003636 struct lpfc_sli *psli;
3637 uint8_t *pcmd;
3638 uint16_t cmdsize;
3639 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003640 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003641
3642 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003643 oldcmd = &oldiocb->iocb;
3644
3645 switch (flag) {
3646 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003647 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003648 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3649 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003650 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003651 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003652 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003653 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003654 return 1;
dea31012005-04-17 16:05:31 -05003655 }
James Smart2e0fef82007-06-17 19:56:36 -05003656
dea31012005-04-17 16:05:31 -05003657 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003658 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3659 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003660 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3661 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003662 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003663
3664 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3665 "Issue ACC: did:x%x flg:x%x",
3666 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003667 break;
3668 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003669 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003670 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3671 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003672 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003673 return 1;
James Smart488d1462006-03-07 15:02:37 -05003674
dea31012005-04-17 16:05:31 -05003675 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003676 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3677 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003678 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3679
3680 if (mbox)
3681 elsiocb->context_un.mbox = mbox;
3682
3683 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003684 pcmd += sizeof(uint32_t);
3685 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003686
3687 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3688 "Issue ACC PLOGI: did:x%x flg:x%x",
3689 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003690 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003691 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003692 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003693 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003694 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3695 if (!elsiocb)
3696 return 1;
3697
3698 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003699 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3700 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04003701 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3702
3703 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003704 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003705 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3706 els_pkt_ptr = (ELS_PKT *) pcmd;
3707 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003708
3709 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3710 "Issue ACC PRLO: did:x%x flg:x%x",
3711 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003712 break;
dea31012005-04-17 16:05:31 -05003713 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003714 return 1;
dea31012005-04-17 16:05:31 -05003715 }
dea31012005-04-17 16:05:31 -05003716 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003717 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3718 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3719 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3720 elsiocb->iotag, elsiocb->iocb.ulpContext,
3721 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3722 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003723 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003724 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003725 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003726 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003727 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3728 } else {
James Smart858c9f62007-06-17 19:56:39 -05003729 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003730 }
3731
3732 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003733 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003734 if (rc == IOCB_ERROR) {
3735 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003736 return 1;
dea31012005-04-17 16:05:31 -05003737 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003738 return 0;
dea31012005-04-17 16:05:31 -05003739}
3740
James Smarte59058c2008-08-24 21:49:00 -04003741/**
James Smart3621a712009-04-06 18:47:14 -04003742 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003743 * @vport: pointer to a virtual N_Port data structure.
3744 * @rejectError:
3745 * @oldiocb: pointer to the original lpfc command iocb data structure.
3746 * @ndlp: pointer to a node-list data structure.
3747 * @mbox: pointer to the driver internal queue element for mailbox command.
3748 *
3749 * This routine prepares and issue an Reject (RJT) response IOCB
3750 * command. If a @mbox pointer is passed in, it will be put into the
3751 * context_un.mbox field of the IOCB for the completion callback function
3752 * to issue to the HBA later.
3753 *
3754 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3755 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3756 * will be stored into the context1 field of the IOCB for the completion
3757 * callback function to the reject response ELS IOCB command.
3758 *
3759 * Return code
3760 * 0 - Successfully issued reject response
3761 * 1 - Failed to issue reject response
3762 **/
dea31012005-04-17 16:05:31 -05003763int
James Smart2e0fef82007-06-17 19:56:36 -05003764lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003765 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3766 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003767{
James Smart2e0fef82007-06-17 19:56:36 -05003768 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003769 IOCB_t *icmd;
3770 IOCB_t *oldcmd;
3771 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003772 struct lpfc_sli *psli;
3773 uint8_t *pcmd;
3774 uint16_t cmdsize;
3775 int rc;
3776
3777 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003778 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003779 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3780 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003781 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003782 return 1;
dea31012005-04-17 16:05:31 -05003783
3784 icmd = &elsiocb->iocb;
3785 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003786 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3787 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003788 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3789
3790 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003791 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003792 *((uint32_t *) (pcmd)) = rejectError;
3793
James Smart51ef4c22007-08-02 11:10:31 -04003794 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003795 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003796
dea31012005-04-17 16:05:31 -05003797 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003798 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3799 "0129 Xmit ELS RJT x%x response tag x%x "
3800 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3801 "rpi x%x\n",
3802 rejectError, elsiocb->iotag,
3803 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3804 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003805 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3806 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3807 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3808
dea31012005-04-17 16:05:31 -05003809 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003810 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003811 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003812
dea31012005-04-17 16:05:31 -05003813 if (rc == IOCB_ERROR) {
3814 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003815 return 1;
dea31012005-04-17 16:05:31 -05003816 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003817 return 0;
dea31012005-04-17 16:05:31 -05003818}
3819
James Smarte59058c2008-08-24 21:49:00 -04003820/**
James Smart3621a712009-04-06 18:47:14 -04003821 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003822 * @vport: pointer to a virtual N_Port data structure.
3823 * @oldiocb: pointer to the original lpfc command iocb data structure.
3824 * @ndlp: pointer to a node-list data structure.
3825 *
3826 * This routine prepares and issues an Accept (ACC) response to Address
3827 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3828 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3829 *
3830 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3831 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3832 * will be stored into the context1 field of the IOCB for the completion
3833 * callback function to the ADISC Accept response ELS IOCB command.
3834 *
3835 * Return code
3836 * 0 - Successfully issued acc adisc response
3837 * 1 - Failed to issue adisc acc response
3838 **/
dea31012005-04-17 16:05:31 -05003839int
James Smart2e0fef82007-06-17 19:56:36 -05003840lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3841 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003842{
James Smart2e0fef82007-06-17 19:56:36 -05003843 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003844 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003845 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003846 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003847 uint8_t *pcmd;
3848 uint16_t cmdsize;
3849 int rc;
3850
James Smart92d7f7b2007-06-17 19:56:38 -05003851 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003852 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3853 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003854 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003855 return 1;
dea31012005-04-17 16:05:31 -05003856
dea31012005-04-17 16:05:31 -05003857 icmd = &elsiocb->iocb;
3858 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003859 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3860 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04003861
3862 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003863 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3864 "0130 Xmit ADISC ACC response iotag x%x xri: "
3865 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3866 elsiocb->iotag, elsiocb->iocb.ulpContext,
3867 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3868 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003869 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3870
3871 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003872 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003873
3874 ap = (ADISC *) (pcmd);
3875 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003876 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3877 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003878 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003879
James Smart858c9f62007-06-17 19:56:39 -05003880 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3881 "Issue ACC ADISC: did:x%x flg:x%x",
3882 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3883
dea31012005-04-17 16:05:31 -05003884 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003885 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003886 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003887 if (rc == IOCB_ERROR) {
3888 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003889 return 1;
dea31012005-04-17 16:05:31 -05003890 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003891 return 0;
dea31012005-04-17 16:05:31 -05003892}
3893
James Smarte59058c2008-08-24 21:49:00 -04003894/**
James Smart3621a712009-04-06 18:47:14 -04003895 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003896 * @vport: pointer to a virtual N_Port data structure.
3897 * @oldiocb: pointer to the original lpfc command iocb data structure.
3898 * @ndlp: pointer to a node-list data structure.
3899 *
3900 * This routine prepares and issues an Accept (ACC) response to Process
3901 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3902 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3903 *
3904 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3905 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3906 * will be stored into the context1 field of the IOCB for the completion
3907 * callback function to the PRLI Accept response ELS IOCB command.
3908 *
3909 * Return code
3910 * 0 - Successfully issued acc prli response
3911 * 1 - Failed to issue acc prli response
3912 **/
dea31012005-04-17 16:05:31 -05003913int
James Smart2e0fef82007-06-17 19:56:36 -05003914lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003915 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003916{
James Smart2e0fef82007-06-17 19:56:36 -05003917 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003918 PRLI *npr;
3919 lpfc_vpd_t *vpd;
3920 IOCB_t *icmd;
3921 IOCB_t *oldcmd;
3922 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003923 struct lpfc_sli *psli;
3924 uint8_t *pcmd;
3925 uint16_t cmdsize;
3926 int rc;
3927
3928 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003929
James Smart92d7f7b2007-06-17 19:56:38 -05003930 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003931 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003932 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003933 if (!elsiocb)
3934 return 1;
dea31012005-04-17 16:05:31 -05003935
dea31012005-04-17 16:05:31 -05003936 icmd = &elsiocb->iocb;
3937 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003938 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3939 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
3940
James Smart5b8bd0c2007-04-25 09:52:49 -04003941 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003942 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3943 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3944 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3945 elsiocb->iotag, elsiocb->iocb.ulpContext,
3946 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3947 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003948 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3949
3950 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003951 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003952
3953 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003954 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003955
3956 npr = (PRLI *) pcmd;
3957 vpd = &phba->vpd;
3958 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003959 * If the remote port is a target and our firmware version is 3.20 or
3960 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003961 */
James Smart0d2b6b82008-06-14 22:52:47 -04003962 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3963 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003964 npr->ConfmComplAllowed = 1;
3965 npr->Retry = 1;
3966 npr->TaskRetryIdReq = 1;
3967 }
3968
3969 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3970 npr->estabImagePair = 1;
3971 npr->readXferRdyDis = 1;
3972 npr->ConfmComplAllowed = 1;
3973
3974 npr->prliType = PRLI_FCP_TYPE;
3975 npr->initiatorFunc = 1;
3976
James Smart858c9f62007-06-17 19:56:39 -05003977 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3978 "Issue ACC PRLI: did:x%x flg:x%x",
3979 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3980
dea31012005-04-17 16:05:31 -05003981 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003982 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003983
James Smart3772a992009-05-22 14:50:54 -04003984 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003985 if (rc == IOCB_ERROR) {
3986 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003987 return 1;
dea31012005-04-17 16:05:31 -05003988 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003989 return 0;
dea31012005-04-17 16:05:31 -05003990}
3991
James Smarte59058c2008-08-24 21:49:00 -04003992/**
James Smart3621a712009-04-06 18:47:14 -04003993 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003994 * @vport: pointer to a virtual N_Port data structure.
3995 * @format: rnid command format.
3996 * @oldiocb: pointer to the original lpfc command iocb data structure.
3997 * @ndlp: pointer to a node-list data structure.
3998 *
3999 * This routine issues a Request Node Identification Data (RNID) Accept
4000 * (ACC) response. It constructs the RNID ACC response command according to
4001 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4002 * issue the response. Note that this command does not need to hold the ndlp
4003 * reference count for the callback. So, the ndlp reference count taken by
4004 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4005 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4006 * there is no ndlp reference available.
4007 *
4008 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4009 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4010 * will be stored into the context1 field of the IOCB for the completion
4011 * callback function. However, for the RNID Accept Response ELS command,
4012 * this is undone later by this routine after the IOCB is allocated.
4013 *
4014 * Return code
4015 * 0 - Successfully issued acc rnid response
4016 * 1 - Failed to issue acc rnid response
4017 **/
dea31012005-04-17 16:05:31 -05004018static int
James Smart2e0fef82007-06-17 19:56:36 -05004019lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004020 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004021{
James Smart2e0fef82007-06-17 19:56:36 -05004022 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004023 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004024 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004025 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004026 struct lpfc_sli *psli;
4027 uint8_t *pcmd;
4028 uint16_t cmdsize;
4029 int rc;
4030
4031 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004032 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4033 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004034 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004035 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004036
James Smart2e0fef82007-06-17 19:56:36 -05004037 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4038 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004039 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004040 return 1;
dea31012005-04-17 16:05:31 -05004041
dea31012005-04-17 16:05:31 -05004042 icmd = &elsiocb->iocb;
4043 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004044 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4045 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4046
James Smart5b8bd0c2007-04-25 09:52:49 -04004047 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004048 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4049 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4050 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004051 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004052 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004053 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004054
James Smart92d7f7b2007-06-17 19:56:38 -05004055 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004056 rn = (RNID *) (pcmd);
4057 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004058 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4059 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4060 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004061 switch (format) {
4062 case 0:
4063 rn->SpecificLen = 0;
4064 break;
4065 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004066 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004067 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004068 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004069 rn->un.topologyDisc.unitType = RNID_HBA;
4070 rn->un.topologyDisc.physPort = 0;
4071 rn->un.topologyDisc.attachedNodes = 0;
4072 break;
4073 default:
4074 rn->CommonLen = 0;
4075 rn->SpecificLen = 0;
4076 break;
4077 }
4078
James Smart858c9f62007-06-17 19:56:39 -05004079 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4080 "Issue ACC RNID: did:x%x flg:x%x",
4081 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4082
dea31012005-04-17 16:05:31 -05004083 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004084 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004085
James Smart3772a992009-05-22 14:50:54 -04004086 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004087 if (rc == IOCB_ERROR) {
4088 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004089 return 1;
dea31012005-04-17 16:05:31 -05004090 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004091 return 0;
dea31012005-04-17 16:05:31 -05004092}
4093
James Smarte59058c2008-08-24 21:49:00 -04004094/**
James Smart19ca7602010-11-20 23:11:55 -05004095 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4096 * @vport: pointer to a virtual N_Port data structure.
4097 * @iocb: pointer to the lpfc command iocb data structure.
4098 * @ndlp: pointer to a node-list data structure.
4099 *
4100 * Return
4101 **/
4102static void
4103lpfc_els_clear_rrq(struct lpfc_vport *vport,
4104 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4105{
4106 struct lpfc_hba *phba = vport->phba;
4107 uint8_t *pcmd;
4108 struct RRQ *rrq;
4109 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004110 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004111 struct lpfc_node_rrq *prrq;
4112
4113
4114 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4115 pcmd += sizeof(uint32_t);
4116 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004117 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b062011-04-16 11:03:17 -04004118 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004119
4120 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4121 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4122 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004123 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b062011-04-16 11:03:17 -04004124 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004125 rxid,
4126 iocb->iotag, iocb->iocb.ulpContext);
4127
4128 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4129 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4130 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004131 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b062011-04-16 11:03:17 -04004132 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004133 else
4134 xri = rxid;
4135 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004136 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004137 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004138 return;
4139}
4140
4141/**
James Smart12265f62010-10-22 11:05:53 -04004142 * lpfc_els_rsp_echo_acc - Issue echo acc response
4143 * @vport: pointer to a virtual N_Port data structure.
4144 * @data: pointer to echo data to return in the accept.
4145 * @oldiocb: pointer to the original lpfc command iocb data structure.
4146 * @ndlp: pointer to a node-list data structure.
4147 *
4148 * Return code
4149 * 0 - Successfully issued acc echo response
4150 * 1 - Failed to issue acc echo response
4151 **/
4152static int
4153lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4154 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4155{
4156 struct lpfc_hba *phba = vport->phba;
4157 struct lpfc_iocbq *elsiocb;
4158 struct lpfc_sli *psli;
4159 uint8_t *pcmd;
4160 uint16_t cmdsize;
4161 int rc;
4162
4163 psli = &phba->sli;
4164 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4165
James Smartbf086112011-08-21 21:48:13 -04004166 /* The accumulated length can exceed the BPL_SIZE. For
4167 * now, use this as the limit
4168 */
4169 if (cmdsize > LPFC_BPL_SIZE)
4170 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04004171 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4172 ndlp->nlp_DID, ELS_CMD_ACC);
4173 if (!elsiocb)
4174 return 1;
4175
James Smart7851fe22011-07-22 18:36:52 -04004176 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4177 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4178
James Smart12265f62010-10-22 11:05:53 -04004179 /* Xmit ECHO ACC response tag <ulpIoTag> */
4180 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4181 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4182 elsiocb->iotag, elsiocb->iocb.ulpContext);
4183 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4184 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4185 pcmd += sizeof(uint32_t);
4186 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4187
4188 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4189 "Issue ACC ECHO: did:x%x flg:x%x",
4190 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4191
4192 phba->fc_stat.elsXmitACC++;
4193 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04004194
4195 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4196 if (rc == IOCB_ERROR) {
4197 lpfc_els_free_iocb(phba, elsiocb);
4198 return 1;
4199 }
4200 return 0;
4201}
4202
4203/**
James Smart3621a712009-04-06 18:47:14 -04004204 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004205 * @vport: pointer to a host virtual N_Port data structure.
4206 *
4207 * This routine issues Address Discover (ADISC) ELS commands to those
4208 * N_Ports which are in node port recovery state and ADISC has not been issued
4209 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4210 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4211 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4212 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4213 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4214 * IOCBs quit for later pick up. On the other hand, after walking through
4215 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4216 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4217 * no more ADISC need to be sent.
4218 *
4219 * Return code
4220 * The number of N_Ports with adisc issued.
4221 **/
dea31012005-04-17 16:05:31 -05004222int
James Smart2e0fef82007-06-17 19:56:36 -05004223lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004224{
James Smart2e0fef82007-06-17 19:56:36 -05004225 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004226 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004227 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004228
James Smart685f0bf2007-04-25 09:53:08 -04004229 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004230 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004231 if (!NLP_CHK_NODE_ACT(ndlp))
4232 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004233 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4234 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4235 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004236 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004237 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004238 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004239 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004240 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4241 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004242 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004243 vport->num_disc_nodes++;
4244 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004245 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004246 spin_lock_irq(shost->host_lock);
4247 vport->fc_flag |= FC_NLP_MORE;
4248 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004249 break;
dea31012005-04-17 16:05:31 -05004250 }
4251 }
4252 }
4253 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004254 spin_lock_irq(shost->host_lock);
4255 vport->fc_flag &= ~FC_NLP_MORE;
4256 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004257 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004258 return sentadisc;
dea31012005-04-17 16:05:31 -05004259}
4260
James Smarte59058c2008-08-24 21:49:00 -04004261/**
James Smart3621a712009-04-06 18:47:14 -04004262 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004263 * @vport: pointer to a host virtual N_Port data structure.
4264 *
4265 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4266 * which are in node port recovery state, with a @vport. Each time an ELS
4267 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4268 * the per @vport number of discover count (num_disc_nodes) shall be
4269 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4270 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4271 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4272 * later pick up. On the other hand, after walking through all the ndlps with
4273 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4274 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4275 * PLOGI need to be sent.
4276 *
4277 * Return code
4278 * The number of N_Ports with plogi issued.
4279 **/
dea31012005-04-17 16:05:31 -05004280int
James Smart2e0fef82007-06-17 19:56:36 -05004281lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004282{
James Smart2e0fef82007-06-17 19:56:36 -05004283 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004284 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004285 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004286
James Smart2e0fef82007-06-17 19:56:36 -05004287 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4288 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004289 if (!NLP_CHK_NODE_ACT(ndlp))
4290 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004291 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4292 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4293 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4294 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4295 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004296 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4297 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004298 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004299 vport->num_disc_nodes++;
4300 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004301 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004302 spin_lock_irq(shost->host_lock);
4303 vport->fc_flag |= FC_NLP_MORE;
4304 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004305 break;
dea31012005-04-17 16:05:31 -05004306 }
4307 }
4308 }
James Smart87af33f2007-10-27 13:37:43 -04004309 if (sentplogi) {
4310 lpfc_set_disctmo(vport);
4311 }
4312 else {
James Smart2e0fef82007-06-17 19:56:36 -05004313 spin_lock_irq(shost->host_lock);
4314 vport->fc_flag &= ~FC_NLP_MORE;
4315 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004316 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004317 return sentplogi;
dea31012005-04-17 16:05:31 -05004318}
4319
James Smarte59058c2008-08-24 21:49:00 -04004320/**
James Smart3621a712009-04-06 18:47:14 -04004321 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004322 * @vport: pointer to a host virtual N_Port data structure.
4323 *
4324 * This routine cleans up any Registration State Change Notification
4325 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4326 * @vport together with the host_lock is used to prevent multiple thread
4327 * trying to access the RSCN array on a same @vport at the same time.
4328 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004329void
James Smart2e0fef82007-06-17 19:56:36 -05004330lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004331{
James Smart2e0fef82007-06-17 19:56:36 -05004332 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4333 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004334 int i;
4335
James Smart7f5f3d02008-02-08 18:50:14 -05004336 spin_lock_irq(shost->host_lock);
4337 if (vport->fc_rscn_flush) {
4338 /* Another thread is walking fc_rscn_id_list on this vport */
4339 spin_unlock_irq(shost->host_lock);
4340 return;
4341 }
4342 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4343 vport->fc_rscn_flush = 1;
4344 spin_unlock_irq(shost->host_lock);
4345
James Smart2e0fef82007-06-17 19:56:36 -05004346 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004347 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004348 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004349 }
James Smart2e0fef82007-06-17 19:56:36 -05004350 spin_lock_irq(shost->host_lock);
4351 vport->fc_rscn_id_cnt = 0;
4352 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4353 spin_unlock_irq(shost->host_lock);
4354 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004355 /* Indicate we are done walking this fc_rscn_id_list */
4356 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004357}
4358
James Smarte59058c2008-08-24 21:49:00 -04004359/**
James Smart3621a712009-04-06 18:47:14 -04004360 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004361 * @vport: pointer to a host virtual N_Port data structure.
4362 * @did: remote destination port identifier.
4363 *
4364 * This routine checks whether there is any pending Registration State
4365 * Configuration Notification (RSCN) to a @did on @vport.
4366 *
4367 * Return code
4368 * None zero - The @did matched with a pending rscn
4369 * 0 - not able to match @did with a pending rscn
4370 **/
dea31012005-04-17 16:05:31 -05004371int
James Smart2e0fef82007-06-17 19:56:36 -05004372lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004373{
4374 D_ID ns_did;
4375 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004376 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004377 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004378 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004379
4380 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004381
4382 /* Never match fabric nodes for RSCNs */
4383 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004384 return 0;
dea31012005-04-17 16:05:31 -05004385
4386 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004387 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004388 return did;
dea31012005-04-17 16:05:31 -05004389
James Smart7f5f3d02008-02-08 18:50:14 -05004390 spin_lock_irq(shost->host_lock);
4391 if (vport->fc_rscn_flush) {
4392 /* Another thread is walking fc_rscn_id_list on this vport */
4393 spin_unlock_irq(shost->host_lock);
4394 return 0;
4395 }
4396 /* Indicate we are walking fc_rscn_id_list on this vport */
4397 vport->fc_rscn_flush = 1;
4398 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004399 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004400 lp = vport->fc_rscn_id_list[i]->virt;
4401 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4402 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004403 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004404 rscn_did.un.word = be32_to_cpu(*lp++);
4405 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004406 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4407 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004408 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4409 && (ns_did.un.b.area == rscn_did.un.b.area)
4410 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004411 goto return_did_out;
dea31012005-04-17 16:05:31 -05004412 break;
James Smarteaf15d52008-12-04 22:39:29 -05004413 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004414 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4415 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004416 goto return_did_out;
dea31012005-04-17 16:05:31 -05004417 break;
James Smarteaf15d52008-12-04 22:39:29 -05004418 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004419 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004420 goto return_did_out;
dea31012005-04-17 16:05:31 -05004421 break;
James Smarteaf15d52008-12-04 22:39:29 -05004422 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004423 goto return_did_out;
dea31012005-04-17 16:05:31 -05004424 }
4425 }
James Smart92d7f7b2007-06-17 19:56:38 -05004426 }
James Smart7f5f3d02008-02-08 18:50:14 -05004427 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4428 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004429 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004430return_did_out:
4431 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4432 vport->fc_rscn_flush = 0;
4433 return did;
dea31012005-04-17 16:05:31 -05004434}
4435
James Smarte59058c2008-08-24 21:49:00 -04004436/**
James Smart3621a712009-04-06 18:47:14 -04004437 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004438 * @vport: pointer to a host virtual N_Port data structure.
4439 *
4440 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4441 * state machine for a @vport's nodes that are with pending RSCN (Registration
4442 * State Change Notification).
4443 *
4444 * Return code
4445 * 0 - Successful (currently alway return 0)
4446 **/
dea31012005-04-17 16:05:31 -05004447static int
James Smart2e0fef82007-06-17 19:56:36 -05004448lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004449{
James Smart685f0bf2007-04-25 09:53:08 -04004450 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004451
James Smart0d2b6b82008-06-14 22:52:47 -04004452 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004453 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004454 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004455 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4456 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004457 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004458 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004459 NLP_EVT_DEVICE_RECOVERY);
4460 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004461 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004462 return 0;
dea31012005-04-17 16:05:31 -05004463}
4464
James Smarte59058c2008-08-24 21:49:00 -04004465/**
James Smart3621a712009-04-06 18:47:14 -04004466 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004467 * @vport: pointer to a host virtual N_Port data structure.
4468 * @cmdiocb: pointer to lpfc command iocb data structure.
4469 *
4470 * lpfc_send_rscn_event sends an RSCN netlink event to management
4471 * applications.
4472 */
4473static void
4474lpfc_send_rscn_event(struct lpfc_vport *vport,
4475 struct lpfc_iocbq *cmdiocb)
4476{
4477 struct lpfc_dmabuf *pcmd;
4478 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4479 uint32_t *payload_ptr;
4480 uint32_t payload_len;
4481 struct lpfc_rscn_event_header *rscn_event_data;
4482
4483 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4484 payload_ptr = (uint32_t *) pcmd->virt;
4485 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4486
4487 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4488 payload_len, GFP_KERNEL);
4489 if (!rscn_event_data) {
4490 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4491 "0147 Failed to allocate memory for RSCN event\n");
4492 return;
4493 }
4494 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4495 rscn_event_data->payload_length = payload_len;
4496 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4497 payload_len);
4498
4499 fc_host_post_vendor_event(shost,
4500 fc_get_event_number(),
4501 sizeof(struct lpfc_els_event_header) + payload_len,
4502 (char *)rscn_event_data,
4503 LPFC_NL_VENDOR_ID);
4504
4505 kfree(rscn_event_data);
4506}
4507
4508/**
James Smart3621a712009-04-06 18:47:14 -04004509 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004510 * @vport: pointer to a host virtual N_Port data structure.
4511 * @cmdiocb: pointer to lpfc command iocb data structure.
4512 * @ndlp: pointer to a node-list data structure.
4513 *
4514 * This routine processes an unsolicited RSCN (Registration State Change
4515 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4516 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4517 * discover state machine is about to begin discovery, it just accepts the
4518 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4519 * contains N_Port IDs for other vports on this HBA, it just accepts the
4520 * RSCN and ignore processing it. If the state machine is in the recovery
4521 * state, the fc_rscn_id_list of this @vport is walked and the
4522 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4523 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4524 * routine is invoked to handle the RSCN event.
4525 *
4526 * Return code
4527 * 0 - Just sent the acc response
4528 * 1 - Sent the acc response and waited for name server completion
4529 **/
dea31012005-04-17 16:05:31 -05004530static int
James Smart2e0fef82007-06-17 19:56:36 -05004531lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004532 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004533{
James Smart2e0fef82007-06-17 19:56:36 -05004534 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4535 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004536 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004537 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004538 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004539 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004540 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004541 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004542 int i;
dea31012005-04-17 16:05:31 -05004543
4544 icmd = &cmdiocb->iocb;
4545 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4546 lp = (uint32_t *) pcmd->virt;
4547
James Smart92d7f7b2007-06-17 19:56:38 -05004548 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4549 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004550 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004551 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4552 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004553 vport->fc_flag, payload_len, *lp,
4554 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004555
4556 /* Send an RSCN event to the management application */
4557 lpfc_send_rscn_event(vport, cmdiocb);
4558
James Smartd2873e42006-08-18 17:46:43 -04004559 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004560 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004561 FCH_EVT_RSCN, lp[i]);
4562
dea31012005-04-17 16:05:31 -05004563 /* If we are about to begin discovery, just ACC the RSCN.
4564 * Discovery processing will satisfy it.
4565 */
James Smart2e0fef82007-06-17 19:56:36 -05004566 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004567 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4568 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4569 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4570
James Smart51ef4c22007-08-02 11:10:31 -04004571 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004572 return 0;
dea31012005-04-17 16:05:31 -05004573 }
4574
James Smart92d7f7b2007-06-17 19:56:38 -05004575 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4576 * just ACC and ignore it.
4577 */
4578 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004579 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004580 i = payload_len;
4581 datap = lp;
4582 while (i > 0) {
4583 nportid = *datap++;
4584 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4585 i -= sizeof(uint32_t);
4586 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004587 if (lpfc_find_vport_by_did(phba, nportid))
4588 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004589 }
4590 if (rscn_id == hba_id) {
4591 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004592 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004593 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004594 "Data: x%x x%x x%x x%x\n",
4595 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004596 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004597 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4598 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4599 ndlp->nlp_DID, vport->port_state,
4600 ndlp->nlp_flag);
4601
James Smart92d7f7b2007-06-17 19:56:38 -05004602 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004603 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004604 return 0;
4605 }
4606 }
4607
James Smart7f5f3d02008-02-08 18:50:14 -05004608 spin_lock_irq(shost->host_lock);
4609 if (vport->fc_rscn_flush) {
4610 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004611 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004612 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004613 /* Send back ACC */
4614 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004615 return 0;
4616 }
4617 /* Indicate we are walking fc_rscn_id_list on this vport */
4618 vport->fc_rscn_flush = 1;
4619 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004620 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004621 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004622 /* If we are already processing an RSCN, save the received
4623 * RSCN payload buffer, cmdiocb->context2 to process later.
4624 */
James Smart2e0fef82007-06-17 19:56:36 -05004625 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004626 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4627 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4628 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4629
James Smart09372822008-01-11 01:52:54 -05004630 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004631 vport->fc_flag |= FC_RSCN_DEFERRED;
4632 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004633 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004634 vport->fc_flag |= FC_RSCN_MODE;
4635 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004636 if (rscn_cnt) {
4637 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4638 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4639 }
4640 if ((rscn_cnt) &&
4641 (payload_len + length <= LPFC_BPL_SIZE)) {
4642 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004643 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004644 memcpy(((uint8_t *)cmd) + length, lp,
4645 payload_len);
4646 } else {
4647 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4648 vport->fc_rscn_id_cnt++;
4649 /* If we zero, cmdiocb->context2, the calling
4650 * routine will not try to free it.
4651 */
4652 cmdiocb->context2 = NULL;
4653 }
dea31012005-04-17 16:05:31 -05004654 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004655 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4656 "0235 Deferred RSCN "
4657 "Data: x%x x%x x%x\n",
4658 vport->fc_rscn_id_cnt, vport->fc_flag,
4659 vport->port_state);
dea31012005-04-17 16:05:31 -05004660 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004661 vport->fc_flag |= FC_RSCN_DISCOVERY;
4662 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004663 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004664 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4665 "0234 ReDiscovery RSCN "
4666 "Data: x%x x%x x%x\n",
4667 vport->fc_rscn_id_cnt, vport->fc_flag,
4668 vport->port_state);
dea31012005-04-17 16:05:31 -05004669 }
James Smart7f5f3d02008-02-08 18:50:14 -05004670 /* Indicate we are done walking fc_rscn_id_list on this vport */
4671 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004672 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004673 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004674 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004675 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004676 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004677 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004678 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004679 return 0;
dea31012005-04-17 16:05:31 -05004680 }
James Smart858c9f62007-06-17 19:56:39 -05004681 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4682 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4683 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4684
James Smart2e0fef82007-06-17 19:56:36 -05004685 spin_lock_irq(shost->host_lock);
4686 vport->fc_flag |= FC_RSCN_MODE;
4687 spin_unlock_irq(shost->host_lock);
4688 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
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 /*
4692 * If we zero, cmdiocb->context2, the calling routine will
4693 * not try to free it.
4694 */
4695 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004696 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004697 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004698 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004699 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004700 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004701 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004702}
4703
James Smarte59058c2008-08-24 21:49:00 -04004704/**
James Smart3621a712009-04-06 18:47:14 -04004705 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004706 * @vport: pointer to a host virtual N_Port data structure.
4707 *
4708 * This routine handles the Registration State Configuration Notification
4709 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4710 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4711 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4712 * NameServer shall be issued. If CT command to the NameServer fails to be
4713 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4714 * RSCN activities with the @vport.
4715 *
4716 * Return code
4717 * 0 - Cleaned up rscn on the @vport
4718 * 1 - Wait for plogi to name server before proceed
4719 **/
dea31012005-04-17 16:05:31 -05004720int
James Smart2e0fef82007-06-17 19:56:36 -05004721lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004722{
4723 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004724 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004725
James Smart92d7f7b2007-06-17 19:56:38 -05004726 /* Ignore RSCN if the port is being torn down. */
4727 if (vport->load_flag & FC_UNLOADING) {
4728 lpfc_els_flush_rscn(vport);
4729 return 0;
4730 }
4731
dea31012005-04-17 16:05:31 -05004732 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004733 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004734
4735 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004736 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4737 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4738 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4739 vport->port_state);
dea31012005-04-17 16:05:31 -05004740
4741 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004742 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004743 vport->num_disc_nodes = 0;
4744
James Smart2e0fef82007-06-17 19:56:36 -05004745 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004746 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4747 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004748 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004749 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004750 /* Wait for NameServer query cmpl before we can
4751 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004752 return 1;
dea31012005-04-17 16:05:31 -05004753 } else {
4754 /* If login to NameServer does not exist, issue one */
4755 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004756 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004757 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004758 /* Wait for NameServer login cmpl before we can
4759 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004760 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004761
James Smarte47c9092008-02-08 18:49:26 -05004762 if (ndlp) {
4763 ndlp = lpfc_enable_node(vport, ndlp,
4764 NLP_STE_PLOGI_ISSUE);
4765 if (!ndlp) {
4766 lpfc_els_flush_rscn(vport);
4767 return 0;
4768 }
4769 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004770 } else {
James Smarte47c9092008-02-08 18:49:26 -05004771 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4772 if (!ndlp) {
4773 lpfc_els_flush_rscn(vport);
4774 return 0;
4775 }
James Smart2e0fef82007-06-17 19:56:36 -05004776 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004777 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004778 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004779 }
James Smarte47c9092008-02-08 18:49:26 -05004780 ndlp->nlp_type |= NLP_FABRIC;
4781 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4782 /* Wait for NameServer login cmpl before we can
4783 * continue
4784 */
4785 return 1;
dea31012005-04-17 16:05:31 -05004786 }
4787
James Smart2e0fef82007-06-17 19:56:36 -05004788 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004789 return 0;
dea31012005-04-17 16:05:31 -05004790}
4791
James Smarte59058c2008-08-24 21:49:00 -04004792/**
James Smart3621a712009-04-06 18:47:14 -04004793 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004794 * @vport: pointer to a host virtual N_Port data structure.
4795 * @cmdiocb: pointer to lpfc command iocb data structure.
4796 * @ndlp: pointer to a node-list data structure.
4797 *
4798 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4799 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4800 * point topology. As an unsolicited FLOGI should not be received in a loop
4801 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4802 * lpfc_check_sparm() routine is invoked to check the parameters in the
4803 * unsolicited FLOGI. If parameters validation failed, the routine
4804 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4805 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4806 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4807 * will initiate PLOGI. The higher lexicographical value party shall has
4808 * higher priority (as the winning port) and will initiate PLOGI and
4809 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4810 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4811 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4812 *
4813 * Return code
4814 * 0 - Successfully processed the unsolicited flogi
4815 * 1 - Failed to process the unsolicited flogi
4816 **/
dea31012005-04-17 16:05:31 -05004817static int
James Smart2e0fef82007-06-17 19:56:36 -05004818lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004819 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004820{
James Smart2e0fef82007-06-17 19:56:36 -05004821 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4822 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004823 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4824 uint32_t *lp = (uint32_t *) pcmd->virt;
4825 IOCB_t *icmd = &cmdiocb->iocb;
4826 struct serv_parm *sp;
4827 LPFC_MBOXQ_t *mbox;
4828 struct ls_rjt stat;
4829 uint32_t cmd, did;
4830 int rc;
4831
4832 cmd = *lp++;
4833 sp = (struct serv_parm *) lp;
4834
4835 /* FLOGI received */
4836
James Smart2e0fef82007-06-17 19:56:36 -05004837 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004838
James Smart76a95d72010-11-20 23:11:48 -05004839 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004840 /* We should never receive a FLOGI in loop mode, ignore it */
4841 did = icmd->un.elsreq64.remoteID;
4842
4843 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4844 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004845 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4846 "0113 An FLOGI ELS command x%x was "
4847 "received from DID x%x in Loop Mode\n",
4848 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004849 return 1;
dea31012005-04-17 16:05:31 -05004850 }
4851
4852 did = Fabric_DID;
4853
James Smart341af102010-01-26 23:07:37 -05004854 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004855 /* For a FLOGI we accept, then if our portname is greater
4856 * then the remote portname we initiate Nport login.
4857 */
4858
James Smart2e0fef82007-06-17 19:56:36 -05004859 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004860 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004861
4862 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004863 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4864 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004865 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004866
dea31012005-04-17 16:05:31 -05004867 lpfc_linkdown(phba);
4868 lpfc_init_link(phba, mbox,
4869 phba->cfg_topology,
4870 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004871 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004872 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004873 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004874 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004875 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004876 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004877 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004878 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004879 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004880 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004881 spin_lock_irq(shost->host_lock);
4882 vport->fc_flag |= FC_PT2PT_PLOGI;
4883 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004884 }
James Smart2e0fef82007-06-17 19:56:36 -05004885 spin_lock_irq(shost->host_lock);
4886 vport->fc_flag |= FC_PT2PT;
4887 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4888 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004889 } else {
4890 /* Reject this request because invalid parameters */
4891 stat.un.b.lsRjtRsvd0 = 0;
4892 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4893 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4894 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004895 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4896 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004897 return 1;
dea31012005-04-17 16:05:31 -05004898 }
4899
4900 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004901 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004902
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004903 return 0;
dea31012005-04-17 16:05:31 -05004904}
4905
James Smarte59058c2008-08-24 21:49:00 -04004906/**
James Smart3621a712009-04-06 18:47:14 -04004907 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004908 * @vport: pointer to a host virtual N_Port data structure.
4909 * @cmdiocb: pointer to lpfc command iocb data structure.
4910 * @ndlp: pointer to a node-list data structure.
4911 *
4912 * This routine processes Request Node Identification Data (RNID) IOCB
4913 * received as an ELS unsolicited event. Only when the RNID specified format
4914 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4915 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4916 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4917 * rejected by invoking the lpfc_els_rsp_reject() routine.
4918 *
4919 * Return code
4920 * 0 - Successfully processed rnid iocb (currently always return 0)
4921 **/
dea31012005-04-17 16:05:31 -05004922static int
James Smart2e0fef82007-06-17 19:56:36 -05004923lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4924 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004925{
4926 struct lpfc_dmabuf *pcmd;
4927 uint32_t *lp;
4928 IOCB_t *icmd;
4929 RNID *rn;
4930 struct ls_rjt stat;
4931 uint32_t cmd, did;
4932
4933 icmd = &cmdiocb->iocb;
4934 did = icmd->un.elsreq64.remoteID;
4935 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4936 lp = (uint32_t *) pcmd->virt;
4937
4938 cmd = *lp++;
4939 rn = (RNID *) lp;
4940
4941 /* RNID received */
4942
4943 switch (rn->Format) {
4944 case 0:
4945 case RNID_TOPOLOGY_DISC:
4946 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004947 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004948 break;
4949 default:
4950 /* Reject this request because format not supported */
4951 stat.un.b.lsRjtRsvd0 = 0;
4952 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4953 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4954 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004955 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4956 NULL);
dea31012005-04-17 16:05:31 -05004957 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004958 return 0;
dea31012005-04-17 16:05:31 -05004959}
4960
James Smarte59058c2008-08-24 21:49:00 -04004961/**
James Smart12265f62010-10-22 11:05:53 -04004962 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4963 * @vport: pointer to a host virtual N_Port data structure.
4964 * @cmdiocb: pointer to lpfc command iocb data structure.
4965 * @ndlp: pointer to a node-list data structure.
4966 *
4967 * Return code
4968 * 0 - Successfully processed echo iocb (currently always return 0)
4969 **/
4970static int
4971lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4972 struct lpfc_nodelist *ndlp)
4973{
4974 uint8_t *pcmd;
4975
4976 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4977
4978 /* skip over first word of echo command to find echo data */
4979 pcmd += sizeof(uint32_t);
4980
4981 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
4982 return 0;
4983}
4984
4985/**
James Smart3621a712009-04-06 18:47:14 -04004986 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004987 * @vport: pointer to a host virtual N_Port data structure.
4988 * @cmdiocb: pointer to lpfc command iocb data structure.
4989 * @ndlp: pointer to a node-list data structure.
4990 *
4991 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4992 * received as an ELS unsolicited event. Currently, this function just invokes
4993 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4994 *
4995 * Return code
4996 * 0 - Successfully processed lirr iocb (currently always return 0)
4997 **/
dea31012005-04-17 16:05:31 -05004998static int
James Smart2e0fef82007-06-17 19:56:36 -05004999lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5000 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005001{
5002 struct ls_rjt stat;
5003
5004 /* For now, unconditionally reject this command */
5005 stat.un.b.lsRjtRsvd0 = 0;
5006 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5007 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5008 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005009 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005010 return 0;
5011}
5012
James Smarte59058c2008-08-24 21:49:00 -04005013/**
James Smart5ffc2662009-11-18 15:39:44 -05005014 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5015 * @vport: pointer to a host virtual N_Port data structure.
5016 * @cmdiocb: pointer to lpfc command iocb data structure.
5017 * @ndlp: pointer to a node-list data structure.
5018 *
5019 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5020 * received as an ELS unsolicited event. A request to RRQ shall only
5021 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5022 * Nx_Port N_Port_ID of the target Exchange is the same as the
5023 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5024 * not accepted, an LS_RJT with reason code "Unable to perform
5025 * command request" and reason code explanation "Invalid Originator
5026 * S_ID" shall be returned. For now, we just unconditionally accept
5027 * RRQ from the target.
5028 **/
5029static void
5030lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5031 struct lpfc_nodelist *ndlp)
5032{
5033 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05005034 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5035 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05005036}
5037
5038/**
James Smart12265f62010-10-22 11:05:53 -04005039 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5040 * @phba: pointer to lpfc hba data structure.
5041 * @pmb: pointer to the driver internal queue element for mailbox command.
5042 *
5043 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5044 * mailbox command. This callback function is to actually send the Accept
5045 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5046 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5047 * mailbox command, constructs the RPS response with the link statistics
5048 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5049 * response to the RPS.
5050 *
5051 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5052 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5053 * will be stored into the context1 field of the IOCB for the completion
5054 * callback function to the RPS Accept Response ELS IOCB command.
5055 *
5056 **/
5057static void
5058lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5059{
5060 MAILBOX_t *mb;
5061 IOCB_t *icmd;
5062 struct RLS_RSP *rls_rsp;
5063 uint8_t *pcmd;
5064 struct lpfc_iocbq *elsiocb;
5065 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005066 uint16_t oxid;
5067 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04005068 uint32_t cmdsize;
5069
5070 mb = &pmb->u.mb;
5071
5072 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005073 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5074 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04005075 pmb->context1 = NULL;
5076 pmb->context2 = NULL;
5077
5078 if (mb->mbxStatus) {
5079 mempool_free(pmb, phba->mbox_mem_pool);
5080 return;
5081 }
5082
5083 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
5084 mempool_free(pmb, phba->mbox_mem_pool);
5085 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5086 lpfc_max_els_tries, ndlp,
5087 ndlp->nlp_DID, ELS_CMD_ACC);
5088
5089 /* Decrement the ndlp reference count from previous mbox command */
5090 lpfc_nlp_put(ndlp);
5091
5092 if (!elsiocb)
5093 return;
5094
5095 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005096 icmd->ulpContext = rxid;
5097 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04005098
5099 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5100 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5101 pcmd += sizeof(uint32_t); /* Skip past command */
5102 rls_rsp = (struct RLS_RSP *)pcmd;
5103
5104 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5105 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5106 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5107 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5108 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5109 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
5110
5111 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5112 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5113 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5114 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5115 elsiocb->iotag, elsiocb->iocb.ulpContext,
5116 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5117 ndlp->nlp_rpi);
5118 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5119 phba->fc_stat.elsXmitACC++;
5120 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5121 lpfc_els_free_iocb(phba, elsiocb);
5122}
5123
5124/**
James Smart3621a712009-04-06 18:47:14 -04005125 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005126 * @phba: pointer to lpfc hba data structure.
5127 * @pmb: pointer to the driver internal queue element for mailbox command.
5128 *
5129 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5130 * mailbox command. This callback function is to actually send the Accept
5131 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5132 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5133 * mailbox command, constructs the RPS response with the link statistics
5134 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5135 * response to the RPS.
5136 *
5137 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5138 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5139 * will be stored into the context1 field of the IOCB for the completion
5140 * callback function to the RPS Accept Response ELS IOCB command.
5141 *
5142 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005143static void
James Smart329f9bc2007-04-25 09:53:01 -04005144lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005145{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005146 MAILBOX_t *mb;
5147 IOCB_t *icmd;
5148 RPS_RSP *rps_rsp;
5149 uint8_t *pcmd;
5150 struct lpfc_iocbq *elsiocb;
5151 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005152 uint16_t status;
5153 uint16_t oxid;
5154 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005155 uint32_t cmdsize;
5156
James Smart04c68492009-05-22 14:52:52 -04005157 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005158
5159 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005160 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5161 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07005162 pmb->context1 = NULL;
5163 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005164
5165 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005166 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005167 return;
5168 }
5169
5170 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005171 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005172 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5173 lpfc_max_els_tries, ndlp,
5174 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005175
5176 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005177 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005178
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005179 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005180 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005181
5182 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005183 icmd->ulpContext = rxid;
5184 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005185
5186 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5187 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005188 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005189 rps_rsp = (RPS_RSP *)pcmd;
5190
James Smart76a95d72010-11-20 23:11:48 -05005191 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005192 status = 0x10;
5193 else
5194 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005195 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005196 status |= 0x4;
5197
5198 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005199 rps_rsp->portStatus = cpu_to_be16(status);
5200 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5201 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5202 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5203 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5204 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5205 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005206 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005207 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5208 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5209 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5210 elsiocb->iotag, elsiocb->iocb.ulpContext,
5211 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5212 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005213 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005214 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005215 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005216 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005217 return;
5218}
5219
James Smarte59058c2008-08-24 21:49:00 -04005220/**
James Smart12265f62010-10-22 11:05:53 -04005221 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5222 * @vport: pointer to a host virtual N_Port data structure.
5223 * @cmdiocb: pointer to lpfc command iocb data structure.
5224 * @ndlp: pointer to a node-list data structure.
5225 *
5226 * This routine processes Read Port Status (RPL) IOCB received as an
5227 * ELS unsolicited event. It first checks the remote port state. If the
5228 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5229 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5230 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5231 * for reading the HBA link statistics. It is for the callback function,
5232 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5233 * to actually sending out RPL Accept (ACC) response.
5234 *
5235 * Return codes
5236 * 0 - Successfully processed rls iocb (currently always return 0)
5237 **/
5238static int
5239lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5240 struct lpfc_nodelist *ndlp)
5241{
5242 struct lpfc_hba *phba = vport->phba;
5243 LPFC_MBOXQ_t *mbox;
5244 struct lpfc_dmabuf *pcmd;
5245 struct ls_rjt stat;
5246
5247 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5248 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5249 /* reject the unsolicited RPS request and done with it */
5250 goto reject_out;
5251
5252 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5253
5254 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5255 if (mbox) {
5256 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005257 mbox->context1 = (void *)((unsigned long)
5258 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5259 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04005260 mbox->context2 = lpfc_nlp_get(ndlp);
5261 mbox->vport = vport;
5262 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5263 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5264 != MBX_NOT_FINISHED)
5265 /* Mbox completion will send ELS Response */
5266 return 0;
5267 /* Decrement reference count used for the failed mbox
5268 * command.
5269 */
5270 lpfc_nlp_put(ndlp);
5271 mempool_free(mbox, phba->mbox_mem_pool);
5272 }
5273reject_out:
5274 /* issue rejection response */
5275 stat.un.b.lsRjtRsvd0 = 0;
5276 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5277 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5278 stat.un.b.vendorUnique = 0;
5279 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5280 return 0;
5281}
5282
5283/**
5284 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5285 * @vport: pointer to a host virtual N_Port data structure.
5286 * @cmdiocb: pointer to lpfc command iocb data structure.
5287 * @ndlp: pointer to a node-list data structure.
5288 *
5289 * This routine processes Read Timout Value (RTV) IOCB received as an
5290 * ELS unsolicited event. It first checks the remote port state. If the
5291 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5292 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5293 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5294 * Value (RTV) unsolicited IOCB event.
5295 *
5296 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5297 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5298 * will be stored into the context1 field of the IOCB for the completion
5299 * callback function to the RPS Accept Response ELS IOCB command.
5300 *
5301 * Return codes
5302 * 0 - Successfully processed rtv iocb (currently always return 0)
5303 **/
5304static int
5305lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5306 struct lpfc_nodelist *ndlp)
5307{
5308 struct lpfc_hba *phba = vport->phba;
5309 struct ls_rjt stat;
5310 struct RTV_RSP *rtv_rsp;
5311 uint8_t *pcmd;
5312 struct lpfc_iocbq *elsiocb;
5313 uint32_t cmdsize;
5314
5315
5316 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5317 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5318 /* reject the unsolicited RPS request and done with it */
5319 goto reject_out;
5320
5321 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5322 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5323 lpfc_max_els_tries, ndlp,
5324 ndlp->nlp_DID, ELS_CMD_ACC);
5325
5326 if (!elsiocb)
5327 return 1;
5328
5329 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5330 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5331 pcmd += sizeof(uint32_t); /* Skip past command */
5332
5333 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04005334 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
5335 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04005336
5337 rtv_rsp = (struct RTV_RSP *)pcmd;
5338
5339 /* populate RTV payload */
5340 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5341 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5342 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5343 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5344 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5345
5346 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5347 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5348 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5349 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5350 "Data: x%x x%x x%x\n",
5351 elsiocb->iotag, elsiocb->iocb.ulpContext,
5352 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5353 ndlp->nlp_rpi,
5354 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5355 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5356 phba->fc_stat.elsXmitACC++;
5357 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5358 lpfc_els_free_iocb(phba, elsiocb);
5359 return 0;
5360
5361reject_out:
5362 /* issue rejection response */
5363 stat.un.b.lsRjtRsvd0 = 0;
5364 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5365 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5366 stat.un.b.vendorUnique = 0;
5367 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5368 return 0;
5369}
5370
5371/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005372 * @vport: pointer to a host virtual N_Port data structure.
5373 * @cmdiocb: pointer to lpfc command iocb data structure.
5374 * @ndlp: pointer to a node-list data structure.
5375 *
5376 * This routine processes Read Port Status (RPS) IOCB received as an
5377 * ELS unsolicited event. It first checks the remote port state. If the
5378 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5379 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5380 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5381 * for reading the HBA link statistics. It is for the callback function,
5382 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5383 * to actually sending out RPS Accept (ACC) response.
5384 *
5385 * Return codes
5386 * 0 - Successfully processed rps iocb (currently always return 0)
5387 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005388static int
James Smart2e0fef82007-06-17 19:56:36 -05005389lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5390 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005391{
James Smart2e0fef82007-06-17 19:56:36 -05005392 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005393 uint32_t *lp;
5394 uint8_t flag;
5395 LPFC_MBOXQ_t *mbox;
5396 struct lpfc_dmabuf *pcmd;
5397 RPS *rps;
5398 struct ls_rjt stat;
5399
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005400 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005401 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5402 /* reject the unsolicited RPS request and done with it */
5403 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005404
5405 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5406 lp = (uint32_t *) pcmd->virt;
5407 flag = (be32_to_cpu(*lp++) & 0xf);
5408 rps = (RPS *) lp;
5409
5410 if ((flag == 0) ||
5411 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005412 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005413 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005414
James Smart92d7f7b2007-06-17 19:56:38 -05005415 printk("Fix me....\n");
5416 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005417 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5418 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005419 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005420 mbox->context1 = (void *)((unsigned long)
5421 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5422 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04005423 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005424 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005425 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005426 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005427 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005428 /* Mbox completion will send ELS Response */
5429 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005430 /* Decrement reference count used for the failed mbox
5431 * command.
5432 */
James Smart329f9bc2007-04-25 09:53:01 -04005433 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005434 mempool_free(mbox, phba->mbox_mem_pool);
5435 }
5436 }
James Smart90160e02008-08-24 21:49:45 -04005437
5438reject_out:
5439 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005440 stat.un.b.lsRjtRsvd0 = 0;
5441 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5442 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5443 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005444 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005445 return 0;
5446}
5447
James Smart19ca7602010-11-20 23:11:55 -05005448/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5449 * @vport: pointer to a host virtual N_Port data structure.
5450 * @ndlp: pointer to a node-list data structure.
5451 * @did: DID of the target.
5452 * @rrq: Pointer to the rrq struct.
5453 *
5454 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5455 * Successful the the completion handler will clear the RRQ.
5456 *
5457 * Return codes
5458 * 0 - Successfully sent rrq els iocb.
5459 * 1 - Failed to send rrq els iocb.
5460 **/
5461static int
5462lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5463 uint32_t did, struct lpfc_node_rrq *rrq)
5464{
5465 struct lpfc_hba *phba = vport->phba;
5466 struct RRQ *els_rrq;
5467 IOCB_t *icmd;
5468 struct lpfc_iocbq *elsiocb;
5469 uint8_t *pcmd;
5470 uint16_t cmdsize;
5471 int ret;
5472
5473
5474 if (ndlp != rrq->ndlp)
5475 ndlp = rrq->ndlp;
5476 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5477 return 1;
5478
5479 /* If ndlp is not NULL, we will bump the reference count on it */
5480 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5481 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5482 ELS_CMD_RRQ);
5483 if (!elsiocb)
5484 return 1;
5485
5486 icmd = &elsiocb->iocb;
5487 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5488
5489 /* For RRQ request, remainder of payload is Exchange IDs */
5490 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5491 pcmd += sizeof(uint32_t);
5492 els_rrq = (struct RRQ *) pcmd;
5493
5494 bf_set(rrq_oxid, els_rrq, rrq->xritag);
5495 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5496 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5497 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5498 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5499
5500
5501 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5502 "Issue RRQ: did:x%x",
5503 did, rrq->xritag, rrq->rxid);
5504 elsiocb->context_un.rrq = rrq;
5505 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5506 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5507
5508 if (ret == IOCB_ERROR) {
5509 lpfc_els_free_iocb(phba, elsiocb);
5510 return 1;
5511 }
5512 return 0;
5513}
5514
5515/**
5516 * lpfc_send_rrq - Sends ELS RRQ if needed.
5517 * @phba: pointer to lpfc hba data structure.
5518 * @rrq: pointer to the active rrq.
5519 *
5520 * This routine will call the lpfc_issue_els_rrq if the rrq is
5521 * still active for the xri. If this function returns a failure then
5522 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5523 *
5524 * Returns 0 Success.
5525 * 1 Failure.
5526 **/
5527int
5528lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5529{
5530 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5531 rrq->nlp_DID);
5532 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5533 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5534 rrq->nlp_DID, rrq);
5535 else
5536 return 1;
5537}
5538
James Smarte59058c2008-08-24 21:49:00 -04005539/**
James Smart3621a712009-04-06 18:47:14 -04005540 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005541 * @vport: pointer to a host virtual N_Port data structure.
5542 * @cmdsize: size of the ELS command.
5543 * @oldiocb: pointer to the original lpfc command iocb data structure.
5544 * @ndlp: pointer to a node-list data structure.
5545 *
5546 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5547 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5548 *
5549 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5550 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5551 * will be stored into the context1 field of the IOCB for the completion
5552 * callback function to the RPL Accept Response ELS command.
5553 *
5554 * Return code
5555 * 0 - Successfully issued ACC RPL ELS command
5556 * 1 - Failed to issue ACC RPL ELS command
5557 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005558static int
James Smart2e0fef82007-06-17 19:56:36 -05005559lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5560 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005561{
James Smart2e0fef82007-06-17 19:56:36 -05005562 struct lpfc_hba *phba = vport->phba;
5563 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005564 RPL_RSP rpl_rsp;
5565 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005566 uint8_t *pcmd;
5567
James Smart2e0fef82007-06-17 19:56:36 -05005568 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5569 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005570
James Smart488d1462006-03-07 15:02:37 -05005571 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005572 return 1;
James Smart488d1462006-03-07 15:02:37 -05005573
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005574 icmd = &elsiocb->iocb;
5575 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005576 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5577 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005578
5579 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5580 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005581 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005582 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5583 pcmd += sizeof(uint16_t);
5584
5585 /* Setup the RPL ACC payload */
5586 rpl_rsp.listLen = be32_to_cpu(1);
5587 rpl_rsp.index = 0;
5588 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005589 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5590 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005591 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005592 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005593 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005594 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5595 "0120 Xmit ELS RPL ACC response tag x%x "
5596 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5597 "rpi x%x\n",
5598 elsiocb->iotag, elsiocb->iocb.ulpContext,
5599 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5600 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005601 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005602 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005603 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5604 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005605 lpfc_els_free_iocb(phba, elsiocb);
5606 return 1;
5607 }
5608 return 0;
5609}
5610
James Smarte59058c2008-08-24 21:49:00 -04005611/**
James Smart3621a712009-04-06 18:47:14 -04005612 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005613 * @vport: pointer to a host virtual N_Port data structure.
5614 * @cmdiocb: pointer to lpfc command iocb data structure.
5615 * @ndlp: pointer to a node-list data structure.
5616 *
5617 * This routine processes Read Port List (RPL) IOCB received as an ELS
5618 * unsolicited event. It first checks the remote port state. If the remote
5619 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5620 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5621 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5622 * to accept the RPL.
5623 *
5624 * Return code
5625 * 0 - Successfully processed rpl iocb (currently always return 0)
5626 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005627static int
James Smart2e0fef82007-06-17 19:56:36 -05005628lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5629 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005630{
5631 struct lpfc_dmabuf *pcmd;
5632 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005633 uint32_t maxsize;
5634 uint16_t cmdsize;
5635 RPL *rpl;
5636 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005637
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005638 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5639 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005640 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005641 stat.un.b.lsRjtRsvd0 = 0;
5642 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5643 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5644 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005645 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5646 NULL);
James Smart90160e02008-08-24 21:49:45 -04005647 /* rejected the unsolicited RPL request and done with it */
5648 return 0;
dea31012005-04-17 16:05:31 -05005649 }
5650
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005651 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5652 lp = (uint32_t *) pcmd->virt;
5653 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005654 maxsize = be32_to_cpu(rpl->maxsize);
5655
5656 /* We support only one port */
5657 if ((rpl->index == 0) &&
5658 ((maxsize == 0) ||
5659 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5660 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005661 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005662 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5663 }
James Smart2e0fef82007-06-17 19:56:36 -05005664 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005665
5666 return 0;
5667}
5668
James Smarte59058c2008-08-24 21:49:00 -04005669/**
James Smart3621a712009-04-06 18:47:14 -04005670 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005671 * @vport: pointer to a virtual N_Port data structure.
5672 * @cmdiocb: pointer to lpfc command iocb data structure.
5673 * @ndlp: pointer to a node-list data structure.
5674 *
5675 * This routine processes Fibre Channel Address Resolution Protocol
5676 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5677 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5678 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5679 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5680 * remote PortName is compared against the FC PortName stored in the @vport
5681 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5682 * compared against the FC NodeName stored in the @vport data structure.
5683 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5684 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5685 * invoked to send out FARP Response to the remote node. Before sending the
5686 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5687 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5688 * routine is invoked to log into the remote port first.
5689 *
5690 * Return code
5691 * 0 - Either the FARP Match Mode not supported or successfully processed
5692 **/
dea31012005-04-17 16:05:31 -05005693static int
James Smart2e0fef82007-06-17 19:56:36 -05005694lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5695 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005696{
5697 struct lpfc_dmabuf *pcmd;
5698 uint32_t *lp;
5699 IOCB_t *icmd;
5700 FARP *fp;
5701 uint32_t cmd, cnt, did;
5702
5703 icmd = &cmdiocb->iocb;
5704 did = icmd->un.elsreq64.remoteID;
5705 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5706 lp = (uint32_t *) pcmd->virt;
5707
5708 cmd = *lp++;
5709 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005710 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005711 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5712 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005713 /* We will only support match on WWPN or WWNN */
5714 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005715 return 0;
dea31012005-04-17 16:05:31 -05005716 }
5717
5718 cnt = 0;
5719 /* If this FARP command is searching for my portname */
5720 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005721 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005722 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005723 cnt = 1;
5724 }
5725
5726 /* If this FARP command is searching for my nodename */
5727 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005728 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005729 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005730 cnt = 1;
5731 }
5732
5733 if (cnt) {
5734 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5735 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5736 /* Log back into the node before sending the FARP. */
5737 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005738 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005739 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005740 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005741 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005742 }
5743
5744 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005745 if (fp->Rflags & FARP_REQUEST_FARPR)
5746 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005747 }
5748 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005749 return 0;
dea31012005-04-17 16:05:31 -05005750}
5751
James Smarte59058c2008-08-24 21:49:00 -04005752/**
James Smart3621a712009-04-06 18:47:14 -04005753 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005754 * @vport: pointer to a host virtual N_Port data structure.
5755 * @cmdiocb: pointer to lpfc command iocb data structure.
5756 * @ndlp: pointer to a node-list data structure.
5757 *
5758 * This routine processes Fibre Channel Address Resolution Protocol
5759 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5760 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5761 * the FARP response request.
5762 *
5763 * Return code
5764 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5765 **/
dea31012005-04-17 16:05:31 -05005766static int
James Smart2e0fef82007-06-17 19:56:36 -05005767lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5768 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005769{
5770 struct lpfc_dmabuf *pcmd;
5771 uint32_t *lp;
5772 IOCB_t *icmd;
5773 uint32_t cmd, did;
5774
5775 icmd = &cmdiocb->iocb;
5776 did = icmd->un.elsreq64.remoteID;
5777 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5778 lp = (uint32_t *) pcmd->virt;
5779
5780 cmd = *lp++;
5781 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005782 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5783 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005784 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005785 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005786
5787 return 0;
5788}
5789
James Smarte59058c2008-08-24 21:49:00 -04005790/**
James Smart3621a712009-04-06 18:47:14 -04005791 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005792 * @vport: pointer to a host virtual N_Port data structure.
5793 * @cmdiocb: pointer to lpfc command iocb data structure.
5794 * @fan_ndlp: pointer to a node-list data structure.
5795 *
5796 * This routine processes a Fabric Address Notification (FAN) IOCB
5797 * command received as an ELS unsolicited event. The FAN ELS command will
5798 * only be processed on a physical port (i.e., the @vport represents the
5799 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5800 * compared against those in the phba data structure. If any of those is
5801 * different, the lpfc_initial_flogi() routine is invoked to initialize
5802 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5803 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5804 * is invoked to register login to the fabric.
5805 *
5806 * Return code
5807 * 0 - Successfully processed fan iocb (currently always return 0).
5808 **/
dea31012005-04-17 16:05:31 -05005809static int
James Smart2e0fef82007-06-17 19:56:36 -05005810lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5811 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005812{
James Smart2e0fef82007-06-17 19:56:36 -05005813 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005814 uint32_t *lp;
5815 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005816
James Smart0d2b6b82008-06-14 22:52:47 -04005817 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5818 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5819 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005820 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005821 if ((vport == phba->pport) &&
5822 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005823 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005824 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005825 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005826 sizeof(struct lpfc_name)))) {
5827 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05005828 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005829 } else {
5830 /* FAN verified - skip FLOGI */
5831 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005832 if (phba->sli_rev < LPFC_SLI_REV4)
5833 lpfc_issue_fabric_reglogin(vport);
5834 else
5835 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005836 }
dea31012005-04-17 16:05:31 -05005837 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005838 return 0;
dea31012005-04-17 16:05:31 -05005839}
5840
James Smarte59058c2008-08-24 21:49:00 -04005841/**
James Smart3621a712009-04-06 18:47:14 -04005842 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005843 * @ptr: holder for the timer function associated data.
5844 *
5845 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5846 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5847 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5848 * up the worker thread. It is for the worker thread to invoke the routine
5849 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5850 **/
dea31012005-04-17 16:05:31 -05005851void
5852lpfc_els_timeout(unsigned long ptr)
5853{
James Smart2e0fef82007-06-17 19:56:36 -05005854 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5855 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005856 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005857 unsigned long iflag;
5858
James Smart2e0fef82007-06-17 19:56:36 -05005859 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005860 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5861 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005862 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005863 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005864
James Smart5e9d9b82008-06-14 22:52:53 -04005865 if (!tmo_posted)
5866 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005867 return;
5868}
5869
James Smart2a9bf3d2010-06-07 15:24:45 -04005870
James Smarte59058c2008-08-24 21:49:00 -04005871/**
James Smart3621a712009-04-06 18:47:14 -04005872 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005873 * @vport: pointer to a virtual N_Port data structure.
5874 *
5875 * This routine is the actual handler function that processes an ELS timeout
5876 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5877 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5878 * invoking the lpfc_sli_issue_abort_iotag() routine.
5879 **/
dea31012005-04-17 16:05:31 -05005880void
James Smart2e0fef82007-06-17 19:56:36 -05005881lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005882{
James Smart2e0fef82007-06-17 19:56:36 -05005883 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005884 struct lpfc_sli_ring *pring;
5885 struct lpfc_iocbq *tmp_iocb, *piocb;
5886 IOCB_t *cmd = NULL;
5887 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005888 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005889 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005890 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005891 LIST_HEAD(txcmplq_completions);
5892 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005893
James Smart2a9bf3d2010-06-07 15:24:45 -04005894
dea31012005-04-17 16:05:31 -05005895 timeout = (uint32_t)(phba->fc_ratov << 1);
5896
5897 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005898
James Smart2a9bf3d2010-06-07 15:24:45 -04005899 spin_lock_irq(&phba->hbalock);
5900 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5901 spin_unlock_irq(&phba->hbalock);
5902
5903 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005904 cmd = &piocb->iocb;
5905
James Smart2e0fef82007-06-17 19:56:36 -05005906 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5907 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5908 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005909 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005910
5911 if (piocb->vport != vport)
5912 continue;
5913
dea31012005-04-17 16:05:31 -05005914 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005915 if (pcmd)
5916 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005917
James Smart92d7f7b2007-06-17 19:56:38 -05005918 if (els_command == ELS_CMD_FARP ||
5919 els_command == ELS_CMD_FARPR ||
5920 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005921 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005922
dea31012005-04-17 16:05:31 -05005923 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005924 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005925 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005926 else
dea31012005-04-17 16:05:31 -05005927 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005928 continue;
5929 }
5930
James Smart2e0fef82007-06-17 19:56:36 -05005931 remote_ID = 0xffffffff;
5932 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005933 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005934 else {
5935 struct lpfc_nodelist *ndlp;
5936 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005937 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005938 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005939 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005940 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05005941 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005942 spin_lock_irq(&phba->hbalock);
5943 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05005944 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005945
James Smart2a9bf3d2010-06-07 15:24:45 -04005946 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5947 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5948 "0127 ELS timeout Data: x%x x%x x%x "
5949 "x%x\n", els_command,
5950 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5951 spin_lock_irq(&phba->hbalock);
5952 list_del_init(&piocb->dlist);
5953 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5954 spin_unlock_irq(&phba->hbalock);
5955 }
5956
James Smart2e0fef82007-06-17 19:56:36 -05005957 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5958 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005959}
5960
James Smarte59058c2008-08-24 21:49:00 -04005961/**
James Smart3621a712009-04-06 18:47:14 -04005962 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005963 * @vport: pointer to a host virtual N_Port data structure.
5964 *
5965 * This routine is used to clean up all the outstanding ELS commands on a
5966 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5967 * routine. After that, it walks the ELS transmit queue to remove all the
5968 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5969 * the IOCBs with a non-NULL completion callback function, the callback
5970 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5971 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5972 * callback function, the IOCB will simply be released. Finally, it walks
5973 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5974 * completion queue IOCB that is associated with the @vport and is not
5975 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5976 * part of the discovery state machine) out to HBA by invoking the
5977 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5978 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5979 * the IOCBs are aborted when this function returns.
5980 **/
dea31012005-04-17 16:05:31 -05005981void
James Smart2e0fef82007-06-17 19:56:36 -05005982lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005983{
James Smart2534ba72007-04-25 09:52:20 -04005984 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005985 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005986 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005987 struct lpfc_iocbq *tmp_iocb, *piocb;
5988 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005989
5990 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005991
James Smart2e0fef82007-06-17 19:56:36 -05005992 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005993 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5994 cmd = &piocb->iocb;
5995
5996 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5997 continue;
5998 }
5999
6000 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04006001 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6002 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6003 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6004 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05006005 continue;
dea31012005-04-17 16:05:31 -05006006
James Smart2e0fef82007-06-17 19:56:36 -05006007 if (piocb->vport != vport)
6008 continue;
6009
James Smart2534ba72007-04-25 09:52:20 -04006010 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04006011 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05006012 }
6013
6014 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05006015 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6016 continue;
6017 }
dea31012005-04-17 16:05:31 -05006018
James Smart2e0fef82007-06-17 19:56:36 -05006019 if (piocb->vport != vport)
6020 continue;
6021
James Smart07951072007-04-25 09:51:38 -04006022 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05006023 }
James Smart2e0fef82007-06-17 19:56:36 -05006024 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04006025
James Smarta257bf92009-04-06 18:48:10 -04006026 /* Cancell all the IOCBs from the completions list */
6027 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6028 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04006029
dea31012005-04-17 16:05:31 -05006030 return;
6031}
6032
James Smarte59058c2008-08-24 21:49:00 -04006033/**
James Smart3621a712009-04-06 18:47:14 -04006034 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04006035 * @phba: pointer to lpfc hba data structure.
6036 *
6037 * This routine is used to clean up all the outstanding ELS commands on a
6038 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6039 * routine. After that, it walks the ELS transmit queue to remove all the
6040 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6041 * the IOCBs with the completion callback function associated, the callback
6042 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6043 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6044 * callback function associated, the IOCB will simply be released. Finally,
6045 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6046 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6047 * management plane IOCBs that are not part of the discovery state machine)
6048 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6049 **/
James Smart549e55c2007-08-02 11:09:51 -04006050void
6051lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6052{
6053 LIST_HEAD(completions);
6054 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6055 struct lpfc_iocbq *tmp_iocb, *piocb;
6056 IOCB_t *cmd = NULL;
6057
6058 lpfc_fabric_abort_hba(phba);
6059 spin_lock_irq(&phba->hbalock);
6060 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6061 cmd = &piocb->iocb;
6062 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6063 continue;
6064 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6065 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6066 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6067 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6068 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6069 continue;
6070 list_move_tail(&piocb->list, &completions);
6071 pring->txq_cnt--;
6072 }
6073 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6074 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6075 continue;
6076 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6077 }
6078 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04006079
6080 /* Cancel all the IOCBs from the completions list */
6081 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6082 IOERR_SLI_ABORTED);
6083
James Smart549e55c2007-08-02 11:09:51 -04006084 return;
6085}
6086
James Smarte59058c2008-08-24 21:49:00 -04006087/**
James Smart3621a712009-04-06 18:47:14 -04006088 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04006089 * @phba: Pointer to hba context object.
6090 * @cmdiocbp: Pointer to command iocb which reported error.
6091 * @rspiocbp: Pointer to response iocb which reported error.
6092 *
6093 * This function sends an event when there is an ELS command
6094 * failure.
6095 **/
6096void
6097lpfc_send_els_failure_event(struct lpfc_hba *phba,
6098 struct lpfc_iocbq *cmdiocbp,
6099 struct lpfc_iocbq *rspiocbp)
6100{
6101 struct lpfc_vport *vport = cmdiocbp->vport;
6102 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6103 struct lpfc_lsrjt_event lsrjt_event;
6104 struct lpfc_fabric_event_header fabric_event;
6105 struct ls_rjt stat;
6106 struct lpfc_nodelist *ndlp;
6107 uint32_t *pcmd;
6108
6109 ndlp = cmdiocbp->context1;
6110 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6111 return;
6112
6113 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6114 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6115 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6116 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6117 sizeof(struct lpfc_name));
6118 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6119 sizeof(struct lpfc_name));
6120 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6121 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006122 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006123 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6124 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6125 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6126 fc_host_post_vendor_event(shost,
6127 fc_get_event_number(),
6128 sizeof(lsrjt_event),
6129 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006130 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006131 return;
6132 }
6133 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6134 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6135 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6136 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6137 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6138 else
6139 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6140 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6141 sizeof(struct lpfc_name));
6142 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6143 sizeof(struct lpfc_name));
6144 fc_host_post_vendor_event(shost,
6145 fc_get_event_number(),
6146 sizeof(fabric_event),
6147 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006148 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006149 return;
6150 }
6151
6152}
6153
6154/**
James Smart3621a712009-04-06 18:47:14 -04006155 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006156 * @vport: Pointer to vport object.
6157 * @ndlp: Pointer FC node object.
6158 * @cmd: ELS command code.
6159 *
6160 * This function posts an event when there is an incoming
6161 * unsolicited ELS command.
6162 **/
6163static void
6164lpfc_send_els_event(struct lpfc_vport *vport,
6165 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006166 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006167{
James Smartddcc50f2008-12-04 22:38:46 -05006168 struct lpfc_els_event_header *els_data = NULL;
6169 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006170 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6171
James Smartddcc50f2008-12-04 22:38:46 -05006172 if (*payload == ELS_CMD_LOGO) {
6173 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6174 if (!logo_data) {
6175 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6176 "0148 Failed to allocate memory "
6177 "for LOGO event\n");
6178 return;
6179 }
6180 els_data = &logo_data->header;
6181 } else {
6182 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6183 GFP_KERNEL);
6184 if (!els_data) {
6185 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6186 "0149 Failed to allocate memory "
6187 "for ELS event\n");
6188 return;
6189 }
6190 }
6191 els_data->event_type = FC_REG_ELS_EVENT;
6192 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006193 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006194 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006195 break;
6196 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006197 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006198 break;
6199 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006200 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6201 break;
6202 case ELS_CMD_LOGO:
6203 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6204 /* Copy the WWPN in the LOGO payload */
6205 memcpy(logo_data->logo_wwpn, &payload[2],
6206 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006207 break;
6208 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006209 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006210 return;
6211 }
James Smartddcc50f2008-12-04 22:38:46 -05006212 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6213 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6214 if (*payload == ELS_CMD_LOGO) {
6215 fc_host_post_vendor_event(shost,
6216 fc_get_event_number(),
6217 sizeof(struct lpfc_logo_event),
6218 (char *)logo_data,
6219 LPFC_NL_VENDOR_ID);
6220 kfree(logo_data);
6221 } else {
6222 fc_host_post_vendor_event(shost,
6223 fc_get_event_number(),
6224 sizeof(struct lpfc_els_event_header),
6225 (char *)els_data,
6226 LPFC_NL_VENDOR_ID);
6227 kfree(els_data);
6228 }
James Smartea2151b2008-09-07 11:52:10 -04006229
6230 return;
6231}
6232
6233
6234/**
James Smart3621a712009-04-06 18:47:14 -04006235 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006236 * @phba: pointer to lpfc hba data structure.
6237 * @pring: pointer to a SLI ring.
6238 * @vport: pointer to a host virtual N_Port data structure.
6239 * @elsiocb: pointer to lpfc els command iocb data structure.
6240 *
6241 * This routine is used for processing the IOCB associated with a unsolicited
6242 * event. It first determines whether there is an existing ndlp that matches
6243 * the DID from the unsolicited IOCB. If not, it will create a new one with
6244 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6245 * IOCB is then used to invoke the proper routine and to set up proper state
6246 * of the discovery state machine.
6247 **/
James Smarted957682007-06-17 19:56:37 -05006248static void
6249lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006250 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006251{
James Smart87af33f2007-10-27 13:37:43 -04006252 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006253 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006254 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006255 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05006256 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006257 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006258
James Smarte47c9092008-02-08 18:49:26 -05006259 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006260 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006261
dea31012005-04-17 16:05:31 -05006262 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006263 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6264 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006265 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006266 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006267
James Smart858c9f62007-06-17 19:56:39 -05006268 did = icmd->un.rcvels.remoteID;
6269 if (icmd->ulpStatus) {
6270 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6271 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6272 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006273 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006274 }
dea31012005-04-17 16:05:31 -05006275
6276 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006277 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006278 goto dropit;
dea31012005-04-17 16:05:31 -05006279
James Smartc8685952009-11-18 15:39:16 -05006280 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006281 if (vport->load_flag & FC_UNLOADING)
6282 goto dropit;
6283
James Smart92494142011-02-16 12:39:44 -05006284 /* If NPort discovery is delayed drop incoming ELS */
6285 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6286 (cmd != ELS_CMD_PLOGI))
6287 goto dropit;
6288
James Smart2e0fef82007-06-17 19:56:36 -05006289 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006290 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006291 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006292 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006293 if (!ndlp)
dea31012005-04-17 16:05:31 -05006294 goto dropit;
dea31012005-04-17 16:05:31 -05006295
James Smart2e0fef82007-06-17 19:56:36 -05006296 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006297 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006298 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006299 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006300 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006301 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6302 ndlp = lpfc_enable_node(vport, ndlp,
6303 NLP_STE_UNUSED_NODE);
6304 if (!ndlp)
6305 goto dropit;
6306 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6307 newnode = 1;
6308 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6309 ndlp->nlp_type |= NLP_FABRIC;
6310 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6311 /* This is similar to the new node path */
6312 ndlp = lpfc_nlp_get(ndlp);
6313 if (!ndlp)
6314 goto dropit;
6315 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6316 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006317 }
dea31012005-04-17 16:05:31 -05006318
6319 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006320
James Smart329f9bc2007-04-25 09:53:01 -04006321 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006322 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006323
6324 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6325 cmd &= ELS_CMD_MASK;
6326 }
6327 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006328 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6329 "0112 ELS command x%x received from NPORT x%x "
6330 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006331 switch (cmd) {
6332 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006333 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6334 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6335 did, vport->port_state, ndlp->nlp_flag);
6336
dea31012005-04-17 16:05:31 -05006337 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006338 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6339
James Smartddcc50f2008-12-04 22:38:46 -05006340 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05006341
6342 /* If Nport discovery is delayed, reject PLOGIs */
6343 if (vport->fc_flag & FC_DISC_DELAYED) {
6344 rjt_err = LSRJT_UNABLE_TPC;
6345 break;
6346 }
James Smart858c9f62007-06-17 19:56:39 -05006347 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006348 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6349 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6350 rjt_err = LSRJT_UNABLE_TPC;
6351 break;
6352 }
6353 /* We get here, and drop thru, if we are PT2PT with
6354 * another NPort and the other side has initiated
6355 * the PLOGI before responding to our FLOGI.
6356 */
dea31012005-04-17 16:05:31 -05006357 }
James Smart87af33f2007-10-27 13:37:43 -04006358
6359 shost = lpfc_shost_from_vport(vport);
6360 spin_lock_irq(shost->host_lock);
6361 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6362 spin_unlock_irq(shost->host_lock);
6363
James Smart2e0fef82007-06-17 19:56:36 -05006364 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6365 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006366
dea31012005-04-17 16:05:31 -05006367 break;
6368 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006369 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6370 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6371 did, vport->port_state, ndlp->nlp_flag);
6372
dea31012005-04-17 16:05:31 -05006373 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006374 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006375 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006376 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006377 break;
6378 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006379 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6380 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6381 did, vport->port_state, ndlp->nlp_flag);
6382
dea31012005-04-17 16:05:31 -05006383 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006384 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006385 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006386 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006387 break;
6388 }
James Smart2e0fef82007-06-17 19:56:36 -05006389 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006390 break;
6391 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006392 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6393 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6394 did, vport->port_state, ndlp->nlp_flag);
6395
dea31012005-04-17 16:05:31 -05006396 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006397 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006398 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006399 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006400 break;
6401 }
James Smart2e0fef82007-06-17 19:56:36 -05006402 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006403 break;
6404 case ELS_CMD_RSCN:
6405 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006406 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006407 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006408 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006409 break;
6410 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006411 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6412 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6413 did, vport->port_state, ndlp->nlp_flag);
6414
James Smartddcc50f2008-12-04 22:38:46 -05006415 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006416 phba->fc_stat.elsRcvADISC++;
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,
6422 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006423 break;
6424 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006425 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6426 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6427 did, vport->port_state, ndlp->nlp_flag);
6428
dea31012005-04-17 16:05:31 -05006429 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006430 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006431 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006432 break;
6433 }
James Smart2e0fef82007-06-17 19:56:36 -05006434 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6435 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006436 break;
6437 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006438 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6439 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6440 did, vport->port_state, ndlp->nlp_flag);
6441
dea31012005-04-17 16:05:31 -05006442 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006443 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006444 break;
6445 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006446 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6447 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6448 did, vport->port_state, ndlp->nlp_flag);
6449
dea31012005-04-17 16:05:31 -05006450 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006451 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006452 break;
6453 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006454 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6455 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6456 did, vport->port_state, ndlp->nlp_flag);
6457
dea31012005-04-17 16:05:31 -05006458 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006459 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006460 break;
dea31012005-04-17 16:05:31 -05006461 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006462 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6463 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6464 did, vport->port_state, ndlp->nlp_flag);
6465
dea31012005-04-17 16:05:31 -05006466 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006467 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006468 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006469 break;
6470 }
James Smart2e0fef82007-06-17 19:56:36 -05006471 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006472 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006473 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006474 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6475 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6476 did, vport->port_state, ndlp->nlp_flag);
6477
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006478 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006479 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006480 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006481 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006482 break;
James Smart12265f62010-10-22 11:05:53 -04006483 case ELS_CMD_RLS:
6484 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6485 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6486 did, vport->port_state, ndlp->nlp_flag);
6487
6488 phba->fc_stat.elsRcvRLS++;
6489 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6490 if (newnode)
6491 lpfc_nlp_put(ndlp);
6492 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006493 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006494 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6495 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6496 did, vport->port_state, ndlp->nlp_flag);
6497
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006498 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006499 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006500 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006501 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006502 break;
6503 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006504 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6505 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6506 did, vport->port_state, ndlp->nlp_flag);
6507
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006508 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006509 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006510 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006511 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006512 break;
dea31012005-04-17 16:05:31 -05006513 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006514 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6515 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6516 did, vport->port_state, ndlp->nlp_flag);
6517
dea31012005-04-17 16:05:31 -05006518 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006519 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006520 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006521 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006522 break;
James Smart12265f62010-10-22 11:05:53 -04006523 case ELS_CMD_RTV:
6524 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6525 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6526 did, vport->port_state, ndlp->nlp_flag);
6527 phba->fc_stat.elsRcvRTV++;
6528 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6529 if (newnode)
6530 lpfc_nlp_put(ndlp);
6531 break;
James Smart5ffc2662009-11-18 15:39:44 -05006532 case ELS_CMD_RRQ:
6533 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6534 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6535 did, vport->port_state, ndlp->nlp_flag);
6536
6537 phba->fc_stat.elsRcvRRQ++;
6538 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6539 if (newnode)
6540 lpfc_nlp_put(ndlp);
6541 break;
James Smart12265f62010-10-22 11:05:53 -04006542 case ELS_CMD_ECHO:
6543 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6544 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6545 did, vport->port_state, ndlp->nlp_flag);
6546
6547 phba->fc_stat.elsRcvECHO++;
6548 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6549 if (newnode)
6550 lpfc_nlp_put(ndlp);
6551 break;
dea31012005-04-17 16:05:31 -05006552 default:
James Smart858c9f62007-06-17 19:56:39 -05006553 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6554 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6555 cmd, did, vport->port_state);
6556
dea31012005-04-17 16:05:31 -05006557 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006558 rjt_err = LSRJT_CMD_UNSUPPORTED;
dea31012005-04-17 16:05:31 -05006559
6560 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006561 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6562 "0115 Unknown ELS command x%x "
6563 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006564 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006565 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006566 break;
6567 }
6568
6569 /* check if need to LS_RJT received ELS cmd */
6570 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006571 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006572 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006573 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006574 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6575 NULL);
dea31012005-04-17 16:05:31 -05006576 }
6577
James Smartd7c255b2008-08-24 21:50:00 -04006578 lpfc_nlp_put(elsiocb->context1);
6579 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006580 return;
6581
6582dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006583 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006584 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6585 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006586 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006587 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006588 phba->fc_stat.elsRcvDrop++;
6589}
6590
James Smarte59058c2008-08-24 21:49:00 -04006591/**
James Smart3621a712009-04-06 18:47:14 -04006592 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04006593 * @phba: pointer to lpfc hba data structure.
6594 * @vpi: host virtual N_Port identifier.
6595 *
6596 * This routine finds a vport on a HBA (referred by @phba) through a
6597 * @vpi. The function walks the HBA's vport list and returns the address
6598 * of the vport with the matching @vpi.
6599 *
6600 * Return code
6601 * NULL - No vport with the matching @vpi found
6602 * Otherwise - Address to the vport with the matching @vpi.
6603 **/
James Smart6669f9b2009-10-02 15:16:45 -04006604struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05006605lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6606{
6607 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04006608 unsigned long flags;
James Smart5248a742011-07-22 18:37:06 -04006609 int i = 0;
James Smart6d368e52011-05-24 11:44:12 -04006610
6611 /* The physical ports are always vpi 0 - translate is unnecessary. */
6612 if (vpi > 0) {
6613 /*
6614 * Translate the physical vpi to the logical vpi. The
6615 * vport stores the logical vpi.
6616 */
6617 for (i = 0; i < phba->max_vpi; i++) {
6618 if (vpi == phba->vpi_ids[i])
6619 break;
6620 }
6621
6622 if (i >= phba->max_vpi) {
6623 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
6624 "2936 Could not find Vport mapped "
6625 "to vpi %d\n", vpi);
6626 return NULL;
6627 }
6628 }
James Smart92d7f7b2007-06-17 19:56:38 -05006629
James Smart549e55c2007-08-02 11:09:51 -04006630 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006631 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart5248a742011-07-22 18:37:06 -04006632 if (vport->vpi == i) {
James Smart549e55c2007-08-02 11:09:51 -04006633 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006634 return vport;
James Smart549e55c2007-08-02 11:09:51 -04006635 }
James Smart92d7f7b2007-06-17 19:56:38 -05006636 }
James Smart549e55c2007-08-02 11:09:51 -04006637 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006638 return NULL;
6639}
James Smarted957682007-06-17 19:56:37 -05006640
James Smarte59058c2008-08-24 21:49:00 -04006641/**
James Smart3621a712009-04-06 18:47:14 -04006642 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006643 * @phba: pointer to lpfc hba data structure.
6644 * @pring: pointer to a SLI ring.
6645 * @elsiocb: pointer to lpfc els iocb data structure.
6646 *
6647 * This routine is used to process an unsolicited event received from a SLI
6648 * (Service Level Interface) ring. The actual processing of the data buffer
6649 * associated with the unsolicited event is done by invoking the routine
6650 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6651 * SLI ring on which the unsolicited event was received.
6652 **/
James Smarted957682007-06-17 19:56:37 -05006653void
6654lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6655 struct lpfc_iocbq *elsiocb)
6656{
6657 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006658 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006659 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006660 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6661 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006662
James Smartd7c255b2008-08-24 21:50:00 -04006663 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006664 elsiocb->context2 = NULL;
6665 elsiocb->context3 = NULL;
6666
6667 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6668 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6669 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6670 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006671 phba->fc_stat.NoRcvBuf++;
6672 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006673 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006674 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006675 return;
6676 }
6677
James Smart92d7f7b2007-06-17 19:56:38 -05006678 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6679 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6680 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6681 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6682 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006683 else
6684 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04006685 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05006686 }
James Smart6d368e52011-05-24 11:44:12 -04006687
James Smart7f5f3d02008-02-08 18:50:14 -05006688 /* If there are no BDEs associated
6689 * with this IOCB, there is nothing to do.
6690 */
James Smarted957682007-06-17 19:56:37 -05006691 if (icmd->ulpBdeCount == 0)
6692 return;
6693
James Smart7f5f3d02008-02-08 18:50:14 -05006694 /* type of ELS cmd is first 32bit word
6695 * in packet
6696 */
James Smarted957682007-06-17 19:56:37 -05006697 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006698 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006699 } else {
6700 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6701 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006702 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6703 paddr);
James Smarted957682007-06-17 19:56:37 -05006704 }
6705
James Smart92d7f7b2007-06-17 19:56:38 -05006706 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6707 /*
6708 * The different unsolicited event handlers would tell us
6709 * if they are done with "mp" by setting context2 to NULL.
6710 */
dea31012005-04-17 16:05:31 -05006711 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006712 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6713 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006714 }
James Smarted957682007-06-17 19:56:37 -05006715
6716 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006717 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006718 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006719 elsiocb->context2 = bdeBuf2;
6720 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006721 /* free mp if we are done with it */
6722 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006723 lpfc_in_buf_free(phba, elsiocb->context2);
6724 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006725 }
dea31012005-04-17 16:05:31 -05006726 }
dea31012005-04-17 16:05:31 -05006727}
James Smart92d7f7b2007-06-17 19:56:38 -05006728
James Smarte59058c2008-08-24 21:49:00 -04006729/**
James Smart3621a712009-04-06 18:47:14 -04006730 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006731 * @phba: pointer to lpfc hba data structure.
6732 * @vport: pointer to a virtual N_Port data structure.
6733 *
6734 * This routine issues a Port Login (PLOGI) to the Name Server with
6735 * State Change Request (SCR) for a @vport. This routine will create an
6736 * ndlp for the Name Server associated to the @vport if such node does
6737 * not already exist. The PLOGI to Name Server is issued by invoking the
6738 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6739 * (FDMI) is configured to the @vport, a FDMI node will be created and
6740 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6741 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006742void
6743lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6744{
6745 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05006746 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6747
6748 /*
6749 * If lpfc_delay_discovery parameter is set and the clean address
6750 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6751 * discovery.
6752 */
6753 spin_lock_irq(shost->host_lock);
6754 if (vport->fc_flag & FC_DISC_DELAYED) {
6755 spin_unlock_irq(shost->host_lock);
6756 mod_timer(&vport->delayed_disc_tmo,
6757 jiffies + HZ * phba->fc_ratov);
6758 return;
6759 }
6760 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006761
6762 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6763 if (!ndlp) {
6764 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6765 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006766 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05006767 lpfc_disc_start(vport);
6768 return;
6769 }
6770 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006771 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6772 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006773 return;
6774 }
6775 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006776 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6777 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6778 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006779 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05006780 lpfc_disc_start(vport);
6781 return;
6782 }
6783 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6784 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6785 "0348 NameServer login: node freed\n");
6786 return;
6787 }
James Smart92d7f7b2007-06-17 19:56:38 -05006788 }
James Smart58da1ff2008-04-07 10:15:56 -04006789 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006790
6791 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6792
6793 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6794 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006795 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6796 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006797 return;
6798 }
6799
James Smart3de2a652007-08-02 11:09:59 -04006800 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05006801 /* If this is the first time, allocate an ndlp and initialize
6802 * it. Otherwise, make sure the node is enabled and then do the
6803 * login.
6804 */
6805 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
6806 if (!ndlp_fdmi) {
6807 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6808 GFP_KERNEL);
6809 if (ndlp_fdmi) {
6810 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6811 ndlp_fdmi->nlp_type |= NLP_FABRIC;
6812 } else
6813 return;
6814 }
6815 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
6816 ndlp_fdmi = lpfc_enable_node(vport,
6817 ndlp_fdmi,
6818 NLP_STE_NPR_NODE);
6819
James Smart92d7f7b2007-06-17 19:56:38 -05006820 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04006821 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05006822 NLP_STE_PLOGI_ISSUE);
6823 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006824 }
6825 }
James Smart92d7f7b2007-06-17 19:56:38 -05006826}
6827
James Smarte59058c2008-08-24 21:49:00 -04006828/**
James Smart3621a712009-04-06 18:47:14 -04006829 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006830 * @phba: pointer to lpfc hba data structure.
6831 * @pmb: pointer to the driver internal queue element for mailbox command.
6832 *
6833 * This routine is the completion callback function to register new vport
6834 * mailbox command. If the new vport mailbox command completes successfully,
6835 * the fabric registration login shall be performed on physical port (the
6836 * new vport created is actually a physical port, with VPI 0) or the port
6837 * login to Name Server for State Change Request (SCR) will be performed
6838 * on virtual port (real virtual port, with VPI greater than 0).
6839 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006840static void
6841lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6842{
6843 struct lpfc_vport *vport = pmb->vport;
6844 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6845 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006846 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006847 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006848
James Smart09372822008-01-11 01:52:54 -05006849 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006850 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006851 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006852
6853 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006854 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006855 "0915 Register VPI failed : Status: x%x"
6856 " upd bit: x%x \n", mb->mbxStatus,
6857 mb->un.varRegVpi.upd);
6858 if (phba->sli_rev == LPFC_SLI_REV4 &&
6859 mb->un.varRegVpi.upd)
6860 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006861
6862 switch (mb->mbxStatus) {
6863 case 0x11: /* unsupported feature */
6864 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006865 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006866 /* giving up on vport registration */
6867 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6868 spin_lock_irq(shost->host_lock);
6869 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6870 spin_unlock_irq(shost->host_lock);
6871 lpfc_can_disctmo(vport);
6872 break;
James Smart695a8142010-01-26 23:08:03 -05006873 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6874 case 0x20:
6875 spin_lock_irq(shost->host_lock);
6876 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6877 spin_unlock_irq(shost->host_lock);
6878 lpfc_init_vpi(phba, pmb, vport->vpi);
6879 pmb->vport = vport;
6880 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6881 rc = lpfc_sli_issue_mbox(phba, pmb,
6882 MBX_NOWAIT);
6883 if (rc == MBX_NOT_FINISHED) {
6884 lpfc_printf_vlog(vport,
6885 KERN_ERR, LOG_MBOX,
6886 "2732 Failed to issue INIT_VPI"
6887 " mailbox command\n");
6888 } else {
6889 lpfc_nlp_put(ndlp);
6890 return;
6891 }
6892
James Smart92d7f7b2007-06-17 19:56:38 -05006893 default:
6894 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04006895 if (phba->sli_rev == LPFC_SLI_REV4)
6896 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006897 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006898 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006899 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006900 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006901 if (vport->port_type == LPFC_PHYSICAL_PORT
6902 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05006903 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05006904 else
6905 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006906 break;
6907 }
James Smart92d7f7b2007-06-17 19:56:38 -05006908 } else {
James Smart695a8142010-01-26 23:08:03 -05006909 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006910 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006911 spin_unlock_irq(shost->host_lock);
6912 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006913 if (phba->sli_rev < LPFC_SLI_REV4)
6914 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006915 else {
James Smartfc2b9892010-02-26 14:15:29 -05006916 /*
6917 * If the physical port is instantiated using
6918 * FDISC, do not start vport discovery.
6919 */
6920 if (vport->port_state != LPFC_FDISC)
6921 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006922 lpfc_do_scr_ns_plogi(phba, vport);
6923 }
6924 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006925 lpfc_do_scr_ns_plogi(phba, vport);
6926 }
James Smart38b92ef2010-08-04 16:11:39 -04006927mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05006928 /* Now, we decrement the ndlp reference count held for this
6929 * callback function
6930 */
6931 lpfc_nlp_put(ndlp);
6932
James Smart92d7f7b2007-06-17 19:56:38 -05006933 mempool_free(pmb, phba->mbox_mem_pool);
6934 return;
6935}
6936
James Smarte59058c2008-08-24 21:49:00 -04006937/**
James Smart3621a712009-04-06 18:47:14 -04006938 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006939 * @phba: pointer to lpfc hba data structure.
6940 * @vport: pointer to a host virtual N_Port data structure.
6941 * @ndlp: pointer to a node-list data structure.
6942 *
6943 * This routine registers the @vport as a new virtual port with a HBA.
6944 * It is done through a registering vpi mailbox command.
6945 **/
James Smart695a8142010-01-26 23:08:03 -05006946void
James Smart92d7f7b2007-06-17 19:56:38 -05006947lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6948 struct lpfc_nodelist *ndlp)
6949{
James Smart09372822008-01-11 01:52:54 -05006950 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006951 LPFC_MBOXQ_t *mbox;
6952
6953 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6954 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006955 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006956 mbox->vport = vport;
6957 mbox->context2 = lpfc_nlp_get(ndlp);
6958 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006959 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006960 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006961 /* mailbox command not success, decrement ndlp
6962 * reference count for this command
6963 */
6964 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006965 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006966
James Smarte8b62012007-08-02 11:10:09 -04006967 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6968 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006969 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006970 }
6971 } else {
James Smarte8b62012007-08-02 11:10:09 -04006972 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6973 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006974 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006975 }
James Smartfa4066b2008-01-11 01:53:27 -05006976 return;
6977
6978mbox_err_exit:
6979 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6980 spin_lock_irq(shost->host_lock);
6981 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6982 spin_unlock_irq(shost->host_lock);
6983 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006984}
6985
James Smarte59058c2008-08-24 21:49:00 -04006986/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006987 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006988 * @phba: pointer to lpfc hba data structure.
6989 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006990 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006991 **/
6992void
James Smart0c9ab6f2010-02-26 14:15:57 -05006993lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006994{
6995 struct lpfc_vport **vports;
6996 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006997 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006998 int i;
James Smart695a8142010-01-26 23:08:03 -05006999
7000 /* Treat this failure as linkdown for all vports */
7001 link_state = phba->link_state;
7002 lpfc_linkdown(phba);
7003 phba->link_state = link_state;
7004
7005 vports = lpfc_create_vport_work_array(phba);
7006
7007 if (vports) {
7008 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
7009 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
7010 if (ndlp)
7011 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
7012 lpfc_els_flush_cmd(vports[i]);
7013 }
7014 lpfc_destroy_vport_work_array(phba, vports);
7015 }
James Smart0c9ab6f2010-02-26 14:15:57 -05007016}
7017
7018/**
7019 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7020 * @phba: pointer to lpfc hba data structure.
7021 *
7022 * This routine abort all pending discovery commands and
7023 * start a timer to retry FLOGI for the physical port
7024 * discovery.
7025 **/
7026void
7027lpfc_retry_pport_discovery(struct lpfc_hba *phba)
7028{
7029 struct lpfc_nodelist *ndlp;
7030 struct Scsi_Host *shost;
7031
7032 /* Cancel the all vports retry delay retry timers */
7033 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05007034
7035 /* If fabric require FLOGI, then re-instantiate physical login */
7036 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
7037 if (!ndlp)
7038 return;
7039
James Smart695a8142010-01-26 23:08:03 -05007040 shost = lpfc_shost_from_vport(phba->pport);
7041 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
7042 spin_lock_irq(shost->host_lock);
7043 ndlp->nlp_flag |= NLP_DELAY_TMO;
7044 spin_unlock_irq(shost->host_lock);
7045 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7046 phba->pport->port_state = LPFC_FLOGI;
7047 return;
7048}
7049
7050/**
7051 * lpfc_fabric_login_reqd - Check if FLOGI required.
7052 * @phba: pointer to lpfc hba data structure.
7053 * @cmdiocb: pointer to FDISC command iocb.
7054 * @rspiocb: pointer to FDISC response iocb.
7055 *
7056 * This routine checks if a FLOGI is reguired for FDISC
7057 * to succeed.
7058 **/
7059static int
7060lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7061 struct lpfc_iocbq *cmdiocb,
7062 struct lpfc_iocbq *rspiocb)
7063{
7064
7065 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7066 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7067 return 0;
7068 else
7069 return 1;
7070}
7071
7072/**
James Smart3621a712009-04-06 18:47:14 -04007073 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007074 * @phba: pointer to lpfc hba data structure.
7075 * @cmdiocb: pointer to lpfc command iocb data structure.
7076 * @rspiocb: pointer to lpfc response iocb data structure.
7077 *
7078 * This routine is the completion callback function to a Fabric Discover
7079 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7080 * single threaded, each FDISC completion callback function will reset
7081 * the discovery timer for all vports such that the timers will not get
7082 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7083 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7084 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7085 * assigned to the vport has been changed with the completion of the FDISC
7086 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7087 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7088 * routine is invoked to register new vport with the HBA. Otherwise, the
7089 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7090 * Server for State Change Request (SCR).
7091 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007092static void
7093lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7094 struct lpfc_iocbq *rspiocb)
7095{
7096 struct lpfc_vport *vport = cmdiocb->vport;
7097 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7098 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7099 struct lpfc_nodelist *np;
7100 struct lpfc_nodelist *next_np;
7101 IOCB_t *irsp = &rspiocb->iocb;
7102 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05007103 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7104 struct serv_parm *sp;
7105 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05007106
James Smarte8b62012007-08-02 11:10:09 -04007107 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7108 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7109 irsp->ulpStatus, irsp->un.ulpWord[4],
7110 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05007111 /* Since all FDISCs are being single threaded, we
7112 * must reset the discovery timer for ALL vports
7113 * waiting to send FDISC when one completes.
7114 */
7115 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7116 lpfc_set_disctmo(piocb->vport);
7117 }
7118
James Smart858c9f62007-06-17 19:56:39 -05007119 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7120 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7121 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7122
James Smart92d7f7b2007-06-17 19:56:38 -05007123 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05007124
7125 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7126 lpfc_retry_pport_discovery(phba);
7127 goto out;
7128 }
7129
James Smart92d7f7b2007-06-17 19:56:38 -05007130 /* Check for retry */
7131 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7132 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007133 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04007134 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04007135 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04007136 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04007137 goto fdisc_failed;
7138 }
James Smartd7c255b2008-08-24 21:50:00 -04007139 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05007140 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04007141 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04007142 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05007143 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04007144 vport->fc_flag |= FC_PUBLIC_LOOP;
7145 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007146
James Smartd7c255b2008-08-24 21:50:00 -04007147 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7148 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05007149 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7150 sp = prsp->virt + sizeof(uint32_t);
7151 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7152 memcpy(&vport->fabric_portname, &sp->portName,
7153 sizeof(struct lpfc_name));
7154 memcpy(&vport->fabric_nodename, &sp->nodeName,
7155 sizeof(struct lpfc_name));
7156 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04007157 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7158 /* If our NportID changed, we need to ensure all
7159 * remaining NPORTs get unreg_login'ed so we can
7160 * issue unreg_vpi.
7161 */
7162 list_for_each_entry_safe(np, next_np,
7163 &vport->fc_nodes, nlp_listp) {
7164 if (!NLP_CHK_NODE_ACT(ndlp) ||
7165 (np->nlp_state != NLP_STE_NPR_NODE) ||
7166 !(np->nlp_flag & NLP_NPR_ADISC))
7167 continue;
James Smart09372822008-01-11 01:52:54 -05007168 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007169 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007170 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007171 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007172 }
James Smart78730cf2010-04-06 15:06:30 -04007173 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007174
7175 if (phba->sli_rev == LPFC_SLI_REV4)
7176 lpfc_sli4_unreg_all_rpis(vport);
7177
James Smartd7c255b2008-08-24 21:50:00 -04007178 lpfc_mbx_unreg_vpi(vport);
7179 spin_lock_irq(shost->host_lock);
7180 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007181 if (phba->sli_rev == LPFC_SLI_REV4)
7182 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007183 else
7184 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007185 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007186 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7187 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7188 /*
7189 * Driver needs to re-reg VPI in order for f/w
7190 * to update the MAC address.
7191 */
7192 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007193 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007194 }
7195
James Smartecfd03c2010-02-12 14:41:27 -05007196 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7197 lpfc_issue_init_vpi(vport);
7198 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007199 lpfc_register_new_vport(phba, vport, ndlp);
7200 else
7201 lpfc_do_scr_ns_plogi(phba, vport);
7202 goto out;
7203fdisc_failed:
7204 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7205 /* Cancel discovery timer */
7206 lpfc_can_disctmo(vport);
7207 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007208out:
7209 lpfc_els_free_iocb(phba, cmdiocb);
7210}
7211
James Smarte59058c2008-08-24 21:49:00 -04007212/**
James Smart3621a712009-04-06 18:47:14 -04007213 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007214 * @vport: pointer to a virtual N_Port data structure.
7215 * @ndlp: pointer to a node-list data structure.
7216 * @retry: number of retries to the command IOCB.
7217 *
7218 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7219 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7220 * routine to issue the IOCB, which makes sure only one outstanding fabric
7221 * IOCB will be sent off HBA at any given time.
7222 *
7223 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7224 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7225 * will be stored into the context1 field of the IOCB for the completion
7226 * callback function to the FDISC ELS command.
7227 *
7228 * Return code
7229 * 0 - Successfully issued fdisc iocb command
7230 * 1 - Failed to issue fdisc iocb command
7231 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007232static int
James Smart92d7f7b2007-06-17 19:56:38 -05007233lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7234 uint8_t retry)
7235{
7236 struct lpfc_hba *phba = vport->phba;
7237 IOCB_t *icmd;
7238 struct lpfc_iocbq *elsiocb;
7239 struct serv_parm *sp;
7240 uint8_t *pcmd;
7241 uint16_t cmdsize;
7242 int did = ndlp->nlp_DID;
7243 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007244
James Smart5ffc2662009-11-18 15:39:44 -05007245 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05007246 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7247 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7248 ELS_CMD_FDISC);
7249 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007250 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007251 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7252 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007253 return 1;
7254 }
7255
7256 icmd = &elsiocb->iocb;
7257 icmd->un.elsreq64.myID = 0;
7258 icmd->un.elsreq64.fl = 1;
7259
James Smart40426292010-12-15 17:58:10 -05007260 if ((phba->sli_rev == LPFC_SLI_REV4) &&
7261 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
7262 LPFC_SLI_INTF_IF_TYPE_0)) {
James Smartf1126682009-06-10 17:22:44 -04007263 /* FDISC needs to be 1 for WQE VPI */
7264 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
7265 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
7266 /* Set the ulpContext to the vpi */
James Smart6d368e52011-05-24 11:44:12 -04007267 elsiocb->iocb.ulpContext = phba->vpi_ids[vport->vpi];
James Smartf1126682009-06-10 17:22:44 -04007268 } else {
7269 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
7270 icmd->ulpCt_h = 1;
7271 icmd->ulpCt_l = 0;
7272 }
James Smart92d7f7b2007-06-17 19:56:38 -05007273
7274 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7275 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7276 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7277 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7278 sp = (struct serv_parm *) pcmd;
7279 /* Setup CSPs accordingly for Fabric */
7280 sp->cmn.e_d_tov = 0;
7281 sp->cmn.w2.r_a_tov = 0;
7282 sp->cls1.classValid = 0;
7283 sp->cls2.seqDelivery = 1;
7284 sp->cls3.seqDelivery = 1;
7285
7286 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7287 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7288 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7289 pcmd += sizeof(uint32_t); /* Port Name */
7290 memcpy(pcmd, &vport->fc_portname, 8);
7291 pcmd += sizeof(uint32_t); /* Node Name */
7292 pcmd += sizeof(uint32_t); /* Node Name */
7293 memcpy(pcmd, &vport->fc_nodename, 8);
7294
7295 lpfc_set_disctmo(vport);
7296
7297 phba->fc_stat.elsXmitFDISC++;
7298 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7299
James Smart858c9f62007-06-17 19:56:39 -05007300 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7301 "Issue FDISC: did:x%x",
7302 did, 0, 0);
7303
James Smart92d7f7b2007-06-17 19:56:38 -05007304 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7305 if (rc == IOCB_ERROR) {
7306 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007307 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007308 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7309 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007310 return 1;
7311 }
7312 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007313 return 0;
7314}
7315
James Smarte59058c2008-08-24 21:49:00 -04007316/**
James Smart3621a712009-04-06 18:47:14 -04007317 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007318 * @phba: pointer to lpfc hba data structure.
7319 * @cmdiocb: pointer to lpfc command iocb data structure.
7320 * @rspiocb: pointer to lpfc response iocb data structure.
7321 *
7322 * This routine is the completion callback function to the issuing of a LOGO
7323 * ELS command off a vport. It frees the command IOCB and then decrement the
7324 * reference count held on ndlp for this completion function, indicating that
7325 * the reference to the ndlp is no long needed. Note that the
7326 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7327 * callback function and an additional explicit ndlp reference decrementation
7328 * will trigger the actual release of the ndlp.
7329 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007330static void
7331lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7332 struct lpfc_iocbq *rspiocb)
7333{
7334 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007335 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007336 struct lpfc_nodelist *ndlp;
James Smart9589b062011-04-16 11:03:17 -04007337 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05007338
James Smart9589b062011-04-16 11:03:17 -04007339 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007340 irsp = &rspiocb->iocb;
7341 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7342 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7343 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007344
7345 lpfc_els_free_iocb(phba, cmdiocb);
7346 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007347
7348 /* Trigger the release of the ndlp after logo */
7349 lpfc_nlp_put(ndlp);
James Smart9589b062011-04-16 11:03:17 -04007350
7351 /* NPIV LOGO completes to NPort <nlp_DID> */
7352 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7353 "2928 NPIV LOGO completes to NPort x%x "
7354 "Data: x%x x%x x%x x%x\n",
7355 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
7356 irsp->ulpTimeout, vport->num_disc_nodes);
7357
7358 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
7359 spin_lock_irq(shost->host_lock);
7360 vport->fc_flag &= ~FC_FABRIC;
7361 spin_unlock_irq(shost->host_lock);
7362 }
James Smart92d7f7b2007-06-17 19:56:38 -05007363}
7364
James Smarte59058c2008-08-24 21:49:00 -04007365/**
James Smart3621a712009-04-06 18:47:14 -04007366 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007367 * @vport: pointer to a virtual N_Port data structure.
7368 * @ndlp: pointer to a node-list data structure.
7369 *
7370 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7371 *
7372 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7373 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7374 * will be stored into the context1 field of the IOCB for the completion
7375 * callback function to the LOGO ELS command.
7376 *
7377 * Return codes
7378 * 0 - Successfully issued logo off the @vport
7379 * 1 - Failed to issue logo off the @vport
7380 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007381int
7382lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7383{
7384 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7385 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007386 IOCB_t *icmd;
7387 struct lpfc_iocbq *elsiocb;
7388 uint8_t *pcmd;
7389 uint16_t cmdsize;
7390
7391 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7392 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7393 ELS_CMD_LOGO);
7394 if (!elsiocb)
7395 return 1;
7396
7397 icmd = &elsiocb->iocb;
7398 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7399 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7400 pcmd += sizeof(uint32_t);
7401
7402 /* Fill in LOGO payload */
7403 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7404 pcmd += sizeof(uint32_t);
7405 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7406
James Smart858c9f62007-06-17 19:56:39 -05007407 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7408 "Issue LOGO npiv did:x%x flg:x%x",
7409 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7410
James Smart92d7f7b2007-06-17 19:56:38 -05007411 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7412 spin_lock_irq(shost->host_lock);
7413 ndlp->nlp_flag |= NLP_LOGO_SND;
7414 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007415 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7416 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007417 spin_lock_irq(shost->host_lock);
7418 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7419 spin_unlock_irq(shost->host_lock);
7420 lpfc_els_free_iocb(phba, elsiocb);
7421 return 1;
7422 }
7423 return 0;
7424}
7425
James Smarte59058c2008-08-24 21:49:00 -04007426/**
James Smart3621a712009-04-06 18:47:14 -04007427 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007428 * @ptr: holder for the timer function associated data.
7429 *
7430 * This routine is invoked by the fabric iocb block timer after
7431 * timeout. It posts the fabric iocb block timeout event by setting the
7432 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7433 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7434 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7435 * posted event WORKER_FABRIC_BLOCK_TMO.
7436 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007437void
7438lpfc_fabric_block_timeout(unsigned long ptr)
7439{
7440 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7441 unsigned long iflags;
7442 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007443
James Smart92d7f7b2007-06-17 19:56:38 -05007444 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7445 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7446 if (!tmo_posted)
7447 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7448 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7449
James Smart5e9d9b82008-06-14 22:52:53 -04007450 if (!tmo_posted)
7451 lpfc_worker_wake_up(phba);
7452 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007453}
7454
James Smarte59058c2008-08-24 21:49:00 -04007455/**
James Smart3621a712009-04-06 18:47:14 -04007456 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007457 * @phba: pointer to lpfc hba data structure.
7458 *
7459 * This routine issues one fabric iocb from the driver internal list to
7460 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7461 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7462 * remove one pending fabric iocb from the driver internal list and invokes
7463 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7464 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007465static void
7466lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7467{
7468 struct lpfc_iocbq *iocb;
7469 unsigned long iflags;
7470 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007471 IOCB_t *cmd;
7472
7473repeat:
7474 iocb = NULL;
7475 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007476 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007477 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7478 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7479 list);
7480 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007481 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007482 atomic_inc(&phba->fabric_iocb_count);
7483 }
7484 spin_unlock_irqrestore(&phba->hbalock, iflags);
7485 if (iocb) {
7486 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7487 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7488 iocb->iocb_flag |= LPFC_IO_FABRIC;
7489
James Smart858c9f62007-06-17 19:56:39 -05007490 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7491 "Fabric sched1: ste:x%x",
7492 iocb->vport->port_state, 0, 0);
7493
James Smart3772a992009-05-22 14:50:54 -04007494 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007495
7496 if (ret == IOCB_ERROR) {
7497 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7498 iocb->fabric_iocb_cmpl = NULL;
7499 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7500 cmd = &iocb->iocb;
7501 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7502 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7503 iocb->iocb_cmpl(phba, iocb, iocb);
7504
7505 atomic_dec(&phba->fabric_iocb_count);
7506 goto repeat;
7507 }
7508 }
7509
7510 return;
7511}
7512
James Smarte59058c2008-08-24 21:49:00 -04007513/**
James Smart3621a712009-04-06 18:47:14 -04007514 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007515 * @phba: pointer to lpfc hba data structure.
7516 *
7517 * This routine unblocks the issuing fabric iocb command. The function
7518 * will clear the fabric iocb block bit and then invoke the routine
7519 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7520 * from the driver internal fabric iocb list.
7521 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007522void
7523lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7524{
7525 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7526
7527 lpfc_resume_fabric_iocbs(phba);
7528 return;
7529}
7530
James Smarte59058c2008-08-24 21:49:00 -04007531/**
James Smart3621a712009-04-06 18:47:14 -04007532 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007533 * @phba: pointer to lpfc hba data structure.
7534 *
7535 * This routine blocks the issuing fabric iocb for a specified amount of
7536 * time (currently 100 ms). This is done by set the fabric iocb block bit
7537 * and set up a timeout timer for 100ms. When the block bit is set, no more
7538 * fabric iocb will be issued out of the HBA.
7539 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007540static void
7541lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7542{
7543 int blocked;
7544
7545 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007546 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007547 if (!blocked)
7548 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7549
7550 return;
7551}
7552
James Smarte59058c2008-08-24 21:49:00 -04007553/**
James Smart3621a712009-04-06 18:47:14 -04007554 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007555 * @phba: pointer to lpfc hba data structure.
7556 * @cmdiocb: pointer to lpfc command iocb data structure.
7557 * @rspiocb: pointer to lpfc response iocb data structure.
7558 *
7559 * This routine is the callback function that is put to the fabric iocb's
7560 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7561 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7562 * function first restores and invokes the original iocb's callback function
7563 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7564 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7565 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007566static void
7567lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7568 struct lpfc_iocbq *rspiocb)
7569{
7570 struct ls_rjt stat;
7571
7572 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7573 BUG();
7574
7575 switch (rspiocb->iocb.ulpStatus) {
7576 case IOSTAT_NPORT_RJT:
7577 case IOSTAT_FABRIC_RJT:
7578 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7579 lpfc_block_fabric_iocbs(phba);
7580 }
7581 break;
7582
7583 case IOSTAT_NPORT_BSY:
7584 case IOSTAT_FABRIC_BSY:
7585 lpfc_block_fabric_iocbs(phba);
7586 break;
7587
7588 case IOSTAT_LS_RJT:
7589 stat.un.lsRjtError =
7590 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7591 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7592 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7593 lpfc_block_fabric_iocbs(phba);
7594 break;
7595 }
7596
7597 if (atomic_read(&phba->fabric_iocb_count) == 0)
7598 BUG();
7599
7600 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7601 cmdiocb->fabric_iocb_cmpl = NULL;
7602 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7603 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7604
7605 atomic_dec(&phba->fabric_iocb_count);
7606 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007607 /* Post any pending iocbs to HBA */
7608 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007609 }
7610}
7611
James Smarte59058c2008-08-24 21:49:00 -04007612/**
James Smart3621a712009-04-06 18:47:14 -04007613 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007614 * @phba: pointer to lpfc hba data structure.
7615 * @iocb: pointer to lpfc command iocb data structure.
7616 *
7617 * This routine is used as the top-level API for issuing a fabric iocb command
7618 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7619 * function makes sure that only one fabric bound iocb will be outstanding at
7620 * any given time. As such, this function will first check to see whether there
7621 * is already an outstanding fabric iocb on the wire. If so, it will put the
7622 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7623 * issued later. Otherwise, it will issue the iocb on the wire and update the
7624 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7625 *
7626 * Note, this implementation has a potential sending out fabric IOCBs out of
7627 * order. The problem is caused by the construction of the "ready" boolen does
7628 * not include the condition that the internal fabric IOCB list is empty. As
7629 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7630 * ahead of the fabric IOCBs in the internal list.
7631 *
7632 * Return code
7633 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7634 * IOCB_ERROR - failed to issue fabric iocb
7635 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007636static int
James Smart92d7f7b2007-06-17 19:56:38 -05007637lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7638{
7639 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007640 int ready;
7641 int ret;
7642
7643 if (atomic_read(&phba->fabric_iocb_count) > 1)
7644 BUG();
7645
7646 spin_lock_irqsave(&phba->hbalock, iflags);
7647 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7648 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7649
James Smart7f5f3d02008-02-08 18:50:14 -05007650 if (ready)
7651 /* Increment fabric iocb count to hold the position */
7652 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007653 spin_unlock_irqrestore(&phba->hbalock, iflags);
7654 if (ready) {
7655 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7656 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7657 iocb->iocb_flag |= LPFC_IO_FABRIC;
7658
James Smart858c9f62007-06-17 19:56:39 -05007659 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7660 "Fabric sched2: ste:x%x",
7661 iocb->vport->port_state, 0, 0);
7662
James Smart3772a992009-05-22 14:50:54 -04007663 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007664
7665 if (ret == IOCB_ERROR) {
7666 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7667 iocb->fabric_iocb_cmpl = NULL;
7668 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7669 atomic_dec(&phba->fabric_iocb_count);
7670 }
7671 } else {
7672 spin_lock_irqsave(&phba->hbalock, iflags);
7673 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7674 spin_unlock_irqrestore(&phba->hbalock, iflags);
7675 ret = IOCB_SUCCESS;
7676 }
7677 return ret;
7678}
7679
James Smarte59058c2008-08-24 21:49:00 -04007680/**
James Smart3621a712009-04-06 18:47:14 -04007681 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007682 * @vport: pointer to a virtual N_Port data structure.
7683 *
7684 * This routine aborts all the IOCBs associated with a @vport from the
7685 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7686 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7687 * list, removes each IOCB associated with the @vport off the list, set the
7688 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7689 * associated with the IOCB.
7690 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007691static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007692{
7693 LIST_HEAD(completions);
7694 struct lpfc_hba *phba = vport->phba;
7695 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007696
7697 spin_lock_irq(&phba->hbalock);
7698 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7699 list) {
7700
7701 if (piocb->vport != vport)
7702 continue;
7703
7704 list_move_tail(&piocb->list, &completions);
7705 }
7706 spin_unlock_irq(&phba->hbalock);
7707
James Smarta257bf92009-04-06 18:48:10 -04007708 /* Cancel all the IOCBs from the completions list */
7709 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7710 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007711}
7712
James Smarte59058c2008-08-24 21:49:00 -04007713/**
James Smart3621a712009-04-06 18:47:14 -04007714 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007715 * @ndlp: pointer to a node-list data structure.
7716 *
7717 * This routine aborts all the IOCBs associated with an @ndlp from the
7718 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7719 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7720 * list, removes each IOCB associated with the @ndlp off the list, set the
7721 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7722 * associated with the IOCB.
7723 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007724void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7725{
7726 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007727 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007728 struct lpfc_iocbq *tmp_iocb, *piocb;
7729 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007730
7731 spin_lock_irq(&phba->hbalock);
7732 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7733 list) {
7734 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7735
7736 list_move_tail(&piocb->list, &completions);
7737 }
7738 }
7739 spin_unlock_irq(&phba->hbalock);
7740
James Smarta257bf92009-04-06 18:48:10 -04007741 /* Cancel all the IOCBs from the completions list */
7742 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7743 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007744}
7745
James Smarte59058c2008-08-24 21:49:00 -04007746/**
James Smart3621a712009-04-06 18:47:14 -04007747 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007748 * @phba: pointer to lpfc hba data structure.
7749 *
7750 * This routine aborts all the IOCBs currently on the driver internal
7751 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7752 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7753 * list, removes IOCBs off the list, set the status feild to
7754 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7755 * the IOCB.
7756 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007757void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7758{
7759 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007760
7761 spin_lock_irq(&phba->hbalock);
7762 list_splice_init(&phba->fabric_iocb_list, &completions);
7763 spin_unlock_irq(&phba->hbalock);
7764
James Smarta257bf92009-04-06 18:48:10 -04007765 /* Cancel all the IOCBs from the completions list */
7766 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7767 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007768}
James Smart6fb120a2009-05-22 14:52:59 -04007769
7770/**
James Smart1151e3e2011-02-16 12:39:35 -05007771 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7772 * @vport: pointer to lpfc vport data structure.
7773 *
7774 * This routine is invoked by the vport cleanup for deletions and the cleanup
7775 * for an ndlp on removal.
7776 **/
7777void
7778lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
7779{
7780 struct lpfc_hba *phba = vport->phba;
7781 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7782 unsigned long iflag = 0;
7783
7784 spin_lock_irqsave(&phba->hbalock, iflag);
7785 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7786 list_for_each_entry_safe(sglq_entry, sglq_next,
7787 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7788 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
7789 sglq_entry->ndlp = NULL;
7790 }
7791 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7792 spin_unlock_irqrestore(&phba->hbalock, iflag);
7793 return;
7794}
7795
7796/**
James Smart6fb120a2009-05-22 14:52:59 -04007797 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7798 * @phba: pointer to lpfc hba data structure.
7799 * @axri: pointer to the els xri abort wcqe structure.
7800 *
7801 * This routine is invoked by the worker thread to process a SLI4 slow-path
7802 * ELS aborted xri.
7803 **/
7804void
7805lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7806 struct sli4_wcqe_xri_aborted *axri)
7807{
7808 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05007809 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04007810 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05007811
James Smart6fb120a2009-05-22 14:52:59 -04007812 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7813 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05007814 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04007815 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007816
James Smart0f65ff62010-02-26 14:14:23 -05007817 spin_lock_irqsave(&phba->hbalock, iflag);
7818 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007819 list_for_each_entry_safe(sglq_entry, sglq_next,
7820 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7821 if (sglq_entry->sli4_xritag == xri) {
7822 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05007823 ndlp = sglq_entry->ndlp;
7824 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04007825 list_add_tail(&sglq_entry->list,
7826 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007827 sglq_entry->state = SGL_FREED;
7828 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007829 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart19ca7602010-11-20 23:11:55 -05007830 lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04007831
7832 /* Check if TXQ queue needs to be serviced */
7833 if (pring->txq_cnt)
7834 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007835 return;
7836 }
7837 }
James Smart0f65ff62010-02-26 14:14:23 -05007838 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04007839 lxri = lpfc_sli4_xri_inrange(phba, xri);
7840 if (lxri == NO_XRI) {
7841 spin_unlock_irqrestore(&phba->hbalock, iflag);
7842 return;
7843 }
7844 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05007845 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7846 spin_unlock_irqrestore(&phba->hbalock, iflag);
7847 return;
7848 }
7849 sglq_entry->state = SGL_XRI_ABORTED;
7850 spin_unlock_irqrestore(&phba->hbalock, iflag);
7851 return;
James Smart6fb120a2009-05-22 14:52:59 -04007852}