blob: e2c452467c8bdb4582fc0487905bcf08b02753ec [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 Smartda0436e2009-05-22 14:51:39 -0400253 icmd->ulpContext = vport->vpi + phba->vpi_base;
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 }
457 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
458 if (!mboxq) {
459 rc = -ENOMEM;
460 goto fail_free_coherent;
461 }
462 vport->port_state = LPFC_FABRIC_CFG_LINK;
463 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
464 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
465 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
466 mboxq->vport = vport;
467 mboxq->context1 = dmabuf;
468 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
469 if (rc == MBX_NOT_FINISHED) {
470 rc = -ENXIO;
471 goto fail_free_mbox;
472 }
473 return 0;
474
475fail_free_mbox:
476 mempool_free(mboxq, phba->mbox_mem_pool);
477fail_free_coherent:
478 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
479fail_free_dmabuf:
480 kfree(dmabuf);
481fail:
482 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
483 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
484 "0289 Issue Register VFI failed: Err %d\n", rc);
485 return rc;
486}
487
488/**
James Smart92494142011-02-16 12:39:44 -0500489 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
490 * @vport: pointer to a host virtual N_Port data structure.
491 * @sp: pointer to service parameter data structure.
492 *
493 * This routine is called from FLOGI/FDISC completion handler functions.
494 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
495 * node nodename is changed in the completion service parameter else return
496 * 0. This function also set flag in the vport data structure to delay
497 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
498 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
499 * node nodename is changed in the completion service parameter.
500 *
501 * Return code
502 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
503 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
504 *
505 **/
506static uint8_t
507lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
508 struct serv_parm *sp)
509{
510 uint8_t fabric_param_changed = 0;
511 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
512
513 if ((vport->fc_prevDID != vport->fc_myDID) ||
514 memcmp(&vport->fabric_portname, &sp->portName,
515 sizeof(struct lpfc_name)) ||
516 memcmp(&vport->fabric_nodename, &sp->nodeName,
517 sizeof(struct lpfc_name)))
518 fabric_param_changed = 1;
519
520 /*
521 * Word 1 Bit 31 in common service parameter is overloaded.
522 * Word 1 Bit 31 in FLOGI request is multiple NPort request
523 * Word 1 Bit 31 in FLOGI response is clean address bit
524 *
525 * If fabric parameter is changed and clean address bit is
526 * cleared delay nport discovery if
527 * - vport->fc_prevDID != 0 (not initial discovery) OR
528 * - lpfc_delay_discovery module parameter is set.
529 */
530 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
531 (vport->fc_prevDID || lpfc_delay_discovery)) {
532 spin_lock_irq(shost->host_lock);
533 vport->fc_flag |= FC_DISC_DELAYED;
534 spin_unlock_irq(shost->host_lock);
535 }
536
537 return fabric_param_changed;
538}
539
540
541/**
James Smart3621a712009-04-06 18:47:14 -0400542 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400543 * @vport: pointer to a host virtual N_Port data structure.
544 * @ndlp: pointer to a node-list data structure.
545 * @sp: pointer to service parameter data structure.
546 * @irsp: pointer to the IOCB within the lpfc response IOCB.
547 *
548 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
549 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
550 * port in a fabric topology. It properly sets up the parameters to the @ndlp
551 * from the IOCB response. It also check the newly assigned N_Port ID to the
552 * @vport against the previously assigned N_Port ID. If it is different from
553 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
554 * is invoked on all the remaining nodes with the @vport to unregister the
555 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
556 * is invoked to register login to the fabric.
557 *
558 * Return code
559 * 0 - Success (currently, always return 0)
560 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500561static int
James Smart2e0fef82007-06-17 19:56:36 -0500562lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
563 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500564{
James Smart2e0fef82007-06-17 19:56:36 -0500565 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
566 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500567 struct lpfc_nodelist *np;
568 struct lpfc_nodelist *next_np;
James Smart92494142011-02-16 12:39:44 -0500569 uint8_t fabric_param_changed;
dea31012005-04-17 16:05:31 -0500570
James Smart2e0fef82007-06-17 19:56:36 -0500571 spin_lock_irq(shost->host_lock);
572 vport->fc_flag |= FC_FABRIC;
573 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500574
575 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
576 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
577 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
578
James Smart12265f62010-10-22 11:05:53 -0400579 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500580 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
581
James Smart76a95d72010-11-20 23:11:48 -0500582 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500583 spin_lock_irq(shost->host_lock);
584 vport->fc_flag |= FC_PUBLIC_LOOP;
585 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500586 }
587
James Smart2e0fef82007-06-17 19:56:36 -0500588 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500589 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500590 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500591 ndlp->nlp_class_sup = 0;
592 if (sp->cls1.classValid)
593 ndlp->nlp_class_sup |= FC_COS_CLASS1;
594 if (sp->cls2.classValid)
595 ndlp->nlp_class_sup |= FC_COS_CLASS2;
596 if (sp->cls3.classValid)
597 ndlp->nlp_class_sup |= FC_COS_CLASS3;
598 if (sp->cls4.classValid)
599 ndlp->nlp_class_sup |= FC_COS_CLASS4;
600 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
601 sp->cmn.bbRcvSizeLsb;
James Smart92494142011-02-16 12:39:44 -0500602
603 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
604 memcpy(&vport->fabric_portname, &sp->portName,
605 sizeof(struct lpfc_name));
606 memcpy(&vport->fabric_nodename, &sp->nodeName,
607 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500608 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
609
James Smart92d7f7b2007-06-17 19:56:38 -0500610 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
611 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400612 lpfc_printf_vlog(vport, KERN_WARNING,
613 LOG_ELS | LOG_VPORT,
614 "1816 FLOGI NPIV supported, "
615 "response data 0x%x\n",
616 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500617 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500618 } else {
619 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400620 to call reg_vnpid atleast for the physcial host */
621 lpfc_printf_vlog(vport, KERN_WARNING,
622 LOG_ELS | LOG_VPORT,
623 "1817 Fabric does not support NPIV "
624 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500625 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
626 }
627 }
628
James Smart92494142011-02-16 12:39:44 -0500629 if (fabric_param_changed &&
James Smart92d7f7b2007-06-17 19:56:38 -0500630 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
631
632 /* If our NportID changed, we need to ensure all
633 * remaining NPORTs get unreg_login'ed.
634 */
635 list_for_each_entry_safe(np, next_np,
636 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400637 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500638 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500639 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
640 !(np->nlp_flag & NLP_NPR_ADISC))
641 continue;
642 spin_lock_irq(shost->host_lock);
643 np->nlp_flag &= ~NLP_NPR_ADISC;
644 spin_unlock_irq(shost->host_lock);
645 lpfc_unreg_rpi(vport, np);
646 }
James Smart78730cf2010-04-06 15:06:30 -0400647 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400648
649 if (phba->sli_rev == LPFC_SLI_REV4)
650 lpfc_sli4_unreg_all_rpis(vport);
651
James Smart92d7f7b2007-06-17 19:56:38 -0500652 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
653 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500654 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500655 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500656 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500657 }
James Smartecfd03c2010-02-12 14:41:27 -0500658 /*
659 * If VPI is unreged, driver need to do INIT_VPI
660 * before re-registering
661 */
662 if (phba->sli_rev == LPFC_SLI_REV4) {
663 spin_lock_irq(shost->host_lock);
664 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
665 spin_unlock_irq(shost->host_lock);
666 }
James Smart38b92ef2010-08-04 16:11:39 -0400667 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
668 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
669 /*
670 * Driver needs to re-reg VPI in order for f/w
671 * to update the MAC address.
672 */
James Smart9589b0622011-04-16 11:03:17 -0400673 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400674 lpfc_register_new_vport(phba, vport, ndlp);
675 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500676 }
677
James Smart6fb120a2009-05-22 14:52:59 -0400678 if (phba->sli_rev < LPFC_SLI_REV4) {
679 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
680 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
681 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
682 lpfc_register_new_vport(phba, vport, ndlp);
683 else
684 lpfc_issue_fabric_reglogin(vport);
685 } else {
686 ndlp->nlp_type |= NLP_FABRIC;
687 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500688 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
689 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400690 lpfc_start_fdiscs(phba);
691 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500692 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500693 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500694 else
James Smart6fb120a2009-05-22 14:52:59 -0400695 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500696 }
dea31012005-04-17 16:05:31 -0500697 return 0;
dea31012005-04-17 16:05:31 -0500698}
James Smarte59058c2008-08-24 21:49:00 -0400699/**
James Smart3621a712009-04-06 18:47:14 -0400700 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400701 * @vport: pointer to a host virtual N_Port data structure.
702 * @ndlp: pointer to a node-list data structure.
703 * @sp: pointer to service parameter data structure.
704 *
705 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
706 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
707 * in a point-to-point topology. First, the @vport's N_Port Name is compared
708 * with the received N_Port Name: if the @vport's N_Port Name is greater than
709 * the received N_Port Name lexicographically, this node shall assign local
710 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
711 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
712 * this node shall just wait for the remote node to issue PLOGI and assign
713 * N_Port IDs.
714 *
715 * Return code
716 * 0 - Success
717 * -ENXIO - Fail
718 **/
dea31012005-04-17 16:05:31 -0500719static int
James Smart2e0fef82007-06-17 19:56:36 -0500720lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
721 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500722{
James Smart2e0fef82007-06-17 19:56:36 -0500723 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
724 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500725 LPFC_MBOXQ_t *mbox;
726 int rc;
727
James Smart2e0fef82007-06-17 19:56:36 -0500728 spin_lock_irq(shost->host_lock);
729 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
730 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500731
732 phba->fc_edtov = FF_DEF_EDTOV;
733 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500734 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500735 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500736 if (rc >= 0) {
737 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500738 spin_lock_irq(shost->host_lock);
739 vport->fc_flag |= FC_PT2PT_PLOGI;
740 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500741
742 /*
743 * N_Port ID cannot be 0, set our to LocalID the other
744 * side will be RemoteID.
745 */
746
747 /* not equal */
748 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500749 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500750
751 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
752 if (!mbox)
753 goto fail;
754
755 lpfc_config_link(phba, mbox);
756
757 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500758 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400759 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500760 if (rc == MBX_NOT_FINISHED) {
761 mempool_free(mbox, phba->mbox_mem_pool);
762 goto fail;
763 }
James Smarte47c9092008-02-08 18:49:26 -0500764 /* Decrement ndlp reference count indicating that ndlp can be
765 * safely released when other references to it are done.
766 */
James Smart329f9bc2007-04-25 09:53:01 -0400767 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500768
James Smart2e0fef82007-06-17 19:56:36 -0500769 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500770 if (!ndlp) {
771 /*
772 * Cannot find existing Fabric ndlp, so allocate a
773 * new one
774 */
775 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
776 if (!ndlp)
777 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500778 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500779 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
780 ndlp = lpfc_enable_node(vport, ndlp,
781 NLP_STE_UNUSED_NODE);
782 if(!ndlp)
783 goto fail;
dea31012005-04-17 16:05:31 -0500784 }
785
786 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500787 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500788 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500789 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500790 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500791 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
792 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500793 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500794 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500795 } else
796 /* This side will wait for the PLOGI, decrement ndlp reference
797 * count indicating that ndlp can be released when other
798 * references to it are done.
799 */
James Smart329f9bc2007-04-25 09:53:01 -0400800 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500801
James Smart09372822008-01-11 01:52:54 -0500802 /* If we are pt2pt with another NPort, force NPIV off! */
803 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
804
James Smart2e0fef82007-06-17 19:56:36 -0500805 spin_lock_irq(shost->host_lock);
806 vport->fc_flag |= FC_PT2PT;
807 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500808
809 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500810 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500811 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500812fail:
dea31012005-04-17 16:05:31 -0500813 return -ENXIO;
814}
815
James Smarte59058c2008-08-24 21:49:00 -0400816/**
James Smart3621a712009-04-06 18:47:14 -0400817 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400818 * @phba: pointer to lpfc hba data structure.
819 * @cmdiocb: pointer to lpfc command iocb data structure.
820 * @rspiocb: pointer to lpfc response iocb data structure.
821 *
822 * This routine is the top-level completion callback function for issuing
823 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
824 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
825 * retry has been made (either immediately or delayed with lpfc_els_retry()
826 * returning 1), the command IOCB will be released and function returned.
827 * If the retry attempt has been given up (possibly reach the maximum
828 * number of retries), one additional decrement of ndlp reference shall be
829 * invoked before going out after releasing the command IOCB. This will
830 * actually release the remote node (Note, lpfc_els_free_iocb() will also
831 * invoke one decrement of ndlp reference count). If no error reported in
832 * the IOCB status, the command Port ID field is used to determine whether
833 * this is a point-to-point topology or a fabric topology: if the Port ID
834 * field is assigned, it is a fabric topology; otherwise, it is a
835 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
836 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
837 * specific topology completion conditions.
838 **/
dea31012005-04-17 16:05:31 -0500839static void
James Smart329f9bc2007-04-25 09:53:01 -0400840lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
841 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500842{
James Smart2e0fef82007-06-17 19:56:36 -0500843 struct lpfc_vport *vport = cmdiocb->vport;
844 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500845 IOCB_t *irsp = &rspiocb->iocb;
846 struct lpfc_nodelist *ndlp = cmdiocb->context1;
847 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
848 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500849 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500850 int rc;
851
852 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500853 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500854 /* One additional decrement on node reference count to
855 * trigger the release of the node
856 */
James Smart329f9bc2007-04-25 09:53:01 -0400857 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500858 goto out;
859 }
860
James Smart858c9f62007-06-17 19:56:39 -0500861 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
862 "FLOGI cmpl: status:x%x/x%x state:x%x",
863 irsp->ulpStatus, irsp->un.ulpWord[4],
864 vport->port_state);
865
dea31012005-04-17 16:05:31 -0500866 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500867 /*
James Smarta93ff372010-10-22 11:06:08 -0400868 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500869 * due to new FCF discovery
870 */
871 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smartdbb6b3a2010-06-08 18:31:37 -0400872 (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
James Smart9589b0622011-04-16 11:03:17 -0400873 !((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
874 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500875 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400876 "2611 FLOGI failed on FCF (x%x), "
877 "status:x%x/x%x, tmo:x%x, perform "
878 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -0400879 phba->fcf.current_rec.fcf_indx,
880 irsp->ulpStatus, irsp->un.ulpWord[4],
881 irsp->ulpTimeout);
James Smart0c9ab6f2010-02-26 14:15:57 -0500882 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -0400883 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
884 if (rc)
885 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500886 }
887
James Smart38b92ef2010-08-04 16:11:39 -0400888 /* FLOGI failure */
889 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
890 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
891 irsp->ulpStatus, irsp->un.ulpWord[4],
892 irsp->ulpTimeout);
893
dea31012005-04-17 16:05:31 -0500894 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500895 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500896 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500897
James Smart76a95d72010-11-20 23:11:48 -0500898 /* FLOGI failure */
899 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
900 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
901 irsp->ulpStatus, irsp->un.ulpWord[4],
902 irsp->ulpTimeout);
903
dea31012005-04-17 16:05:31 -0500904 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500905 spin_lock_irq(shost->host_lock);
906 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
907 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500908
James Smart329f9bc2007-04-25 09:53:01 -0400909 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500910 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
911 * alpa map would take too long otherwise.
912 */
913 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400914 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smart76a95d72010-11-20 23:11:48 -0500915 if ((phba->sli_rev == LPFC_SLI_REV4) &&
916 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
917 (vport->fc_prevDID != vport->fc_myDID))) {
918 if (vport->fc_flag & FC_VFI_REGISTERED)
919 lpfc_sli4_unreg_all_rpis(vport);
920 lpfc_issue_reg_vfi(vport);
921 lpfc_nlp_put(ndlp);
922 goto out;
923 }
dea31012005-04-17 16:05:31 -0500924 }
dea31012005-04-17 16:05:31 -0500925 goto flogifail;
926 }
James Smart695a8142010-01-26 23:08:03 -0500927 spin_lock_irq(shost->host_lock);
928 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400929 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500930 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500931
932 /*
933 * The FLogI succeeded. Sync the data for the CPU before
934 * accessing it.
935 */
936 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
937
938 sp = prsp->virt + sizeof(uint32_t);
939
940 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400941 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200942 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400943 "Data: x%x x%x x%x x%x\n",
944 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
945 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500946
James Smart2e0fef82007-06-17 19:56:36 -0500947 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500948 /*
949 * If Common Service Parameters indicate Nport
950 * we are point to point, if Fport we are Fabric.
951 */
952 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500953 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -0500954 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -0500955 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400956 else {
957 lpfc_printf_vlog(vport, KERN_ERR,
958 LOG_FIP | LOG_ELS,
959 "2831 FLOGI response with cleared Fabric "
960 "bit fcf_index 0x%x "
961 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
962 "Fabric Name "
963 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
964 phba->fcf.current_rec.fcf_indx,
965 phba->fcf.current_rec.switch_name[0],
966 phba->fcf.current_rec.switch_name[1],
967 phba->fcf.current_rec.switch_name[2],
968 phba->fcf.current_rec.switch_name[3],
969 phba->fcf.current_rec.switch_name[4],
970 phba->fcf.current_rec.switch_name[5],
971 phba->fcf.current_rec.switch_name[6],
972 phba->fcf.current_rec.switch_name[7],
973 phba->fcf.current_rec.fabric_name[0],
974 phba->fcf.current_rec.fabric_name[1],
975 phba->fcf.current_rec.fabric_name[2],
976 phba->fcf.current_rec.fabric_name[3],
977 phba->fcf.current_rec.fabric_name[4],
978 phba->fcf.current_rec.fabric_name[5],
979 phba->fcf.current_rec.fabric_name[6],
980 phba->fcf.current_rec.fabric_name[7]);
981 lpfc_nlp_put(ndlp);
982 spin_lock_irq(&phba->hbalock);
983 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400984 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -0400985 spin_unlock_irq(&phba->hbalock);
986 goto out;
987 }
James Smart0c9ab6f2010-02-26 14:15:57 -0500988 if (!rc) {
989 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400990 if (phba->hba_flag & HBA_FIP_SUPPORT)
991 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
992 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400993 "2769 FLOGI to FCF (x%x) "
994 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -0400995 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500996 spin_lock_irq(&phba->hbalock);
997 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400998 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -0500999 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001000 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001001 }
dea31012005-04-17 16:05:31 -05001002 }
1003
1004flogifail:
James Smart329f9bc2007-04-25 09:53:01 -04001005 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001006
James Smart858c9f62007-06-17 19:56:39 -05001007 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001008 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001009 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001010
1011 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001012 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001013 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1014 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
1015 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
1016 (phba->link_state != LPFC_CLEAR_LA)) {
1017 /* If FLOGI failed enable link interrupt. */
1018 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001019 }
dea31012005-04-17 16:05:31 -05001020out:
1021 lpfc_els_free_iocb(phba, cmdiocb);
1022}
1023
James Smarte59058c2008-08-24 21:49:00 -04001024/**
James Smart3621a712009-04-06 18:47:14 -04001025 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001026 * @vport: pointer to a host virtual N_Port data structure.
1027 * @ndlp: pointer to a node-list data structure.
1028 * @retry: number of retries to the command IOCB.
1029 *
1030 * This routine issues a Fabric Login (FLOGI) Request ELS command
1031 * for a @vport. The initiator service parameters are put into the payload
1032 * of the FLOGI Request IOCB and the top-level callback function pointer
1033 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1034 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1035 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1036 *
1037 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1038 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1039 * will be stored into the context1 field of the IOCB for the completion
1040 * callback function to the FLOGI ELS command.
1041 *
1042 * Return code
1043 * 0 - successfully issued flogi iocb for @vport
1044 * 1 - failed to issue flogi iocb for @vport
1045 **/
dea31012005-04-17 16:05:31 -05001046static int
James Smart2e0fef82007-06-17 19:56:36 -05001047lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001048 uint8_t retry)
1049{
James Smart2e0fef82007-06-17 19:56:36 -05001050 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001051 struct serv_parm *sp;
1052 IOCB_t *icmd;
1053 struct lpfc_iocbq *elsiocb;
1054 struct lpfc_sli_ring *pring;
1055 uint8_t *pcmd;
1056 uint16_t cmdsize;
1057 uint32_t tmo;
1058 int rc;
1059
1060 pring = &phba->sli.ring[LPFC_ELS_RING];
1061
James Smart92d7f7b2007-06-17 19:56:38 -05001062 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001063 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1064 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001065
James Smart488d1462006-03-07 15:02:37 -05001066 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001067 return 1;
dea31012005-04-17 16:05:31 -05001068
1069 icmd = &elsiocb->iocb;
1070 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1071
1072 /* For FLOGI request, remainder of payload is service parameters */
1073 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001074 pcmd += sizeof(uint32_t);
1075 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001076 sp = (struct serv_parm *) pcmd;
1077
1078 /* Setup CSPs accordingly for Fabric */
1079 sp->cmn.e_d_tov = 0;
1080 sp->cmn.w2.r_a_tov = 0;
1081 sp->cls1.classValid = 0;
1082 sp->cls2.seqDelivery = 1;
1083 sp->cls3.seqDelivery = 1;
1084 if (sp->cmn.fcphLow < FC_PH3)
1085 sp->cmn.fcphLow = FC_PH3;
1086 if (sp->cmn.fcphHigh < FC_PH3)
1087 sp->cmn.fcphHigh = FC_PH3;
1088
James Smartc31098c2011-04-16 11:03:33 -04001089 if (phba->sli_rev == LPFC_SLI_REV4) {
1090 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1091 LPFC_SLI_INTF_IF_TYPE_0) {
1092 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1093 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1094 /* FLOGI needs to be 3 for WQE FCFI */
1095 /* Set the fcfi to the fcfi we registered with */
1096 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1097 }
James Smart6fb120a2009-05-22 14:52:59 -04001098 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001099 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001100 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1101 icmd->ulpCt_h = 1;
1102 icmd->ulpCt_l = 0;
1103 }
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;
3658 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3659 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3660 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003661 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003662
3663 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3664 "Issue ACC: did:x%x flg:x%x",
3665 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003666 break;
3667 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003668 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003669 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3670 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003671 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003672 return 1;
James Smart488d1462006-03-07 15:02:37 -05003673
dea31012005-04-17 16:05:31 -05003674 icmd = &elsiocb->iocb;
3675 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3676 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3677
3678 if (mbox)
3679 elsiocb->context_un.mbox = mbox;
3680
3681 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003682 pcmd += sizeof(uint32_t);
3683 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003684
3685 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3686 "Issue ACC PLOGI: did:x%x flg:x%x",
3687 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003688 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003689 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003690 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003691 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003692 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3693 if (!elsiocb)
3694 return 1;
3695
3696 icmd = &elsiocb->iocb;
3697 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3698 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3699
3700 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003701 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003702 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3703 els_pkt_ptr = (ELS_PKT *) pcmd;
3704 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003705
3706 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3707 "Issue ACC PRLO: did:x%x flg:x%x",
3708 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003709 break;
dea31012005-04-17 16:05:31 -05003710 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003711 return 1;
dea31012005-04-17 16:05:31 -05003712 }
dea31012005-04-17 16:05:31 -05003713 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003714 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3715 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3716 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3717 elsiocb->iotag, elsiocb->iocb.ulpContext,
3718 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3719 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003720 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003721 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003722 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003723 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003724 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3725 } else {
James Smart858c9f62007-06-17 19:56:39 -05003726 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003727 }
3728
3729 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003730 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003731 if (rc == IOCB_ERROR) {
3732 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003733 return 1;
dea31012005-04-17 16:05:31 -05003734 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003735 return 0;
dea31012005-04-17 16:05:31 -05003736}
3737
James Smarte59058c2008-08-24 21:49:00 -04003738/**
James Smart3621a712009-04-06 18:47:14 -04003739 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003740 * @vport: pointer to a virtual N_Port data structure.
3741 * @rejectError:
3742 * @oldiocb: pointer to the original lpfc command iocb data structure.
3743 * @ndlp: pointer to a node-list data structure.
3744 * @mbox: pointer to the driver internal queue element for mailbox command.
3745 *
3746 * This routine prepares and issue an Reject (RJT) response IOCB
3747 * command. If a @mbox pointer is passed in, it will be put into the
3748 * context_un.mbox field of the IOCB for the completion callback function
3749 * to issue to the HBA later.
3750 *
3751 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3752 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3753 * will be stored into the context1 field of the IOCB for the completion
3754 * callback function to the reject response ELS IOCB command.
3755 *
3756 * Return code
3757 * 0 - Successfully issued reject response
3758 * 1 - Failed to issue reject response
3759 **/
dea31012005-04-17 16:05:31 -05003760int
James Smart2e0fef82007-06-17 19:56:36 -05003761lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003762 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3763 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003764{
James Smart2e0fef82007-06-17 19:56:36 -05003765 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003766 IOCB_t *icmd;
3767 IOCB_t *oldcmd;
3768 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003769 struct lpfc_sli *psli;
3770 uint8_t *pcmd;
3771 uint16_t cmdsize;
3772 int rc;
3773
3774 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003775 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003776 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3777 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003778 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003779 return 1;
dea31012005-04-17 16:05:31 -05003780
3781 icmd = &elsiocb->iocb;
3782 oldcmd = &oldiocb->iocb;
3783 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3784 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3785
3786 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003787 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003788 *((uint32_t *) (pcmd)) = rejectError;
3789
James Smart51ef4c22007-08-02 11:10:31 -04003790 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003791 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003792
dea31012005-04-17 16:05:31 -05003793 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003794 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3795 "0129 Xmit ELS RJT x%x response tag x%x "
3796 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3797 "rpi x%x\n",
3798 rejectError, elsiocb->iotag,
3799 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3800 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003801 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3802 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3803 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3804
dea31012005-04-17 16:05:31 -05003805 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003806 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003807 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003808
dea31012005-04-17 16:05:31 -05003809 if (rc == IOCB_ERROR) {
3810 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003811 return 1;
dea31012005-04-17 16:05:31 -05003812 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003813 return 0;
dea31012005-04-17 16:05:31 -05003814}
3815
James Smarte59058c2008-08-24 21:49:00 -04003816/**
James Smart3621a712009-04-06 18:47:14 -04003817 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003818 * @vport: pointer to a virtual N_Port data structure.
3819 * @oldiocb: pointer to the original lpfc command iocb data structure.
3820 * @ndlp: pointer to a node-list data structure.
3821 *
3822 * This routine prepares and issues an Accept (ACC) response to Address
3823 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3824 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3825 *
3826 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3827 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3828 * will be stored into the context1 field of the IOCB for the completion
3829 * callback function to the ADISC Accept response ELS IOCB command.
3830 *
3831 * Return code
3832 * 0 - Successfully issued acc adisc response
3833 * 1 - Failed to issue adisc acc response
3834 **/
dea31012005-04-17 16:05:31 -05003835int
James Smart2e0fef82007-06-17 19:56:36 -05003836lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3837 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003838{
James Smart2e0fef82007-06-17 19:56:36 -05003839 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003840 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003841 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003842 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003843 uint8_t *pcmd;
3844 uint16_t cmdsize;
3845 int rc;
3846
James Smart92d7f7b2007-06-17 19:56:38 -05003847 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003848 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3849 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003850 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003851 return 1;
dea31012005-04-17 16:05:31 -05003852
dea31012005-04-17 16:05:31 -05003853 icmd = &elsiocb->iocb;
3854 oldcmd = &oldiocb->iocb;
3855 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003856
3857 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003858 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3859 "0130 Xmit ADISC ACC response iotag x%x xri: "
3860 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3861 elsiocb->iotag, elsiocb->iocb.ulpContext,
3862 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3863 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003864 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3865
3866 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003867 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003868
3869 ap = (ADISC *) (pcmd);
3870 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003871 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3872 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003873 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003874
James Smart858c9f62007-06-17 19:56:39 -05003875 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3876 "Issue ACC ADISC: did:x%x flg:x%x",
3877 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3878
dea31012005-04-17 16:05:31 -05003879 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003880 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003881 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003882 if (rc == IOCB_ERROR) {
3883 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003884 return 1;
dea31012005-04-17 16:05:31 -05003885 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003886 return 0;
dea31012005-04-17 16:05:31 -05003887}
3888
James Smarte59058c2008-08-24 21:49:00 -04003889/**
James Smart3621a712009-04-06 18:47:14 -04003890 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003891 * @vport: pointer to a virtual N_Port data structure.
3892 * @oldiocb: pointer to the original lpfc command iocb data structure.
3893 * @ndlp: pointer to a node-list data structure.
3894 *
3895 * This routine prepares and issues an Accept (ACC) response to Process
3896 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3897 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3898 *
3899 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3900 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3901 * will be stored into the context1 field of the IOCB for the completion
3902 * callback function to the PRLI Accept response ELS IOCB command.
3903 *
3904 * Return code
3905 * 0 - Successfully issued acc prli response
3906 * 1 - Failed to issue acc prli response
3907 **/
dea31012005-04-17 16:05:31 -05003908int
James Smart2e0fef82007-06-17 19:56:36 -05003909lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003910 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003911{
James Smart2e0fef82007-06-17 19:56:36 -05003912 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003913 PRLI *npr;
3914 lpfc_vpd_t *vpd;
3915 IOCB_t *icmd;
3916 IOCB_t *oldcmd;
3917 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003918 struct lpfc_sli *psli;
3919 uint8_t *pcmd;
3920 uint16_t cmdsize;
3921 int rc;
3922
3923 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003924
James Smart92d7f7b2007-06-17 19:56:38 -05003925 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003926 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003927 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003928 if (!elsiocb)
3929 return 1;
dea31012005-04-17 16:05:31 -05003930
dea31012005-04-17 16:05:31 -05003931 icmd = &elsiocb->iocb;
3932 oldcmd = &oldiocb->iocb;
3933 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003934 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003935 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3936 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3937 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3938 elsiocb->iotag, elsiocb->iocb.ulpContext,
3939 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3940 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003941 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3942
3943 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003944 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003945
3946 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003947 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003948
3949 npr = (PRLI *) pcmd;
3950 vpd = &phba->vpd;
3951 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003952 * If the remote port is a target and our firmware version is 3.20 or
3953 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003954 */
James Smart0d2b6b82008-06-14 22:52:47 -04003955 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3956 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003957 npr->ConfmComplAllowed = 1;
3958 npr->Retry = 1;
3959 npr->TaskRetryIdReq = 1;
3960 }
3961
3962 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3963 npr->estabImagePair = 1;
3964 npr->readXferRdyDis = 1;
3965 npr->ConfmComplAllowed = 1;
3966
3967 npr->prliType = PRLI_FCP_TYPE;
3968 npr->initiatorFunc = 1;
3969
James Smart858c9f62007-06-17 19:56:39 -05003970 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3971 "Issue ACC PRLI: did:x%x flg:x%x",
3972 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3973
dea31012005-04-17 16:05:31 -05003974 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003975 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003976
James Smart3772a992009-05-22 14:50:54 -04003977 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003978 if (rc == IOCB_ERROR) {
3979 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003980 return 1;
dea31012005-04-17 16:05:31 -05003981 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003982 return 0;
dea31012005-04-17 16:05:31 -05003983}
3984
James Smarte59058c2008-08-24 21:49:00 -04003985/**
James Smart3621a712009-04-06 18:47:14 -04003986 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003987 * @vport: pointer to a virtual N_Port data structure.
3988 * @format: rnid command format.
3989 * @oldiocb: pointer to the original lpfc command iocb data structure.
3990 * @ndlp: pointer to a node-list data structure.
3991 *
3992 * This routine issues a Request Node Identification Data (RNID) Accept
3993 * (ACC) response. It constructs the RNID ACC response command according to
3994 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3995 * issue the response. Note that this command does not need to hold the ndlp
3996 * reference count for the callback. So, the ndlp reference count taken by
3997 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3998 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3999 * there is no ndlp reference available.
4000 *
4001 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4002 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4003 * will be stored into the context1 field of the IOCB for the completion
4004 * callback function. However, for the RNID Accept Response ELS command,
4005 * this is undone later by this routine after the IOCB is allocated.
4006 *
4007 * Return code
4008 * 0 - Successfully issued acc rnid response
4009 * 1 - Failed to issue acc rnid response
4010 **/
dea31012005-04-17 16:05:31 -05004011static int
James Smart2e0fef82007-06-17 19:56:36 -05004012lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004013 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004014{
James Smart2e0fef82007-06-17 19:56:36 -05004015 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004016 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004017 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004018 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004019 struct lpfc_sli *psli;
4020 uint8_t *pcmd;
4021 uint16_t cmdsize;
4022 int rc;
4023
4024 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004025 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4026 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004027 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004028 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004029
James Smart2e0fef82007-06-17 19:56:36 -05004030 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4031 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004032 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004033 return 1;
dea31012005-04-17 16:05:31 -05004034
dea31012005-04-17 16:05:31 -05004035 icmd = &elsiocb->iocb;
4036 oldcmd = &oldiocb->iocb;
4037 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04004038 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004039 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4040 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4041 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004042 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004043 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004044 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004045
James Smart92d7f7b2007-06-17 19:56:38 -05004046 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004047 rn = (RNID *) (pcmd);
4048 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004049 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4050 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4051 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004052 switch (format) {
4053 case 0:
4054 rn->SpecificLen = 0;
4055 break;
4056 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004057 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004058 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004059 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004060 rn->un.topologyDisc.unitType = RNID_HBA;
4061 rn->un.topologyDisc.physPort = 0;
4062 rn->un.topologyDisc.attachedNodes = 0;
4063 break;
4064 default:
4065 rn->CommonLen = 0;
4066 rn->SpecificLen = 0;
4067 break;
4068 }
4069
James Smart858c9f62007-06-17 19:56:39 -05004070 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4071 "Issue ACC RNID: did:x%x flg:x%x",
4072 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4073
dea31012005-04-17 16:05:31 -05004074 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004075 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04004076 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004077 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
4078 * it could be freed */
4079
James Smart3772a992009-05-22 14:50:54 -04004080 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004081 if (rc == IOCB_ERROR) {
4082 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004083 return 1;
dea31012005-04-17 16:05:31 -05004084 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004085 return 0;
dea31012005-04-17 16:05:31 -05004086}
4087
James Smarte59058c2008-08-24 21:49:00 -04004088/**
James Smart19ca7602010-11-20 23:11:55 -05004089 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4090 * @vport: pointer to a virtual N_Port data structure.
4091 * @iocb: pointer to the lpfc command iocb data structure.
4092 * @ndlp: pointer to a node-list data structure.
4093 *
4094 * Return
4095 **/
4096static void
4097lpfc_els_clear_rrq(struct lpfc_vport *vport,
4098 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4099{
4100 struct lpfc_hba *phba = vport->phba;
4101 uint8_t *pcmd;
4102 struct RRQ *rrq;
4103 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004104 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004105 struct lpfc_node_rrq *prrq;
4106
4107
4108 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4109 pcmd += sizeof(uint32_t);
4110 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004111 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b0622011-04-16 11:03:17 -04004112 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004113
4114 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4115 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4116 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004117 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b0622011-04-16 11:03:17 -04004118 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004119 rxid,
4120 iocb->iotag, iocb->iocb.ulpContext);
4121
4122 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4123 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4124 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004125 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b0622011-04-16 11:03:17 -04004126 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004127 else
4128 xri = rxid;
4129 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004130 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004131 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004132 return;
4133}
4134
4135/**
James Smart12265f62010-10-22 11:05:53 -04004136 * lpfc_els_rsp_echo_acc - Issue echo acc response
4137 * @vport: pointer to a virtual N_Port data structure.
4138 * @data: pointer to echo data to return in the accept.
4139 * @oldiocb: pointer to the original lpfc command iocb data structure.
4140 * @ndlp: pointer to a node-list data structure.
4141 *
4142 * Return code
4143 * 0 - Successfully issued acc echo response
4144 * 1 - Failed to issue acc echo response
4145 **/
4146static int
4147lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4148 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4149{
4150 struct lpfc_hba *phba = vport->phba;
4151 struct lpfc_iocbq *elsiocb;
4152 struct lpfc_sli *psli;
4153 uint8_t *pcmd;
4154 uint16_t cmdsize;
4155 int rc;
4156
4157 psli = &phba->sli;
4158 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4159
4160 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4161 ndlp->nlp_DID, ELS_CMD_ACC);
4162 if (!elsiocb)
4163 return 1;
4164
4165 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */
4166 /* Xmit ECHO ACC response tag <ulpIoTag> */
4167 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4168 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4169 elsiocb->iotag, elsiocb->iocb.ulpContext);
4170 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4171 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4172 pcmd += sizeof(uint32_t);
4173 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4174
4175 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4176 "Issue ACC ECHO: did:x%x flg:x%x",
4177 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4178
4179 phba->fc_stat.elsXmitACC++;
4180 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4181 lpfc_nlp_put(ndlp);
4182 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
4183 * it could be freed */
4184
4185 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4186 if (rc == IOCB_ERROR) {
4187 lpfc_els_free_iocb(phba, elsiocb);
4188 return 1;
4189 }
4190 return 0;
4191}
4192
4193/**
James Smart3621a712009-04-06 18:47:14 -04004194 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004195 * @vport: pointer to a host virtual N_Port data structure.
4196 *
4197 * This routine issues Address Discover (ADISC) ELS commands to those
4198 * N_Ports which are in node port recovery state and ADISC has not been issued
4199 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4200 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4201 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4202 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4203 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4204 * IOCBs quit for later pick up. On the other hand, after walking through
4205 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4206 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4207 * no more ADISC need to be sent.
4208 *
4209 * Return code
4210 * The number of N_Ports with adisc issued.
4211 **/
dea31012005-04-17 16:05:31 -05004212int
James Smart2e0fef82007-06-17 19:56:36 -05004213lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004214{
James Smart2e0fef82007-06-17 19:56:36 -05004215 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004216 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004217 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004218
James Smart685f0bf2007-04-25 09:53:08 -04004219 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004220 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004221 if (!NLP_CHK_NODE_ACT(ndlp))
4222 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004223 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4224 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4225 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004226 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004227 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004228 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004229 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004230 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4231 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004232 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004233 vport->num_disc_nodes++;
4234 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004235 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004236 spin_lock_irq(shost->host_lock);
4237 vport->fc_flag |= FC_NLP_MORE;
4238 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004239 break;
dea31012005-04-17 16:05:31 -05004240 }
4241 }
4242 }
4243 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004244 spin_lock_irq(shost->host_lock);
4245 vport->fc_flag &= ~FC_NLP_MORE;
4246 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004247 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004248 return sentadisc;
dea31012005-04-17 16:05:31 -05004249}
4250
James Smarte59058c2008-08-24 21:49:00 -04004251/**
James Smart3621a712009-04-06 18:47:14 -04004252 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004253 * @vport: pointer to a host virtual N_Port data structure.
4254 *
4255 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4256 * which are in node port recovery state, with a @vport. Each time an ELS
4257 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4258 * the per @vport number of discover count (num_disc_nodes) shall be
4259 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4260 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4261 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4262 * later pick up. On the other hand, after walking through all the ndlps with
4263 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4264 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4265 * PLOGI need to be sent.
4266 *
4267 * Return code
4268 * The number of N_Ports with plogi issued.
4269 **/
dea31012005-04-17 16:05:31 -05004270int
James Smart2e0fef82007-06-17 19:56:36 -05004271lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004272{
James Smart2e0fef82007-06-17 19:56:36 -05004273 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004274 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004275 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004276
James Smart2e0fef82007-06-17 19:56:36 -05004277 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4278 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004279 if (!NLP_CHK_NODE_ACT(ndlp))
4280 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004281 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4282 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4283 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4284 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4285 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004286 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4287 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004288 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004289 vport->num_disc_nodes++;
4290 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004291 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004292 spin_lock_irq(shost->host_lock);
4293 vport->fc_flag |= FC_NLP_MORE;
4294 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004295 break;
dea31012005-04-17 16:05:31 -05004296 }
4297 }
4298 }
James Smart87af33f2007-10-27 13:37:43 -04004299 if (sentplogi) {
4300 lpfc_set_disctmo(vport);
4301 }
4302 else {
James Smart2e0fef82007-06-17 19:56:36 -05004303 spin_lock_irq(shost->host_lock);
4304 vport->fc_flag &= ~FC_NLP_MORE;
4305 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004306 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004307 return sentplogi;
dea31012005-04-17 16:05:31 -05004308}
4309
James Smarte59058c2008-08-24 21:49:00 -04004310/**
James Smart3621a712009-04-06 18:47:14 -04004311 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004312 * @vport: pointer to a host virtual N_Port data structure.
4313 *
4314 * This routine cleans up any Registration State Change Notification
4315 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4316 * @vport together with the host_lock is used to prevent multiple thread
4317 * trying to access the RSCN array on a same @vport at the same time.
4318 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004319void
James Smart2e0fef82007-06-17 19:56:36 -05004320lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004321{
James Smart2e0fef82007-06-17 19:56:36 -05004322 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4323 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004324 int i;
4325
James Smart7f5f3d02008-02-08 18:50:14 -05004326 spin_lock_irq(shost->host_lock);
4327 if (vport->fc_rscn_flush) {
4328 /* Another thread is walking fc_rscn_id_list on this vport */
4329 spin_unlock_irq(shost->host_lock);
4330 return;
4331 }
4332 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4333 vport->fc_rscn_flush = 1;
4334 spin_unlock_irq(shost->host_lock);
4335
James Smart2e0fef82007-06-17 19:56:36 -05004336 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004337 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004338 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004339 }
James Smart2e0fef82007-06-17 19:56:36 -05004340 spin_lock_irq(shost->host_lock);
4341 vport->fc_rscn_id_cnt = 0;
4342 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4343 spin_unlock_irq(shost->host_lock);
4344 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004345 /* Indicate we are done walking this fc_rscn_id_list */
4346 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004347}
4348
James Smarte59058c2008-08-24 21:49:00 -04004349/**
James Smart3621a712009-04-06 18:47:14 -04004350 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004351 * @vport: pointer to a host virtual N_Port data structure.
4352 * @did: remote destination port identifier.
4353 *
4354 * This routine checks whether there is any pending Registration State
4355 * Configuration Notification (RSCN) to a @did on @vport.
4356 *
4357 * Return code
4358 * None zero - The @did matched with a pending rscn
4359 * 0 - not able to match @did with a pending rscn
4360 **/
dea31012005-04-17 16:05:31 -05004361int
James Smart2e0fef82007-06-17 19:56:36 -05004362lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004363{
4364 D_ID ns_did;
4365 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004366 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004367 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004368 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004369
4370 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004371
4372 /* Never match fabric nodes for RSCNs */
4373 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004374 return 0;
dea31012005-04-17 16:05:31 -05004375
4376 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004377 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004378 return did;
dea31012005-04-17 16:05:31 -05004379
James Smart7f5f3d02008-02-08 18:50:14 -05004380 spin_lock_irq(shost->host_lock);
4381 if (vport->fc_rscn_flush) {
4382 /* Another thread is walking fc_rscn_id_list on this vport */
4383 spin_unlock_irq(shost->host_lock);
4384 return 0;
4385 }
4386 /* Indicate we are walking fc_rscn_id_list on this vport */
4387 vport->fc_rscn_flush = 1;
4388 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004389 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004390 lp = vport->fc_rscn_id_list[i]->virt;
4391 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4392 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004393 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004394 rscn_did.un.word = be32_to_cpu(*lp++);
4395 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004396 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4397 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004398 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4399 && (ns_did.un.b.area == rscn_did.un.b.area)
4400 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004401 goto return_did_out;
dea31012005-04-17 16:05:31 -05004402 break;
James Smarteaf15d52008-12-04 22:39:29 -05004403 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004404 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4405 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004406 goto return_did_out;
dea31012005-04-17 16:05:31 -05004407 break;
James Smarteaf15d52008-12-04 22:39:29 -05004408 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004409 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004410 goto return_did_out;
dea31012005-04-17 16:05:31 -05004411 break;
James Smarteaf15d52008-12-04 22:39:29 -05004412 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004413 goto return_did_out;
dea31012005-04-17 16:05:31 -05004414 }
4415 }
James Smart92d7f7b2007-06-17 19:56:38 -05004416 }
James Smart7f5f3d02008-02-08 18:50:14 -05004417 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4418 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004419 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004420return_did_out:
4421 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4422 vport->fc_rscn_flush = 0;
4423 return did;
dea31012005-04-17 16:05:31 -05004424}
4425
James Smarte59058c2008-08-24 21:49:00 -04004426/**
James Smart3621a712009-04-06 18:47:14 -04004427 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004428 * @vport: pointer to a host virtual N_Port data structure.
4429 *
4430 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4431 * state machine for a @vport's nodes that are with pending RSCN (Registration
4432 * State Change Notification).
4433 *
4434 * Return code
4435 * 0 - Successful (currently alway return 0)
4436 **/
dea31012005-04-17 16:05:31 -05004437static int
James Smart2e0fef82007-06-17 19:56:36 -05004438lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004439{
James Smart685f0bf2007-04-25 09:53:08 -04004440 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004441
James Smart0d2b6b82008-06-14 22:52:47 -04004442 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004443 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004444 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004445 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4446 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004447 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004448 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004449 NLP_EVT_DEVICE_RECOVERY);
4450 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004451 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004452 return 0;
dea31012005-04-17 16:05:31 -05004453}
4454
James Smarte59058c2008-08-24 21:49:00 -04004455/**
James Smart3621a712009-04-06 18:47:14 -04004456 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004457 * @vport: pointer to a host virtual N_Port data structure.
4458 * @cmdiocb: pointer to lpfc command iocb data structure.
4459 *
4460 * lpfc_send_rscn_event sends an RSCN netlink event to management
4461 * applications.
4462 */
4463static void
4464lpfc_send_rscn_event(struct lpfc_vport *vport,
4465 struct lpfc_iocbq *cmdiocb)
4466{
4467 struct lpfc_dmabuf *pcmd;
4468 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4469 uint32_t *payload_ptr;
4470 uint32_t payload_len;
4471 struct lpfc_rscn_event_header *rscn_event_data;
4472
4473 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4474 payload_ptr = (uint32_t *) pcmd->virt;
4475 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4476
4477 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4478 payload_len, GFP_KERNEL);
4479 if (!rscn_event_data) {
4480 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4481 "0147 Failed to allocate memory for RSCN event\n");
4482 return;
4483 }
4484 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4485 rscn_event_data->payload_length = payload_len;
4486 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4487 payload_len);
4488
4489 fc_host_post_vendor_event(shost,
4490 fc_get_event_number(),
4491 sizeof(struct lpfc_els_event_header) + payload_len,
4492 (char *)rscn_event_data,
4493 LPFC_NL_VENDOR_ID);
4494
4495 kfree(rscn_event_data);
4496}
4497
4498/**
James Smart3621a712009-04-06 18:47:14 -04004499 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004500 * @vport: pointer to a host virtual N_Port data structure.
4501 * @cmdiocb: pointer to lpfc command iocb data structure.
4502 * @ndlp: pointer to a node-list data structure.
4503 *
4504 * This routine processes an unsolicited RSCN (Registration State Change
4505 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4506 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4507 * discover state machine is about to begin discovery, it just accepts the
4508 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4509 * contains N_Port IDs for other vports on this HBA, it just accepts the
4510 * RSCN and ignore processing it. If the state machine is in the recovery
4511 * state, the fc_rscn_id_list of this @vport is walked and the
4512 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4513 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4514 * routine is invoked to handle the RSCN event.
4515 *
4516 * Return code
4517 * 0 - Just sent the acc response
4518 * 1 - Sent the acc response and waited for name server completion
4519 **/
dea31012005-04-17 16:05:31 -05004520static int
James Smart2e0fef82007-06-17 19:56:36 -05004521lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004522 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004523{
James Smart2e0fef82007-06-17 19:56:36 -05004524 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4525 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004526 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004527 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004528 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004529 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004530 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004531 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004532 int i;
dea31012005-04-17 16:05:31 -05004533
4534 icmd = &cmdiocb->iocb;
4535 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4536 lp = (uint32_t *) pcmd->virt;
4537
James Smart92d7f7b2007-06-17 19:56:38 -05004538 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4539 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004540 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004541 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4542 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004543 vport->fc_flag, payload_len, *lp,
4544 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004545
4546 /* Send an RSCN event to the management application */
4547 lpfc_send_rscn_event(vport, cmdiocb);
4548
James Smartd2873e42006-08-18 17:46:43 -04004549 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004550 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004551 FCH_EVT_RSCN, lp[i]);
4552
dea31012005-04-17 16:05:31 -05004553 /* If we are about to begin discovery, just ACC the RSCN.
4554 * Discovery processing will satisfy it.
4555 */
James Smart2e0fef82007-06-17 19:56:36 -05004556 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004557 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4558 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4559 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4560
James Smart51ef4c22007-08-02 11:10:31 -04004561 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004562 return 0;
dea31012005-04-17 16:05:31 -05004563 }
4564
James Smart92d7f7b2007-06-17 19:56:38 -05004565 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4566 * just ACC and ignore it.
4567 */
4568 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004569 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004570 i = payload_len;
4571 datap = lp;
4572 while (i > 0) {
4573 nportid = *datap++;
4574 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4575 i -= sizeof(uint32_t);
4576 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004577 if (lpfc_find_vport_by_did(phba, nportid))
4578 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004579 }
4580 if (rscn_id == hba_id) {
4581 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004582 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004583 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004584 "Data: x%x x%x x%x x%x\n",
4585 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004586 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004587 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4588 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4589 ndlp->nlp_DID, vport->port_state,
4590 ndlp->nlp_flag);
4591
James Smart92d7f7b2007-06-17 19:56:38 -05004592 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004593 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004594 return 0;
4595 }
4596 }
4597
James Smart7f5f3d02008-02-08 18:50:14 -05004598 spin_lock_irq(shost->host_lock);
4599 if (vport->fc_rscn_flush) {
4600 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004601 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004602 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004603 /* Send back ACC */
4604 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004605 return 0;
4606 }
4607 /* Indicate we are walking fc_rscn_id_list on this vport */
4608 vport->fc_rscn_flush = 1;
4609 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004610 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004611 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004612 /* If we are already processing an RSCN, save the received
4613 * RSCN payload buffer, cmdiocb->context2 to process later.
4614 */
James Smart2e0fef82007-06-17 19:56:36 -05004615 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004616 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4617 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4618 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4619
James Smart09372822008-01-11 01:52:54 -05004620 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004621 vport->fc_flag |= FC_RSCN_DEFERRED;
4622 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004623 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004624 vport->fc_flag |= FC_RSCN_MODE;
4625 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004626 if (rscn_cnt) {
4627 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4628 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4629 }
4630 if ((rscn_cnt) &&
4631 (payload_len + length <= LPFC_BPL_SIZE)) {
4632 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004633 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004634 memcpy(((uint8_t *)cmd) + length, lp,
4635 payload_len);
4636 } else {
4637 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4638 vport->fc_rscn_id_cnt++;
4639 /* If we zero, cmdiocb->context2, the calling
4640 * routine will not try to free it.
4641 */
4642 cmdiocb->context2 = NULL;
4643 }
dea31012005-04-17 16:05:31 -05004644 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004645 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4646 "0235 Deferred RSCN "
4647 "Data: x%x x%x x%x\n",
4648 vport->fc_rscn_id_cnt, vport->fc_flag,
4649 vport->port_state);
dea31012005-04-17 16:05:31 -05004650 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004651 vport->fc_flag |= FC_RSCN_DISCOVERY;
4652 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004653 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004654 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4655 "0234 ReDiscovery RSCN "
4656 "Data: x%x x%x x%x\n",
4657 vport->fc_rscn_id_cnt, vport->fc_flag,
4658 vport->port_state);
dea31012005-04-17 16:05:31 -05004659 }
James Smart7f5f3d02008-02-08 18:50:14 -05004660 /* Indicate we are done walking fc_rscn_id_list on this vport */
4661 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004662 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004663 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004664 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004665 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004666 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004667 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004668 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004669 return 0;
dea31012005-04-17 16:05:31 -05004670 }
James Smart858c9f62007-06-17 19:56:39 -05004671 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4672 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4673 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4674
James Smart2e0fef82007-06-17 19:56:36 -05004675 spin_lock_irq(shost->host_lock);
4676 vport->fc_flag |= FC_RSCN_MODE;
4677 spin_unlock_irq(shost->host_lock);
4678 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004679 /* Indicate we are done walking fc_rscn_id_list on this vport */
4680 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004681 /*
4682 * If we zero, cmdiocb->context2, the calling routine will
4683 * not try to free it.
4684 */
4685 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004686 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004687 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004688 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004689 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004690 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004691 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004692}
4693
James Smarte59058c2008-08-24 21:49:00 -04004694/**
James Smart3621a712009-04-06 18:47:14 -04004695 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004696 * @vport: pointer to a host virtual N_Port data structure.
4697 *
4698 * This routine handles the Registration State Configuration Notification
4699 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4700 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4701 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4702 * NameServer shall be issued. If CT command to the NameServer fails to be
4703 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4704 * RSCN activities with the @vport.
4705 *
4706 * Return code
4707 * 0 - Cleaned up rscn on the @vport
4708 * 1 - Wait for plogi to name server before proceed
4709 **/
dea31012005-04-17 16:05:31 -05004710int
James Smart2e0fef82007-06-17 19:56:36 -05004711lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004712{
4713 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004714 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004715
James Smart92d7f7b2007-06-17 19:56:38 -05004716 /* Ignore RSCN if the port is being torn down. */
4717 if (vport->load_flag & FC_UNLOADING) {
4718 lpfc_els_flush_rscn(vport);
4719 return 0;
4720 }
4721
dea31012005-04-17 16:05:31 -05004722 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004723 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004724
4725 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004726 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4727 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4728 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4729 vport->port_state);
dea31012005-04-17 16:05:31 -05004730
4731 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004732 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004733 vport->num_disc_nodes = 0;
4734
James Smart2e0fef82007-06-17 19:56:36 -05004735 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004736 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4737 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004738 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004739 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004740 /* Wait for NameServer query cmpl before we can
4741 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004742 return 1;
dea31012005-04-17 16:05:31 -05004743 } else {
4744 /* If login to NameServer does not exist, issue one */
4745 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004746 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004747 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004748 /* Wait for NameServer login cmpl before we can
4749 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004750 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004751
James Smarte47c9092008-02-08 18:49:26 -05004752 if (ndlp) {
4753 ndlp = lpfc_enable_node(vport, ndlp,
4754 NLP_STE_PLOGI_ISSUE);
4755 if (!ndlp) {
4756 lpfc_els_flush_rscn(vport);
4757 return 0;
4758 }
4759 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004760 } else {
James Smarte47c9092008-02-08 18:49:26 -05004761 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4762 if (!ndlp) {
4763 lpfc_els_flush_rscn(vport);
4764 return 0;
4765 }
James Smart2e0fef82007-06-17 19:56:36 -05004766 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004767 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004768 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004769 }
James Smarte47c9092008-02-08 18:49:26 -05004770 ndlp->nlp_type |= NLP_FABRIC;
4771 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4772 /* Wait for NameServer login cmpl before we can
4773 * continue
4774 */
4775 return 1;
dea31012005-04-17 16:05:31 -05004776 }
4777
James Smart2e0fef82007-06-17 19:56:36 -05004778 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004779 return 0;
dea31012005-04-17 16:05:31 -05004780}
4781
James Smarte59058c2008-08-24 21:49:00 -04004782/**
James Smart3621a712009-04-06 18:47:14 -04004783 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004784 * @vport: pointer to a host virtual N_Port data structure.
4785 * @cmdiocb: pointer to lpfc command iocb data structure.
4786 * @ndlp: pointer to a node-list data structure.
4787 *
4788 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4789 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4790 * point topology. As an unsolicited FLOGI should not be received in a loop
4791 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4792 * lpfc_check_sparm() routine is invoked to check the parameters in the
4793 * unsolicited FLOGI. If parameters validation failed, the routine
4794 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4795 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4796 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4797 * will initiate PLOGI. The higher lexicographical value party shall has
4798 * higher priority (as the winning port) and will initiate PLOGI and
4799 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4800 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4801 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4802 *
4803 * Return code
4804 * 0 - Successfully processed the unsolicited flogi
4805 * 1 - Failed to process the unsolicited flogi
4806 **/
dea31012005-04-17 16:05:31 -05004807static int
James Smart2e0fef82007-06-17 19:56:36 -05004808lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004809 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004810{
James Smart2e0fef82007-06-17 19:56:36 -05004811 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4812 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004813 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4814 uint32_t *lp = (uint32_t *) pcmd->virt;
4815 IOCB_t *icmd = &cmdiocb->iocb;
4816 struct serv_parm *sp;
4817 LPFC_MBOXQ_t *mbox;
4818 struct ls_rjt stat;
4819 uint32_t cmd, did;
4820 int rc;
4821
4822 cmd = *lp++;
4823 sp = (struct serv_parm *) lp;
4824
4825 /* FLOGI received */
4826
James Smart2e0fef82007-06-17 19:56:36 -05004827 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004828
James Smart76a95d72010-11-20 23:11:48 -05004829 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004830 /* We should never receive a FLOGI in loop mode, ignore it */
4831 did = icmd->un.elsreq64.remoteID;
4832
4833 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4834 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004835 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4836 "0113 An FLOGI ELS command x%x was "
4837 "received from DID x%x in Loop Mode\n",
4838 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004839 return 1;
dea31012005-04-17 16:05:31 -05004840 }
4841
4842 did = Fabric_DID;
4843
James Smart341af102010-01-26 23:07:37 -05004844 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004845 /* For a FLOGI we accept, then if our portname is greater
4846 * then the remote portname we initiate Nport login.
4847 */
4848
James Smart2e0fef82007-06-17 19:56:36 -05004849 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004850 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004851
4852 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004853 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4854 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004855 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004856
dea31012005-04-17 16:05:31 -05004857 lpfc_linkdown(phba);
4858 lpfc_init_link(phba, mbox,
4859 phba->cfg_topology,
4860 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004861 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004862 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004863 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004864 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004865 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004866 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004867 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004868 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004869 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004870 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004871 spin_lock_irq(shost->host_lock);
4872 vport->fc_flag |= FC_PT2PT_PLOGI;
4873 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004874 }
James Smart2e0fef82007-06-17 19:56:36 -05004875 spin_lock_irq(shost->host_lock);
4876 vport->fc_flag |= FC_PT2PT;
4877 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4878 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004879 } else {
4880 /* Reject this request because invalid parameters */
4881 stat.un.b.lsRjtRsvd0 = 0;
4882 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4883 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4884 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004885 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4886 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004887 return 1;
dea31012005-04-17 16:05:31 -05004888 }
4889
4890 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004891 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004892
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004893 return 0;
dea31012005-04-17 16:05:31 -05004894}
4895
James Smarte59058c2008-08-24 21:49:00 -04004896/**
James Smart3621a712009-04-06 18:47:14 -04004897 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004898 * @vport: pointer to a host virtual N_Port data structure.
4899 * @cmdiocb: pointer to lpfc command iocb data structure.
4900 * @ndlp: pointer to a node-list data structure.
4901 *
4902 * This routine processes Request Node Identification Data (RNID) IOCB
4903 * received as an ELS unsolicited event. Only when the RNID specified format
4904 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4905 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4906 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4907 * rejected by invoking the lpfc_els_rsp_reject() routine.
4908 *
4909 * Return code
4910 * 0 - Successfully processed rnid iocb (currently always return 0)
4911 **/
dea31012005-04-17 16:05:31 -05004912static int
James Smart2e0fef82007-06-17 19:56:36 -05004913lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4914 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004915{
4916 struct lpfc_dmabuf *pcmd;
4917 uint32_t *lp;
4918 IOCB_t *icmd;
4919 RNID *rn;
4920 struct ls_rjt stat;
4921 uint32_t cmd, did;
4922
4923 icmd = &cmdiocb->iocb;
4924 did = icmd->un.elsreq64.remoteID;
4925 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4926 lp = (uint32_t *) pcmd->virt;
4927
4928 cmd = *lp++;
4929 rn = (RNID *) lp;
4930
4931 /* RNID received */
4932
4933 switch (rn->Format) {
4934 case 0:
4935 case RNID_TOPOLOGY_DISC:
4936 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004937 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004938 break;
4939 default:
4940 /* Reject this request because format not supported */
4941 stat.un.b.lsRjtRsvd0 = 0;
4942 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4943 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4944 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004945 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4946 NULL);
dea31012005-04-17 16:05:31 -05004947 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004948 return 0;
dea31012005-04-17 16:05:31 -05004949}
4950
James Smarte59058c2008-08-24 21:49:00 -04004951/**
James Smart12265f62010-10-22 11:05:53 -04004952 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4953 * @vport: pointer to a host virtual N_Port data structure.
4954 * @cmdiocb: pointer to lpfc command iocb data structure.
4955 * @ndlp: pointer to a node-list data structure.
4956 *
4957 * Return code
4958 * 0 - Successfully processed echo iocb (currently always return 0)
4959 **/
4960static int
4961lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4962 struct lpfc_nodelist *ndlp)
4963{
4964 uint8_t *pcmd;
4965
4966 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4967
4968 /* skip over first word of echo command to find echo data */
4969 pcmd += sizeof(uint32_t);
4970
4971 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
4972 return 0;
4973}
4974
4975/**
James Smart3621a712009-04-06 18:47:14 -04004976 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004977 * @vport: pointer to a host virtual N_Port data structure.
4978 * @cmdiocb: pointer to lpfc command iocb data structure.
4979 * @ndlp: pointer to a node-list data structure.
4980 *
4981 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4982 * received as an ELS unsolicited event. Currently, this function just invokes
4983 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4984 *
4985 * Return code
4986 * 0 - Successfully processed lirr iocb (currently always return 0)
4987 **/
dea31012005-04-17 16:05:31 -05004988static int
James Smart2e0fef82007-06-17 19:56:36 -05004989lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4990 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004991{
4992 struct ls_rjt stat;
4993
4994 /* For now, unconditionally reject this command */
4995 stat.un.b.lsRjtRsvd0 = 0;
4996 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4997 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4998 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004999 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005000 return 0;
5001}
5002
James Smarte59058c2008-08-24 21:49:00 -04005003/**
James Smart5ffc2662009-11-18 15:39:44 -05005004 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5005 * @vport: pointer to a host virtual N_Port data structure.
5006 * @cmdiocb: pointer to lpfc command iocb data structure.
5007 * @ndlp: pointer to a node-list data structure.
5008 *
5009 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5010 * received as an ELS unsolicited event. A request to RRQ shall only
5011 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5012 * Nx_Port N_Port_ID of the target Exchange is the same as the
5013 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5014 * not accepted, an LS_RJT with reason code "Unable to perform
5015 * command request" and reason code explanation "Invalid Originator
5016 * S_ID" shall be returned. For now, we just unconditionally accept
5017 * RRQ from the target.
5018 **/
5019static void
5020lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5021 struct lpfc_nodelist *ndlp)
5022{
5023 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05005024 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5025 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05005026}
5027
5028/**
James Smart12265f62010-10-22 11:05:53 -04005029 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5030 * @phba: pointer to lpfc hba data structure.
5031 * @pmb: pointer to the driver internal queue element for mailbox command.
5032 *
5033 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5034 * mailbox command. This callback function is to actually send the Accept
5035 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5036 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5037 * mailbox command, constructs the RPS response with the link statistics
5038 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5039 * response to the RPS.
5040 *
5041 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5042 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5043 * will be stored into the context1 field of the IOCB for the completion
5044 * callback function to the RPS Accept Response ELS IOCB command.
5045 *
5046 **/
5047static void
5048lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5049{
5050 MAILBOX_t *mb;
5051 IOCB_t *icmd;
5052 struct RLS_RSP *rls_rsp;
5053 uint8_t *pcmd;
5054 struct lpfc_iocbq *elsiocb;
5055 struct lpfc_nodelist *ndlp;
5056 uint16_t xri;
5057 uint32_t cmdsize;
5058
5059 mb = &pmb->u.mb;
5060
5061 ndlp = (struct lpfc_nodelist *) pmb->context2;
5062 xri = (uint16_t) ((unsigned long)(pmb->context1));
5063 pmb->context1 = NULL;
5064 pmb->context2 = NULL;
5065
5066 if (mb->mbxStatus) {
5067 mempool_free(pmb, phba->mbox_mem_pool);
5068 return;
5069 }
5070
5071 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
5072 mempool_free(pmb, phba->mbox_mem_pool);
5073 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5074 lpfc_max_els_tries, ndlp,
5075 ndlp->nlp_DID, ELS_CMD_ACC);
5076
5077 /* Decrement the ndlp reference count from previous mbox command */
5078 lpfc_nlp_put(ndlp);
5079
5080 if (!elsiocb)
5081 return;
5082
5083 icmd = &elsiocb->iocb;
5084 icmd->ulpContext = xri;
5085
5086 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5087 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5088 pcmd += sizeof(uint32_t); /* Skip past command */
5089 rls_rsp = (struct RLS_RSP *)pcmd;
5090
5091 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5092 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5093 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5094 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5095 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5096 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
5097
5098 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5099 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5100 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5101 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5102 elsiocb->iotag, elsiocb->iocb.ulpContext,
5103 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5104 ndlp->nlp_rpi);
5105 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5106 phba->fc_stat.elsXmitACC++;
5107 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5108 lpfc_els_free_iocb(phba, elsiocb);
5109}
5110
5111/**
James Smart3621a712009-04-06 18:47:14 -04005112 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005113 * @phba: pointer to lpfc hba data structure.
5114 * @pmb: pointer to the driver internal queue element for mailbox command.
5115 *
5116 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5117 * mailbox command. This callback function is to actually send the Accept
5118 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5119 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5120 * mailbox command, constructs the RPS response with the link statistics
5121 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5122 * response to the RPS.
5123 *
5124 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5125 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5126 * will be stored into the context1 field of the IOCB for the completion
5127 * callback function to the RPS Accept Response ELS IOCB command.
5128 *
5129 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005130static void
James Smart329f9bc2007-04-25 09:53:01 -04005131lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005132{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005133 MAILBOX_t *mb;
5134 IOCB_t *icmd;
5135 RPS_RSP *rps_rsp;
5136 uint8_t *pcmd;
5137 struct lpfc_iocbq *elsiocb;
5138 struct lpfc_nodelist *ndlp;
5139 uint16_t xri, status;
5140 uint32_t cmdsize;
5141
James Smart04c68492009-05-22 14:52:52 -04005142 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005143
5144 ndlp = (struct lpfc_nodelist *) pmb->context2;
5145 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07005146 pmb->context1 = NULL;
5147 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005148
5149 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005150 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005151 return;
5152 }
5153
5154 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005155 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005156 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5157 lpfc_max_els_tries, ndlp,
5158 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005159
5160 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005161 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005162
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005163 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005164 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005165
5166 icmd = &elsiocb->iocb;
5167 icmd->ulpContext = xri;
5168
5169 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5170 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005171 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005172 rps_rsp = (RPS_RSP *)pcmd;
5173
James Smart76a95d72010-11-20 23:11:48 -05005174 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005175 status = 0x10;
5176 else
5177 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005178 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005179 status |= 0x4;
5180
5181 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005182 rps_rsp->portStatus = cpu_to_be16(status);
5183 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5184 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5185 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5186 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5187 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5188 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005189 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005190 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5191 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5192 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5193 elsiocb->iotag, elsiocb->iocb.ulpContext,
5194 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5195 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005196 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005197 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005198 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005199 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005200 return;
5201}
5202
James Smarte59058c2008-08-24 21:49:00 -04005203/**
James Smart12265f62010-10-22 11:05:53 -04005204 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5205 * @vport: pointer to a host virtual N_Port data structure.
5206 * @cmdiocb: pointer to lpfc command iocb data structure.
5207 * @ndlp: pointer to a node-list data structure.
5208 *
5209 * This routine processes Read Port Status (RPL) IOCB received as an
5210 * ELS unsolicited event. It first checks the remote port state. If the
5211 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5212 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5213 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5214 * for reading the HBA link statistics. It is for the callback function,
5215 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5216 * to actually sending out RPL Accept (ACC) response.
5217 *
5218 * Return codes
5219 * 0 - Successfully processed rls iocb (currently always return 0)
5220 **/
5221static int
5222lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5223 struct lpfc_nodelist *ndlp)
5224{
5225 struct lpfc_hba *phba = vport->phba;
5226 LPFC_MBOXQ_t *mbox;
5227 struct lpfc_dmabuf *pcmd;
5228 struct ls_rjt stat;
5229
5230 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5231 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5232 /* reject the unsolicited RPS request and done with it */
5233 goto reject_out;
5234
5235 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5236
5237 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5238 if (mbox) {
5239 lpfc_read_lnk_stat(phba, mbox);
5240 mbox->context1 =
5241 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
5242 mbox->context2 = lpfc_nlp_get(ndlp);
5243 mbox->vport = vport;
5244 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5245 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5246 != MBX_NOT_FINISHED)
5247 /* Mbox completion will send ELS Response */
5248 return 0;
5249 /* Decrement reference count used for the failed mbox
5250 * command.
5251 */
5252 lpfc_nlp_put(ndlp);
5253 mempool_free(mbox, phba->mbox_mem_pool);
5254 }
5255reject_out:
5256 /* issue rejection response */
5257 stat.un.b.lsRjtRsvd0 = 0;
5258 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5259 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5260 stat.un.b.vendorUnique = 0;
5261 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5262 return 0;
5263}
5264
5265/**
5266 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5267 * @vport: pointer to a host virtual N_Port data structure.
5268 * @cmdiocb: pointer to lpfc command iocb data structure.
5269 * @ndlp: pointer to a node-list data structure.
5270 *
5271 * This routine processes Read Timout Value (RTV) IOCB received as an
5272 * ELS unsolicited event. It first checks the remote port state. If the
5273 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5274 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5275 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5276 * Value (RTV) unsolicited IOCB event.
5277 *
5278 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5279 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5280 * will be stored into the context1 field of the IOCB for the completion
5281 * callback function to the RPS Accept Response ELS IOCB command.
5282 *
5283 * Return codes
5284 * 0 - Successfully processed rtv iocb (currently always return 0)
5285 **/
5286static int
5287lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5288 struct lpfc_nodelist *ndlp)
5289{
5290 struct lpfc_hba *phba = vport->phba;
5291 struct ls_rjt stat;
5292 struct RTV_RSP *rtv_rsp;
5293 uint8_t *pcmd;
5294 struct lpfc_iocbq *elsiocb;
5295 uint32_t cmdsize;
5296
5297
5298 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5299 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5300 /* reject the unsolicited RPS request and done with it */
5301 goto reject_out;
5302
5303 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5304 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5305 lpfc_max_els_tries, ndlp,
5306 ndlp->nlp_DID, ELS_CMD_ACC);
5307
5308 if (!elsiocb)
5309 return 1;
5310
5311 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5312 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5313 pcmd += sizeof(uint32_t); /* Skip past command */
5314
5315 /* use the command's xri in the response */
5316 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext;
5317
5318 rtv_rsp = (struct RTV_RSP *)pcmd;
5319
5320 /* populate RTV payload */
5321 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5322 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5323 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5324 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5325 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5326
5327 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5328 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5329 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5330 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5331 "Data: x%x x%x x%x\n",
5332 elsiocb->iotag, elsiocb->iocb.ulpContext,
5333 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5334 ndlp->nlp_rpi,
5335 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5336 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5337 phba->fc_stat.elsXmitACC++;
5338 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5339 lpfc_els_free_iocb(phba, elsiocb);
5340 return 0;
5341
5342reject_out:
5343 /* issue rejection response */
5344 stat.un.b.lsRjtRsvd0 = 0;
5345 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5346 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5347 stat.un.b.vendorUnique = 0;
5348 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5349 return 0;
5350}
5351
5352/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005353 * @vport: pointer to a host virtual N_Port data structure.
5354 * @cmdiocb: pointer to lpfc command iocb data structure.
5355 * @ndlp: pointer to a node-list data structure.
5356 *
5357 * This routine processes Read Port Status (RPS) IOCB received as an
5358 * ELS unsolicited event. It first checks the remote port state. If the
5359 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5360 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5361 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5362 * for reading the HBA link statistics. It is for the callback function,
5363 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5364 * to actually sending out RPS Accept (ACC) response.
5365 *
5366 * Return codes
5367 * 0 - Successfully processed rps iocb (currently always return 0)
5368 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005369static int
James Smart2e0fef82007-06-17 19:56:36 -05005370lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5371 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005372{
James Smart2e0fef82007-06-17 19:56:36 -05005373 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005374 uint32_t *lp;
5375 uint8_t flag;
5376 LPFC_MBOXQ_t *mbox;
5377 struct lpfc_dmabuf *pcmd;
5378 RPS *rps;
5379 struct ls_rjt stat;
5380
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005381 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005382 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5383 /* reject the unsolicited RPS request and done with it */
5384 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005385
5386 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5387 lp = (uint32_t *) pcmd->virt;
5388 flag = (be32_to_cpu(*lp++) & 0xf);
5389 rps = (RPS *) lp;
5390
5391 if ((flag == 0) ||
5392 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005393 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005394 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005395
James Smart92d7f7b2007-06-17 19:56:38 -05005396 printk("Fix me....\n");
5397 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005398 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5399 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005400 lpfc_read_lnk_stat(phba, mbox);
5401 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05005402 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04005403 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005404 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005405 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005406 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005407 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005408 /* Mbox completion will send ELS Response */
5409 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005410 /* Decrement reference count used for the failed mbox
5411 * command.
5412 */
James Smart329f9bc2007-04-25 09:53:01 -04005413 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005414 mempool_free(mbox, phba->mbox_mem_pool);
5415 }
5416 }
James Smart90160e02008-08-24 21:49:45 -04005417
5418reject_out:
5419 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005420 stat.un.b.lsRjtRsvd0 = 0;
5421 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5422 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5423 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005424 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005425 return 0;
5426}
5427
James Smart19ca7602010-11-20 23:11:55 -05005428/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5429 * @vport: pointer to a host virtual N_Port data structure.
5430 * @ndlp: pointer to a node-list data structure.
5431 * @did: DID of the target.
5432 * @rrq: Pointer to the rrq struct.
5433 *
5434 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5435 * Successful the the completion handler will clear the RRQ.
5436 *
5437 * Return codes
5438 * 0 - Successfully sent rrq els iocb.
5439 * 1 - Failed to send rrq els iocb.
5440 **/
5441static int
5442lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5443 uint32_t did, struct lpfc_node_rrq *rrq)
5444{
5445 struct lpfc_hba *phba = vport->phba;
5446 struct RRQ *els_rrq;
5447 IOCB_t *icmd;
5448 struct lpfc_iocbq *elsiocb;
5449 uint8_t *pcmd;
5450 uint16_t cmdsize;
5451 int ret;
5452
5453
5454 if (ndlp != rrq->ndlp)
5455 ndlp = rrq->ndlp;
5456 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5457 return 1;
5458
5459 /* If ndlp is not NULL, we will bump the reference count on it */
5460 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5461 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5462 ELS_CMD_RRQ);
5463 if (!elsiocb)
5464 return 1;
5465
5466 icmd = &elsiocb->iocb;
5467 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5468
5469 /* For RRQ request, remainder of payload is Exchange IDs */
5470 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5471 pcmd += sizeof(uint32_t);
5472 els_rrq = (struct RRQ *) pcmd;
5473
5474 bf_set(rrq_oxid, els_rrq, rrq->xritag);
5475 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5476 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5477 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5478 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5479
5480
5481 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5482 "Issue RRQ: did:x%x",
5483 did, rrq->xritag, rrq->rxid);
5484 elsiocb->context_un.rrq = rrq;
5485 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5486 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5487
5488 if (ret == IOCB_ERROR) {
5489 lpfc_els_free_iocb(phba, elsiocb);
5490 return 1;
5491 }
5492 return 0;
5493}
5494
5495/**
5496 * lpfc_send_rrq - Sends ELS RRQ if needed.
5497 * @phba: pointer to lpfc hba data structure.
5498 * @rrq: pointer to the active rrq.
5499 *
5500 * This routine will call the lpfc_issue_els_rrq if the rrq is
5501 * still active for the xri. If this function returns a failure then
5502 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5503 *
5504 * Returns 0 Success.
5505 * 1 Failure.
5506 **/
5507int
5508lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5509{
5510 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5511 rrq->nlp_DID);
5512 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5513 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5514 rrq->nlp_DID, rrq);
5515 else
5516 return 1;
5517}
5518
James Smarte59058c2008-08-24 21:49:00 -04005519/**
James Smart3621a712009-04-06 18:47:14 -04005520 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005521 * @vport: pointer to a host virtual N_Port data structure.
5522 * @cmdsize: size of the ELS command.
5523 * @oldiocb: pointer to the original lpfc command iocb data structure.
5524 * @ndlp: pointer to a node-list data structure.
5525 *
5526 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5527 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5528 *
5529 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5530 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5531 * will be stored into the context1 field of the IOCB for the completion
5532 * callback function to the RPL Accept Response ELS command.
5533 *
5534 * Return code
5535 * 0 - Successfully issued ACC RPL ELS command
5536 * 1 - Failed to issue ACC RPL ELS command
5537 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005538static int
James Smart2e0fef82007-06-17 19:56:36 -05005539lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5540 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005541{
James Smart2e0fef82007-06-17 19:56:36 -05005542 struct lpfc_hba *phba = vport->phba;
5543 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005544 RPL_RSP rpl_rsp;
5545 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005546 uint8_t *pcmd;
5547
James Smart2e0fef82007-06-17 19:56:36 -05005548 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5549 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005550
James Smart488d1462006-03-07 15:02:37 -05005551 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005552 return 1;
James Smart488d1462006-03-07 15:02:37 -05005553
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005554 icmd = &elsiocb->iocb;
5555 oldcmd = &oldiocb->iocb;
5556 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
5557
5558 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5559 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005560 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005561 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5562 pcmd += sizeof(uint16_t);
5563
5564 /* Setup the RPL ACC payload */
5565 rpl_rsp.listLen = be32_to_cpu(1);
5566 rpl_rsp.index = 0;
5567 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005568 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5569 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005570 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005571 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005572 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005573 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5574 "0120 Xmit ELS RPL ACC response tag x%x "
5575 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5576 "rpi x%x\n",
5577 elsiocb->iotag, elsiocb->iocb.ulpContext,
5578 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5579 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005580 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005581 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005582 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5583 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005584 lpfc_els_free_iocb(phba, elsiocb);
5585 return 1;
5586 }
5587 return 0;
5588}
5589
James Smarte59058c2008-08-24 21:49:00 -04005590/**
James Smart3621a712009-04-06 18:47:14 -04005591 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005592 * @vport: pointer to a host virtual N_Port data structure.
5593 * @cmdiocb: pointer to lpfc command iocb data structure.
5594 * @ndlp: pointer to a node-list data structure.
5595 *
5596 * This routine processes Read Port List (RPL) IOCB received as an ELS
5597 * unsolicited event. It first checks the remote port state. If the remote
5598 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5599 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5600 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5601 * to accept the RPL.
5602 *
5603 * Return code
5604 * 0 - Successfully processed rpl iocb (currently always return 0)
5605 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005606static int
James Smart2e0fef82007-06-17 19:56:36 -05005607lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5608 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005609{
5610 struct lpfc_dmabuf *pcmd;
5611 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005612 uint32_t maxsize;
5613 uint16_t cmdsize;
5614 RPL *rpl;
5615 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005616
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005617 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5618 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005619 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005620 stat.un.b.lsRjtRsvd0 = 0;
5621 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5622 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5623 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005624 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5625 NULL);
James Smart90160e02008-08-24 21:49:45 -04005626 /* rejected the unsolicited RPL request and done with it */
5627 return 0;
dea31012005-04-17 16:05:31 -05005628 }
5629
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005630 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5631 lp = (uint32_t *) pcmd->virt;
5632 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005633 maxsize = be32_to_cpu(rpl->maxsize);
5634
5635 /* We support only one port */
5636 if ((rpl->index == 0) &&
5637 ((maxsize == 0) ||
5638 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5639 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005640 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005641 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5642 }
James Smart2e0fef82007-06-17 19:56:36 -05005643 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005644
5645 return 0;
5646}
5647
James Smarte59058c2008-08-24 21:49:00 -04005648/**
James Smart3621a712009-04-06 18:47:14 -04005649 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005650 * @vport: pointer to a virtual N_Port data structure.
5651 * @cmdiocb: pointer to lpfc command iocb data structure.
5652 * @ndlp: pointer to a node-list data structure.
5653 *
5654 * This routine processes Fibre Channel Address Resolution Protocol
5655 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5656 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5657 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5658 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5659 * remote PortName is compared against the FC PortName stored in the @vport
5660 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5661 * compared against the FC NodeName stored in the @vport data structure.
5662 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5663 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5664 * invoked to send out FARP Response to the remote node. Before sending the
5665 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5666 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5667 * routine is invoked to log into the remote port first.
5668 *
5669 * Return code
5670 * 0 - Either the FARP Match Mode not supported or successfully processed
5671 **/
dea31012005-04-17 16:05:31 -05005672static int
James Smart2e0fef82007-06-17 19:56:36 -05005673lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5674 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005675{
5676 struct lpfc_dmabuf *pcmd;
5677 uint32_t *lp;
5678 IOCB_t *icmd;
5679 FARP *fp;
5680 uint32_t cmd, cnt, did;
5681
5682 icmd = &cmdiocb->iocb;
5683 did = icmd->un.elsreq64.remoteID;
5684 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5685 lp = (uint32_t *) pcmd->virt;
5686
5687 cmd = *lp++;
5688 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005689 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005690 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5691 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005692 /* We will only support match on WWPN or WWNN */
5693 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005694 return 0;
dea31012005-04-17 16:05:31 -05005695 }
5696
5697 cnt = 0;
5698 /* If this FARP command is searching for my portname */
5699 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005700 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005701 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005702 cnt = 1;
5703 }
5704
5705 /* If this FARP command is searching for my nodename */
5706 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005707 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005708 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005709 cnt = 1;
5710 }
5711
5712 if (cnt) {
5713 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5714 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5715 /* Log back into the node before sending the FARP. */
5716 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005717 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005718 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005719 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005720 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005721 }
5722
5723 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005724 if (fp->Rflags & FARP_REQUEST_FARPR)
5725 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005726 }
5727 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005728 return 0;
dea31012005-04-17 16:05:31 -05005729}
5730
James Smarte59058c2008-08-24 21:49:00 -04005731/**
James Smart3621a712009-04-06 18:47:14 -04005732 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005733 * @vport: pointer to a host virtual N_Port data structure.
5734 * @cmdiocb: pointer to lpfc command iocb data structure.
5735 * @ndlp: pointer to a node-list data structure.
5736 *
5737 * This routine processes Fibre Channel Address Resolution Protocol
5738 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5739 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5740 * the FARP response request.
5741 *
5742 * Return code
5743 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5744 **/
dea31012005-04-17 16:05:31 -05005745static int
James Smart2e0fef82007-06-17 19:56:36 -05005746lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5747 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005748{
5749 struct lpfc_dmabuf *pcmd;
5750 uint32_t *lp;
5751 IOCB_t *icmd;
5752 uint32_t cmd, did;
5753
5754 icmd = &cmdiocb->iocb;
5755 did = icmd->un.elsreq64.remoteID;
5756 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5757 lp = (uint32_t *) pcmd->virt;
5758
5759 cmd = *lp++;
5760 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005761 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5762 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005763 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005764 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005765
5766 return 0;
5767}
5768
James Smarte59058c2008-08-24 21:49:00 -04005769/**
James Smart3621a712009-04-06 18:47:14 -04005770 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005771 * @vport: pointer to a host virtual N_Port data structure.
5772 * @cmdiocb: pointer to lpfc command iocb data structure.
5773 * @fan_ndlp: pointer to a node-list data structure.
5774 *
5775 * This routine processes a Fabric Address Notification (FAN) IOCB
5776 * command received as an ELS unsolicited event. The FAN ELS command will
5777 * only be processed on a physical port (i.e., the @vport represents the
5778 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5779 * compared against those in the phba data structure. If any of those is
5780 * different, the lpfc_initial_flogi() routine is invoked to initialize
5781 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5782 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5783 * is invoked to register login to the fabric.
5784 *
5785 * Return code
5786 * 0 - Successfully processed fan iocb (currently always return 0).
5787 **/
dea31012005-04-17 16:05:31 -05005788static int
James Smart2e0fef82007-06-17 19:56:36 -05005789lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5790 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005791{
James Smart2e0fef82007-06-17 19:56:36 -05005792 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005793 uint32_t *lp;
5794 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005795
James Smart0d2b6b82008-06-14 22:52:47 -04005796 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5797 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5798 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005799 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005800 if ((vport == phba->pport) &&
5801 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005802 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005803 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005804 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005805 sizeof(struct lpfc_name)))) {
5806 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05005807 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005808 } else {
5809 /* FAN verified - skip FLOGI */
5810 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005811 if (phba->sli_rev < LPFC_SLI_REV4)
5812 lpfc_issue_fabric_reglogin(vport);
5813 else
5814 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005815 }
dea31012005-04-17 16:05:31 -05005816 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005817 return 0;
dea31012005-04-17 16:05:31 -05005818}
5819
James Smarte59058c2008-08-24 21:49:00 -04005820/**
James Smart3621a712009-04-06 18:47:14 -04005821 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005822 * @ptr: holder for the timer function associated data.
5823 *
5824 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5825 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5826 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5827 * up the worker thread. It is for the worker thread to invoke the routine
5828 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5829 **/
dea31012005-04-17 16:05:31 -05005830void
5831lpfc_els_timeout(unsigned long ptr)
5832{
James Smart2e0fef82007-06-17 19:56:36 -05005833 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5834 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005835 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005836 unsigned long iflag;
5837
James Smart2e0fef82007-06-17 19:56:36 -05005838 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005839 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5840 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005841 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005842 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005843
James Smart5e9d9b82008-06-14 22:52:53 -04005844 if (!tmo_posted)
5845 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005846 return;
5847}
5848
James Smart2a9bf3d2010-06-07 15:24:45 -04005849
James Smarte59058c2008-08-24 21:49:00 -04005850/**
James Smart3621a712009-04-06 18:47:14 -04005851 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005852 * @vport: pointer to a virtual N_Port data structure.
5853 *
5854 * This routine is the actual handler function that processes an ELS timeout
5855 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5856 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5857 * invoking the lpfc_sli_issue_abort_iotag() routine.
5858 **/
dea31012005-04-17 16:05:31 -05005859void
James Smart2e0fef82007-06-17 19:56:36 -05005860lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005861{
James Smart2e0fef82007-06-17 19:56:36 -05005862 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005863 struct lpfc_sli_ring *pring;
5864 struct lpfc_iocbq *tmp_iocb, *piocb;
5865 IOCB_t *cmd = NULL;
5866 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005867 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005868 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005869 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005870 LIST_HEAD(txcmplq_completions);
5871 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005872
James Smart2a9bf3d2010-06-07 15:24:45 -04005873
dea31012005-04-17 16:05:31 -05005874 timeout = (uint32_t)(phba->fc_ratov << 1);
5875
5876 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005877
James Smart2a9bf3d2010-06-07 15:24:45 -04005878 spin_lock_irq(&phba->hbalock);
5879 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5880 spin_unlock_irq(&phba->hbalock);
5881
5882 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005883 cmd = &piocb->iocb;
5884
James Smart2e0fef82007-06-17 19:56:36 -05005885 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5886 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5887 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005888 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005889
5890 if (piocb->vport != vport)
5891 continue;
5892
dea31012005-04-17 16:05:31 -05005893 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005894 if (pcmd)
5895 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005896
James Smart92d7f7b2007-06-17 19:56:38 -05005897 if (els_command == ELS_CMD_FARP ||
5898 els_command == ELS_CMD_FARPR ||
5899 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005900 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005901
dea31012005-04-17 16:05:31 -05005902 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005903 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005904 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005905 else
dea31012005-04-17 16:05:31 -05005906 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005907 continue;
5908 }
5909
James Smart2e0fef82007-06-17 19:56:36 -05005910 remote_ID = 0xffffffff;
5911 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005912 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005913 else {
5914 struct lpfc_nodelist *ndlp;
5915 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005916 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005917 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005918 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005919 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05005920 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005921 spin_lock_irq(&phba->hbalock);
5922 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05005923 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005924
James Smart2a9bf3d2010-06-07 15:24:45 -04005925 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5926 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5927 "0127 ELS timeout Data: x%x x%x x%x "
5928 "x%x\n", els_command,
5929 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5930 spin_lock_irq(&phba->hbalock);
5931 list_del_init(&piocb->dlist);
5932 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5933 spin_unlock_irq(&phba->hbalock);
5934 }
5935
James Smart2e0fef82007-06-17 19:56:36 -05005936 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5937 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005938}
5939
James Smarte59058c2008-08-24 21:49:00 -04005940/**
James Smart3621a712009-04-06 18:47:14 -04005941 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005942 * @vport: pointer to a host virtual N_Port data structure.
5943 *
5944 * This routine is used to clean up all the outstanding ELS commands on a
5945 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5946 * routine. After that, it walks the ELS transmit queue to remove all the
5947 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5948 * the IOCBs with a non-NULL completion callback function, the callback
5949 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5950 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5951 * callback function, the IOCB will simply be released. Finally, it walks
5952 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5953 * completion queue IOCB that is associated with the @vport and is not
5954 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5955 * part of the discovery state machine) out to HBA by invoking the
5956 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5957 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5958 * the IOCBs are aborted when this function returns.
5959 **/
dea31012005-04-17 16:05:31 -05005960void
James Smart2e0fef82007-06-17 19:56:36 -05005961lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005962{
James Smart2534ba72007-04-25 09:52:20 -04005963 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005964 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005965 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005966 struct lpfc_iocbq *tmp_iocb, *piocb;
5967 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005968
5969 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005970
James Smart2e0fef82007-06-17 19:56:36 -05005971 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005972 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5973 cmd = &piocb->iocb;
5974
5975 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5976 continue;
5977 }
5978
5979 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005980 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5981 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5982 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5983 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005984 continue;
dea31012005-04-17 16:05:31 -05005985
James Smart2e0fef82007-06-17 19:56:36 -05005986 if (piocb->vport != vport)
5987 continue;
5988
James Smart2534ba72007-04-25 09:52:20 -04005989 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005990 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005991 }
5992
5993 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005994 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5995 continue;
5996 }
dea31012005-04-17 16:05:31 -05005997
James Smart2e0fef82007-06-17 19:56:36 -05005998 if (piocb->vport != vport)
5999 continue;
6000
James Smart07951072007-04-25 09:51:38 -04006001 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05006002 }
James Smart2e0fef82007-06-17 19:56:36 -05006003 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04006004
James Smarta257bf92009-04-06 18:48:10 -04006005 /* Cancell all the IOCBs from the completions list */
6006 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6007 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04006008
dea31012005-04-17 16:05:31 -05006009 return;
6010}
6011
James Smarte59058c2008-08-24 21:49:00 -04006012/**
James Smart3621a712009-04-06 18:47:14 -04006013 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04006014 * @phba: pointer to lpfc hba data structure.
6015 *
6016 * This routine is used to clean up all the outstanding ELS commands on a
6017 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6018 * routine. After that, it walks the ELS transmit queue to remove all the
6019 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6020 * the IOCBs with the completion callback function associated, the callback
6021 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6022 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6023 * callback function associated, the IOCB will simply be released. Finally,
6024 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6025 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6026 * management plane IOCBs that are not part of the discovery state machine)
6027 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6028 **/
James Smart549e55c2007-08-02 11:09:51 -04006029void
6030lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6031{
6032 LIST_HEAD(completions);
6033 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6034 struct lpfc_iocbq *tmp_iocb, *piocb;
6035 IOCB_t *cmd = NULL;
6036
6037 lpfc_fabric_abort_hba(phba);
6038 spin_lock_irq(&phba->hbalock);
6039 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6040 cmd = &piocb->iocb;
6041 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6042 continue;
6043 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6044 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6045 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6046 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6047 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6048 continue;
6049 list_move_tail(&piocb->list, &completions);
6050 pring->txq_cnt--;
6051 }
6052 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6053 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6054 continue;
6055 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6056 }
6057 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04006058
6059 /* Cancel all the IOCBs from the completions list */
6060 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6061 IOERR_SLI_ABORTED);
6062
James Smart549e55c2007-08-02 11:09:51 -04006063 return;
6064}
6065
James Smarte59058c2008-08-24 21:49:00 -04006066/**
James Smart3621a712009-04-06 18:47:14 -04006067 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04006068 * @phba: Pointer to hba context object.
6069 * @cmdiocbp: Pointer to command iocb which reported error.
6070 * @rspiocbp: Pointer to response iocb which reported error.
6071 *
6072 * This function sends an event when there is an ELS command
6073 * failure.
6074 **/
6075void
6076lpfc_send_els_failure_event(struct lpfc_hba *phba,
6077 struct lpfc_iocbq *cmdiocbp,
6078 struct lpfc_iocbq *rspiocbp)
6079{
6080 struct lpfc_vport *vport = cmdiocbp->vport;
6081 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6082 struct lpfc_lsrjt_event lsrjt_event;
6083 struct lpfc_fabric_event_header fabric_event;
6084 struct ls_rjt stat;
6085 struct lpfc_nodelist *ndlp;
6086 uint32_t *pcmd;
6087
6088 ndlp = cmdiocbp->context1;
6089 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6090 return;
6091
6092 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6093 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6094 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6095 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6096 sizeof(struct lpfc_name));
6097 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6098 sizeof(struct lpfc_name));
6099 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6100 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006101 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006102 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6103 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6104 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6105 fc_host_post_vendor_event(shost,
6106 fc_get_event_number(),
6107 sizeof(lsrjt_event),
6108 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006109 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006110 return;
6111 }
6112 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6113 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6114 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6115 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6116 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6117 else
6118 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6119 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6120 sizeof(struct lpfc_name));
6121 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6122 sizeof(struct lpfc_name));
6123 fc_host_post_vendor_event(shost,
6124 fc_get_event_number(),
6125 sizeof(fabric_event),
6126 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006127 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006128 return;
6129 }
6130
6131}
6132
6133/**
James Smart3621a712009-04-06 18:47:14 -04006134 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006135 * @vport: Pointer to vport object.
6136 * @ndlp: Pointer FC node object.
6137 * @cmd: ELS command code.
6138 *
6139 * This function posts an event when there is an incoming
6140 * unsolicited ELS command.
6141 **/
6142static void
6143lpfc_send_els_event(struct lpfc_vport *vport,
6144 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006145 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006146{
James Smartddcc50f2008-12-04 22:38:46 -05006147 struct lpfc_els_event_header *els_data = NULL;
6148 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006149 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6150
James Smartddcc50f2008-12-04 22:38:46 -05006151 if (*payload == ELS_CMD_LOGO) {
6152 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6153 if (!logo_data) {
6154 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6155 "0148 Failed to allocate memory "
6156 "for LOGO event\n");
6157 return;
6158 }
6159 els_data = &logo_data->header;
6160 } else {
6161 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6162 GFP_KERNEL);
6163 if (!els_data) {
6164 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6165 "0149 Failed to allocate memory "
6166 "for ELS event\n");
6167 return;
6168 }
6169 }
6170 els_data->event_type = FC_REG_ELS_EVENT;
6171 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006172 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006173 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006174 break;
6175 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006176 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006177 break;
6178 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006179 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6180 break;
6181 case ELS_CMD_LOGO:
6182 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6183 /* Copy the WWPN in the LOGO payload */
6184 memcpy(logo_data->logo_wwpn, &payload[2],
6185 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006186 break;
6187 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006188 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006189 return;
6190 }
James Smartddcc50f2008-12-04 22:38:46 -05006191 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6192 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6193 if (*payload == ELS_CMD_LOGO) {
6194 fc_host_post_vendor_event(shost,
6195 fc_get_event_number(),
6196 sizeof(struct lpfc_logo_event),
6197 (char *)logo_data,
6198 LPFC_NL_VENDOR_ID);
6199 kfree(logo_data);
6200 } else {
6201 fc_host_post_vendor_event(shost,
6202 fc_get_event_number(),
6203 sizeof(struct lpfc_els_event_header),
6204 (char *)els_data,
6205 LPFC_NL_VENDOR_ID);
6206 kfree(els_data);
6207 }
James Smartea2151b2008-09-07 11:52:10 -04006208
6209 return;
6210}
6211
6212
6213/**
James Smart3621a712009-04-06 18:47:14 -04006214 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006215 * @phba: pointer to lpfc hba data structure.
6216 * @pring: pointer to a SLI ring.
6217 * @vport: pointer to a host virtual N_Port data structure.
6218 * @elsiocb: pointer to lpfc els command iocb data structure.
6219 *
6220 * This routine is used for processing the IOCB associated with a unsolicited
6221 * event. It first determines whether there is an existing ndlp that matches
6222 * the DID from the unsolicited IOCB. If not, it will create a new one with
6223 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6224 * IOCB is then used to invoke the proper routine and to set up proper state
6225 * of the discovery state machine.
6226 **/
James Smarted957682007-06-17 19:56:37 -05006227static void
6228lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006229 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006230{
James Smart87af33f2007-10-27 13:37:43 -04006231 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006232 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006233 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006234 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05006235 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006236 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006237
James Smarte47c9092008-02-08 18:49:26 -05006238 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006239 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006240
dea31012005-04-17 16:05:31 -05006241 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006242 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6243 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006244 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006245 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006246
James Smart858c9f62007-06-17 19:56:39 -05006247 did = icmd->un.rcvels.remoteID;
6248 if (icmd->ulpStatus) {
6249 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6250 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6251 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006252 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006253 }
dea31012005-04-17 16:05:31 -05006254
6255 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006256 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006257 goto dropit;
dea31012005-04-17 16:05:31 -05006258
James Smartc8685952009-11-18 15:39:16 -05006259 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006260 if (vport->load_flag & FC_UNLOADING)
6261 goto dropit;
6262
James Smart92494142011-02-16 12:39:44 -05006263 /* If NPort discovery is delayed drop incoming ELS */
6264 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6265 (cmd != ELS_CMD_PLOGI))
6266 goto dropit;
6267
James Smart2e0fef82007-06-17 19:56:36 -05006268 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006269 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006270 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006271 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006272 if (!ndlp)
dea31012005-04-17 16:05:31 -05006273 goto dropit;
dea31012005-04-17 16:05:31 -05006274
James Smart2e0fef82007-06-17 19:56:36 -05006275 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006276 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006277 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006278 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006279 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006280 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6281 ndlp = lpfc_enable_node(vport, ndlp,
6282 NLP_STE_UNUSED_NODE);
6283 if (!ndlp)
6284 goto dropit;
6285 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6286 newnode = 1;
6287 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6288 ndlp->nlp_type |= NLP_FABRIC;
6289 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6290 /* This is similar to the new node path */
6291 ndlp = lpfc_nlp_get(ndlp);
6292 if (!ndlp)
6293 goto dropit;
6294 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6295 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006296 }
dea31012005-04-17 16:05:31 -05006297
6298 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006299
James Smart329f9bc2007-04-25 09:53:01 -04006300 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006301 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006302
6303 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6304 cmd &= ELS_CMD_MASK;
6305 }
6306 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006307 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6308 "0112 ELS command x%x received from NPORT x%x "
6309 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006310 switch (cmd) {
6311 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006312 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6313 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6314 did, vport->port_state, ndlp->nlp_flag);
6315
dea31012005-04-17 16:05:31 -05006316 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006317 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6318
James Smartddcc50f2008-12-04 22:38:46 -05006319 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05006320
6321 /* If Nport discovery is delayed, reject PLOGIs */
6322 if (vport->fc_flag & FC_DISC_DELAYED) {
6323 rjt_err = LSRJT_UNABLE_TPC;
6324 break;
6325 }
James Smart858c9f62007-06-17 19:56:39 -05006326 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006327 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6328 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6329 rjt_err = LSRJT_UNABLE_TPC;
6330 break;
6331 }
6332 /* We get here, and drop thru, if we are PT2PT with
6333 * another NPort and the other side has initiated
6334 * the PLOGI before responding to our FLOGI.
6335 */
dea31012005-04-17 16:05:31 -05006336 }
James Smart87af33f2007-10-27 13:37:43 -04006337
6338 shost = lpfc_shost_from_vport(vport);
6339 spin_lock_irq(shost->host_lock);
6340 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6341 spin_unlock_irq(shost->host_lock);
6342
James Smart2e0fef82007-06-17 19:56:36 -05006343 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6344 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006345
dea31012005-04-17 16:05:31 -05006346 break;
6347 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006348 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6349 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6350 did, vport->port_state, ndlp->nlp_flag);
6351
dea31012005-04-17 16:05:31 -05006352 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006353 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006354 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006355 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006356 break;
6357 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006358 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6359 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6360 did, vport->port_state, ndlp->nlp_flag);
6361
dea31012005-04-17 16:05:31 -05006362 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006363 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006364 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006365 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006366 break;
6367 }
James Smart2e0fef82007-06-17 19:56:36 -05006368 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006369 break;
6370 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006371 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6372 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6373 did, vport->port_state, ndlp->nlp_flag);
6374
dea31012005-04-17 16:05:31 -05006375 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006376 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006377 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006378 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006379 break;
6380 }
James Smart2e0fef82007-06-17 19:56:36 -05006381 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006382 break;
6383 case ELS_CMD_RSCN:
6384 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006385 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006386 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006387 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006388 break;
6389 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006390 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6391 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6392 did, vport->port_state, ndlp->nlp_flag);
6393
James Smartddcc50f2008-12-04 22:38:46 -05006394 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006395 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006396 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006397 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006398 break;
6399 }
James Smart2e0fef82007-06-17 19:56:36 -05006400 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6401 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006402 break;
6403 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006404 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6405 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6406 did, vport->port_state, ndlp->nlp_flag);
6407
dea31012005-04-17 16:05:31 -05006408 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006409 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006410 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006411 break;
6412 }
James Smart2e0fef82007-06-17 19:56:36 -05006413 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6414 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006415 break;
6416 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006417 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6418 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6419 did, vport->port_state, ndlp->nlp_flag);
6420
dea31012005-04-17 16:05:31 -05006421 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006422 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006423 break;
6424 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006425 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6426 "RCV FARP: 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.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006430 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006431 break;
6432 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006433 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6434 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6435 did, vport->port_state, ndlp->nlp_flag);
6436
dea31012005-04-17 16:05:31 -05006437 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006438 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006439 break;
dea31012005-04-17 16:05:31 -05006440 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006441 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6442 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6443 did, vport->port_state, ndlp->nlp_flag);
6444
dea31012005-04-17 16:05:31 -05006445 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006446 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006447 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006448 break;
6449 }
James Smart2e0fef82007-06-17 19:56:36 -05006450 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006451 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006452 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006453 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6454 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6455 did, vport->port_state, ndlp->nlp_flag);
6456
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006457 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006458 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006459 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006460 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006461 break;
James Smart12265f62010-10-22 11:05:53 -04006462 case ELS_CMD_RLS:
6463 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6464 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6465 did, vport->port_state, ndlp->nlp_flag);
6466
6467 phba->fc_stat.elsRcvRLS++;
6468 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6469 if (newnode)
6470 lpfc_nlp_put(ndlp);
6471 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006472 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006473 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6474 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6475 did, vport->port_state, ndlp->nlp_flag);
6476
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006477 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006478 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006479 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006480 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006481 break;
6482 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006483 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6484 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6485 did, vport->port_state, ndlp->nlp_flag);
6486
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006487 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006488 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006489 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006490 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006491 break;
dea31012005-04-17 16:05:31 -05006492 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006493 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6494 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6495 did, vport->port_state, ndlp->nlp_flag);
6496
dea31012005-04-17 16:05:31 -05006497 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006498 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006499 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006500 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006501 break;
James Smart12265f62010-10-22 11:05:53 -04006502 case ELS_CMD_RTV:
6503 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6504 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6505 did, vport->port_state, ndlp->nlp_flag);
6506 phba->fc_stat.elsRcvRTV++;
6507 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6508 if (newnode)
6509 lpfc_nlp_put(ndlp);
6510 break;
James Smart5ffc2662009-11-18 15:39:44 -05006511 case ELS_CMD_RRQ:
6512 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6513 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6514 did, vport->port_state, ndlp->nlp_flag);
6515
6516 phba->fc_stat.elsRcvRRQ++;
6517 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6518 if (newnode)
6519 lpfc_nlp_put(ndlp);
6520 break;
James Smart12265f62010-10-22 11:05:53 -04006521 case ELS_CMD_ECHO:
6522 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6523 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6524 did, vport->port_state, ndlp->nlp_flag);
6525
6526 phba->fc_stat.elsRcvECHO++;
6527 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6528 if (newnode)
6529 lpfc_nlp_put(ndlp);
6530 break;
dea31012005-04-17 16:05:31 -05006531 default:
James Smart858c9f62007-06-17 19:56:39 -05006532 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6533 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6534 cmd, did, vport->port_state);
6535
dea31012005-04-17 16:05:31 -05006536 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006537 rjt_err = LSRJT_CMD_UNSUPPORTED;
dea31012005-04-17 16:05:31 -05006538
6539 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006540 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6541 "0115 Unknown ELS command x%x "
6542 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006543 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006544 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006545 break;
6546 }
6547
6548 /* check if need to LS_RJT received ELS cmd */
6549 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006550 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006551 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006552 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006553 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6554 NULL);
dea31012005-04-17 16:05:31 -05006555 }
6556
James Smartd7c255b2008-08-24 21:50:00 -04006557 lpfc_nlp_put(elsiocb->context1);
6558 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006559 return;
6560
6561dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006562 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006563 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6564 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006565 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006566 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006567 phba->fc_stat.elsRcvDrop++;
6568}
6569
James Smarte59058c2008-08-24 21:49:00 -04006570/**
James Smart3621a712009-04-06 18:47:14 -04006571 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04006572 * @phba: pointer to lpfc hba data structure.
6573 * @vpi: host virtual N_Port identifier.
6574 *
6575 * This routine finds a vport on a HBA (referred by @phba) through a
6576 * @vpi. The function walks the HBA's vport list and returns the address
6577 * of the vport with the matching @vpi.
6578 *
6579 * Return code
6580 * NULL - No vport with the matching @vpi found
6581 * Otherwise - Address to the vport with the matching @vpi.
6582 **/
James Smart6669f9b2009-10-02 15:16:45 -04006583struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05006584lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6585{
6586 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04006587 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05006588
James Smart549e55c2007-08-02 11:09:51 -04006589 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006590 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04006591 if (vport->vpi == vpi) {
6592 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006593 return vport;
James Smart549e55c2007-08-02 11:09:51 -04006594 }
James Smart92d7f7b2007-06-17 19:56:38 -05006595 }
James Smart549e55c2007-08-02 11:09:51 -04006596 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006597 return NULL;
6598}
James Smarted957682007-06-17 19:56:37 -05006599
James Smarte59058c2008-08-24 21:49:00 -04006600/**
James Smart3621a712009-04-06 18:47:14 -04006601 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006602 * @phba: pointer to lpfc hba data structure.
6603 * @pring: pointer to a SLI ring.
6604 * @elsiocb: pointer to lpfc els iocb data structure.
6605 *
6606 * This routine is used to process an unsolicited event received from a SLI
6607 * (Service Level Interface) ring. The actual processing of the data buffer
6608 * associated with the unsolicited event is done by invoking the routine
6609 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6610 * SLI ring on which the unsolicited event was received.
6611 **/
James Smarted957682007-06-17 19:56:37 -05006612void
6613lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6614 struct lpfc_iocbq *elsiocb)
6615{
6616 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006617 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006618 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006619 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6620 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006621
James Smartd7c255b2008-08-24 21:50:00 -04006622 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006623 elsiocb->context2 = NULL;
6624 elsiocb->context3 = NULL;
6625
6626 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6627 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6628 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6629 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006630 phba->fc_stat.NoRcvBuf++;
6631 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006632 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006633 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006634 return;
6635 }
6636
James Smart92d7f7b2007-06-17 19:56:38 -05006637 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6638 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6639 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6640 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6641 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006642 else
6643 vport = lpfc_find_vport_by_vpid(phba,
6644 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05006645 }
James Smart7f5f3d02008-02-08 18:50:14 -05006646 /* If there are no BDEs associated
6647 * with this IOCB, there is nothing to do.
6648 */
James Smarted957682007-06-17 19:56:37 -05006649 if (icmd->ulpBdeCount == 0)
6650 return;
6651
James Smart7f5f3d02008-02-08 18:50:14 -05006652 /* type of ELS cmd is first 32bit word
6653 * in packet
6654 */
James Smarted957682007-06-17 19:56:37 -05006655 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006656 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006657 } else {
6658 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6659 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006660 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6661 paddr);
James Smarted957682007-06-17 19:56:37 -05006662 }
6663
James Smart92d7f7b2007-06-17 19:56:38 -05006664 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6665 /*
6666 * The different unsolicited event handlers would tell us
6667 * if they are done with "mp" by setting context2 to NULL.
6668 */
dea31012005-04-17 16:05:31 -05006669 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006670 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6671 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006672 }
James Smarted957682007-06-17 19:56:37 -05006673
6674 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006675 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006676 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006677 elsiocb->context2 = bdeBuf2;
6678 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006679 /* free mp if we are done with it */
6680 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006681 lpfc_in_buf_free(phba, elsiocb->context2);
6682 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006683 }
dea31012005-04-17 16:05:31 -05006684 }
dea31012005-04-17 16:05:31 -05006685}
James Smart92d7f7b2007-06-17 19:56:38 -05006686
James Smarte59058c2008-08-24 21:49:00 -04006687/**
James Smart3621a712009-04-06 18:47:14 -04006688 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006689 * @phba: pointer to lpfc hba data structure.
6690 * @vport: pointer to a virtual N_Port data structure.
6691 *
6692 * This routine issues a Port Login (PLOGI) to the Name Server with
6693 * State Change Request (SCR) for a @vport. This routine will create an
6694 * ndlp for the Name Server associated to the @vport if such node does
6695 * not already exist. The PLOGI to Name Server is issued by invoking the
6696 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6697 * (FDMI) is configured to the @vport, a FDMI node will be created and
6698 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6699 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006700void
6701lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6702{
6703 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05006704 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6705
6706 /*
6707 * If lpfc_delay_discovery parameter is set and the clean address
6708 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6709 * discovery.
6710 */
6711 spin_lock_irq(shost->host_lock);
6712 if (vport->fc_flag & FC_DISC_DELAYED) {
6713 spin_unlock_irq(shost->host_lock);
6714 mod_timer(&vport->delayed_disc_tmo,
6715 jiffies + HZ * phba->fc_ratov);
6716 return;
6717 }
6718 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006719
6720 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6721 if (!ndlp) {
6722 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6723 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006724 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05006725 lpfc_disc_start(vport);
6726 return;
6727 }
6728 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006729 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6730 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006731 return;
6732 }
6733 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006734 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6735 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6736 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006737 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05006738 lpfc_disc_start(vport);
6739 return;
6740 }
6741 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6742 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6743 "0348 NameServer login: node freed\n");
6744 return;
6745 }
James Smart92d7f7b2007-06-17 19:56:38 -05006746 }
James Smart58da1ff2008-04-07 10:15:56 -04006747 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006748
6749 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6750
6751 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6752 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006753 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6754 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006755 return;
6756 }
6757
James Smart3de2a652007-08-02 11:09:59 -04006758 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05006759 /* If this is the first time, allocate an ndlp and initialize
6760 * it. Otherwise, make sure the node is enabled and then do the
6761 * login.
6762 */
6763 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
6764 if (!ndlp_fdmi) {
6765 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6766 GFP_KERNEL);
6767 if (ndlp_fdmi) {
6768 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6769 ndlp_fdmi->nlp_type |= NLP_FABRIC;
6770 } else
6771 return;
6772 }
6773 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
6774 ndlp_fdmi = lpfc_enable_node(vport,
6775 ndlp_fdmi,
6776 NLP_STE_NPR_NODE);
6777
James Smart92d7f7b2007-06-17 19:56:38 -05006778 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04006779 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05006780 NLP_STE_PLOGI_ISSUE);
6781 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006782 }
6783 }
James Smart92d7f7b2007-06-17 19:56:38 -05006784}
6785
James Smarte59058c2008-08-24 21:49:00 -04006786/**
James Smart3621a712009-04-06 18:47:14 -04006787 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006788 * @phba: pointer to lpfc hba data structure.
6789 * @pmb: pointer to the driver internal queue element for mailbox command.
6790 *
6791 * This routine is the completion callback function to register new vport
6792 * mailbox command. If the new vport mailbox command completes successfully,
6793 * the fabric registration login shall be performed on physical port (the
6794 * new vport created is actually a physical port, with VPI 0) or the port
6795 * login to Name Server for State Change Request (SCR) will be performed
6796 * on virtual port (real virtual port, with VPI greater than 0).
6797 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006798static void
6799lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6800{
6801 struct lpfc_vport *vport = pmb->vport;
6802 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6803 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006804 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006805 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006806
James Smart09372822008-01-11 01:52:54 -05006807 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006808 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006809 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006810
6811 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006812 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006813 "0915 Register VPI failed : Status: x%x"
6814 " upd bit: x%x \n", mb->mbxStatus,
6815 mb->un.varRegVpi.upd);
6816 if (phba->sli_rev == LPFC_SLI_REV4 &&
6817 mb->un.varRegVpi.upd)
6818 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006819
6820 switch (mb->mbxStatus) {
6821 case 0x11: /* unsupported feature */
6822 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006823 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006824 /* giving up on vport registration */
6825 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6826 spin_lock_irq(shost->host_lock);
6827 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6828 spin_unlock_irq(shost->host_lock);
6829 lpfc_can_disctmo(vport);
6830 break;
James Smart695a8142010-01-26 23:08:03 -05006831 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6832 case 0x20:
6833 spin_lock_irq(shost->host_lock);
6834 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6835 spin_unlock_irq(shost->host_lock);
6836 lpfc_init_vpi(phba, pmb, vport->vpi);
6837 pmb->vport = vport;
6838 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6839 rc = lpfc_sli_issue_mbox(phba, pmb,
6840 MBX_NOWAIT);
6841 if (rc == MBX_NOT_FINISHED) {
6842 lpfc_printf_vlog(vport,
6843 KERN_ERR, LOG_MBOX,
6844 "2732 Failed to issue INIT_VPI"
6845 " mailbox command\n");
6846 } else {
6847 lpfc_nlp_put(ndlp);
6848 return;
6849 }
6850
James Smart92d7f7b2007-06-17 19:56:38 -05006851 default:
6852 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04006853 if (phba->sli_rev == LPFC_SLI_REV4)
6854 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006855 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006856 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006857 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006858 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006859 if (vport->port_type == LPFC_PHYSICAL_PORT
6860 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05006861 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05006862 else
6863 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006864 break;
6865 }
James Smart92d7f7b2007-06-17 19:56:38 -05006866 } else {
James Smart695a8142010-01-26 23:08:03 -05006867 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006868 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006869 spin_unlock_irq(shost->host_lock);
6870 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006871 if (phba->sli_rev < LPFC_SLI_REV4)
6872 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006873 else {
James Smartfc2b9892010-02-26 14:15:29 -05006874 /*
6875 * If the physical port is instantiated using
6876 * FDISC, do not start vport discovery.
6877 */
6878 if (vport->port_state != LPFC_FDISC)
6879 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006880 lpfc_do_scr_ns_plogi(phba, vport);
6881 }
6882 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006883 lpfc_do_scr_ns_plogi(phba, vport);
6884 }
James Smart38b92ef2010-08-04 16:11:39 -04006885mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05006886 /* Now, we decrement the ndlp reference count held for this
6887 * callback function
6888 */
6889 lpfc_nlp_put(ndlp);
6890
James Smart92d7f7b2007-06-17 19:56:38 -05006891 mempool_free(pmb, phba->mbox_mem_pool);
6892 return;
6893}
6894
James Smarte59058c2008-08-24 21:49:00 -04006895/**
James Smart3621a712009-04-06 18:47:14 -04006896 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006897 * @phba: pointer to lpfc hba data structure.
6898 * @vport: pointer to a host virtual N_Port data structure.
6899 * @ndlp: pointer to a node-list data structure.
6900 *
6901 * This routine registers the @vport as a new virtual port with a HBA.
6902 * It is done through a registering vpi mailbox command.
6903 **/
James Smart695a8142010-01-26 23:08:03 -05006904void
James Smart92d7f7b2007-06-17 19:56:38 -05006905lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6906 struct lpfc_nodelist *ndlp)
6907{
James Smart09372822008-01-11 01:52:54 -05006908 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006909 LPFC_MBOXQ_t *mbox;
6910
6911 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6912 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006913 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006914 mbox->vport = vport;
6915 mbox->context2 = lpfc_nlp_get(ndlp);
6916 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006917 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006918 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006919 /* mailbox command not success, decrement ndlp
6920 * reference count for this command
6921 */
6922 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006923 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006924
James Smarte8b62012007-08-02 11:10:09 -04006925 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6926 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006927 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006928 }
6929 } else {
James Smarte8b62012007-08-02 11:10:09 -04006930 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6931 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006932 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006933 }
James Smartfa4066b2008-01-11 01:53:27 -05006934 return;
6935
6936mbox_err_exit:
6937 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6938 spin_lock_irq(shost->host_lock);
6939 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6940 spin_unlock_irq(shost->host_lock);
6941 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006942}
6943
James Smarte59058c2008-08-24 21:49:00 -04006944/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006945 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006946 * @phba: pointer to lpfc hba data structure.
6947 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006948 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006949 **/
6950void
James Smart0c9ab6f2010-02-26 14:15:57 -05006951lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006952{
6953 struct lpfc_vport **vports;
6954 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006955 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006956 int i;
James Smart695a8142010-01-26 23:08:03 -05006957
6958 /* Treat this failure as linkdown for all vports */
6959 link_state = phba->link_state;
6960 lpfc_linkdown(phba);
6961 phba->link_state = link_state;
6962
6963 vports = lpfc_create_vport_work_array(phba);
6964
6965 if (vports) {
6966 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6967 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6968 if (ndlp)
6969 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6970 lpfc_els_flush_cmd(vports[i]);
6971 }
6972 lpfc_destroy_vport_work_array(phba, vports);
6973 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006974}
6975
6976/**
6977 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6978 * @phba: pointer to lpfc hba data structure.
6979 *
6980 * This routine abort all pending discovery commands and
6981 * start a timer to retry FLOGI for the physical port
6982 * discovery.
6983 **/
6984void
6985lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6986{
6987 struct lpfc_nodelist *ndlp;
6988 struct Scsi_Host *shost;
6989
6990 /* Cancel the all vports retry delay retry timers */
6991 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05006992
6993 /* If fabric require FLOGI, then re-instantiate physical login */
6994 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6995 if (!ndlp)
6996 return;
6997
James Smart695a8142010-01-26 23:08:03 -05006998 shost = lpfc_shost_from_vport(phba->pport);
6999 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
7000 spin_lock_irq(shost->host_lock);
7001 ndlp->nlp_flag |= NLP_DELAY_TMO;
7002 spin_unlock_irq(shost->host_lock);
7003 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7004 phba->pport->port_state = LPFC_FLOGI;
7005 return;
7006}
7007
7008/**
7009 * lpfc_fabric_login_reqd - Check if FLOGI required.
7010 * @phba: pointer to lpfc hba data structure.
7011 * @cmdiocb: pointer to FDISC command iocb.
7012 * @rspiocb: pointer to FDISC response iocb.
7013 *
7014 * This routine checks if a FLOGI is reguired for FDISC
7015 * to succeed.
7016 **/
7017static int
7018lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7019 struct lpfc_iocbq *cmdiocb,
7020 struct lpfc_iocbq *rspiocb)
7021{
7022
7023 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7024 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7025 return 0;
7026 else
7027 return 1;
7028}
7029
7030/**
James Smart3621a712009-04-06 18:47:14 -04007031 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007032 * @phba: pointer to lpfc hba data structure.
7033 * @cmdiocb: pointer to lpfc command iocb data structure.
7034 * @rspiocb: pointer to lpfc response iocb data structure.
7035 *
7036 * This routine is the completion callback function to a Fabric Discover
7037 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7038 * single threaded, each FDISC completion callback function will reset
7039 * the discovery timer for all vports such that the timers will not get
7040 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7041 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7042 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7043 * assigned to the vport has been changed with the completion of the FDISC
7044 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7045 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7046 * routine is invoked to register new vport with the HBA. Otherwise, the
7047 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7048 * Server for State Change Request (SCR).
7049 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007050static void
7051lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7052 struct lpfc_iocbq *rspiocb)
7053{
7054 struct lpfc_vport *vport = cmdiocb->vport;
7055 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7056 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7057 struct lpfc_nodelist *np;
7058 struct lpfc_nodelist *next_np;
7059 IOCB_t *irsp = &rspiocb->iocb;
7060 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05007061 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7062 struct serv_parm *sp;
7063 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05007064
James Smarte8b62012007-08-02 11:10:09 -04007065 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7066 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7067 irsp->ulpStatus, irsp->un.ulpWord[4],
7068 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05007069 /* Since all FDISCs are being single threaded, we
7070 * must reset the discovery timer for ALL vports
7071 * waiting to send FDISC when one completes.
7072 */
7073 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7074 lpfc_set_disctmo(piocb->vport);
7075 }
7076
James Smart858c9f62007-06-17 19:56:39 -05007077 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7078 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7079 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7080
James Smart92d7f7b2007-06-17 19:56:38 -05007081 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05007082
7083 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7084 lpfc_retry_pport_discovery(phba);
7085 goto out;
7086 }
7087
James Smart92d7f7b2007-06-17 19:56:38 -05007088 /* Check for retry */
7089 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7090 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007091 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04007092 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04007093 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04007094 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04007095 goto fdisc_failed;
7096 }
James Smartd7c255b2008-08-24 21:50:00 -04007097 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05007098 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04007099 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04007100 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05007101 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04007102 vport->fc_flag |= FC_PUBLIC_LOOP;
7103 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007104
James Smartd7c255b2008-08-24 21:50:00 -04007105 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7106 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05007107 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7108 sp = prsp->virt + sizeof(uint32_t);
7109 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7110 memcpy(&vport->fabric_portname, &sp->portName,
7111 sizeof(struct lpfc_name));
7112 memcpy(&vport->fabric_nodename, &sp->nodeName,
7113 sizeof(struct lpfc_name));
7114 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04007115 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7116 /* If our NportID changed, we need to ensure all
7117 * remaining NPORTs get unreg_login'ed so we can
7118 * issue unreg_vpi.
7119 */
7120 list_for_each_entry_safe(np, next_np,
7121 &vport->fc_nodes, nlp_listp) {
7122 if (!NLP_CHK_NODE_ACT(ndlp) ||
7123 (np->nlp_state != NLP_STE_NPR_NODE) ||
7124 !(np->nlp_flag & NLP_NPR_ADISC))
7125 continue;
James Smart09372822008-01-11 01:52:54 -05007126 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007127 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007128 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007129 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007130 }
James Smart78730cf2010-04-06 15:06:30 -04007131 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007132
7133 if (phba->sli_rev == LPFC_SLI_REV4)
7134 lpfc_sli4_unreg_all_rpis(vport);
7135
James Smartd7c255b2008-08-24 21:50:00 -04007136 lpfc_mbx_unreg_vpi(vport);
7137 spin_lock_irq(shost->host_lock);
7138 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007139 if (phba->sli_rev == LPFC_SLI_REV4)
7140 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007141 else
7142 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007143 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007144 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7145 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7146 /*
7147 * Driver needs to re-reg VPI in order for f/w
7148 * to update the MAC address.
7149 */
7150 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007151 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007152 }
7153
James Smartecfd03c2010-02-12 14:41:27 -05007154 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7155 lpfc_issue_init_vpi(vport);
7156 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007157 lpfc_register_new_vport(phba, vport, ndlp);
7158 else
7159 lpfc_do_scr_ns_plogi(phba, vport);
7160 goto out;
7161fdisc_failed:
7162 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7163 /* Cancel discovery timer */
7164 lpfc_can_disctmo(vport);
7165 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007166out:
7167 lpfc_els_free_iocb(phba, cmdiocb);
7168}
7169
James Smarte59058c2008-08-24 21:49:00 -04007170/**
James Smart3621a712009-04-06 18:47:14 -04007171 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007172 * @vport: pointer to a virtual N_Port data structure.
7173 * @ndlp: pointer to a node-list data structure.
7174 * @retry: number of retries to the command IOCB.
7175 *
7176 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7177 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7178 * routine to issue the IOCB, which makes sure only one outstanding fabric
7179 * IOCB will be sent off HBA at any given time.
7180 *
7181 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7182 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7183 * will be stored into the context1 field of the IOCB for the completion
7184 * callback function to the FDISC ELS command.
7185 *
7186 * Return code
7187 * 0 - Successfully issued fdisc iocb command
7188 * 1 - Failed to issue fdisc iocb command
7189 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007190static int
James Smart92d7f7b2007-06-17 19:56:38 -05007191lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7192 uint8_t retry)
7193{
7194 struct lpfc_hba *phba = vport->phba;
7195 IOCB_t *icmd;
7196 struct lpfc_iocbq *elsiocb;
7197 struct serv_parm *sp;
7198 uint8_t *pcmd;
7199 uint16_t cmdsize;
7200 int did = ndlp->nlp_DID;
7201 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007202
James Smart5ffc2662009-11-18 15:39:44 -05007203 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05007204 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7205 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7206 ELS_CMD_FDISC);
7207 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007208 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007209 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7210 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007211 return 1;
7212 }
7213
7214 icmd = &elsiocb->iocb;
7215 icmd->un.elsreq64.myID = 0;
7216 icmd->un.elsreq64.fl = 1;
7217
James Smart40426292010-12-15 17:58:10 -05007218 if ((phba->sli_rev == LPFC_SLI_REV4) &&
7219 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
7220 LPFC_SLI_INTF_IF_TYPE_0)) {
James Smartf1126682009-06-10 17:22:44 -04007221 /* FDISC needs to be 1 for WQE VPI */
7222 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
7223 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
7224 /* Set the ulpContext to the vpi */
7225 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
7226 } else {
7227 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
7228 icmd->ulpCt_h = 1;
7229 icmd->ulpCt_l = 0;
7230 }
James Smart92d7f7b2007-06-17 19:56:38 -05007231
7232 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7233 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7234 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7235 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7236 sp = (struct serv_parm *) pcmd;
7237 /* Setup CSPs accordingly for Fabric */
7238 sp->cmn.e_d_tov = 0;
7239 sp->cmn.w2.r_a_tov = 0;
7240 sp->cls1.classValid = 0;
7241 sp->cls2.seqDelivery = 1;
7242 sp->cls3.seqDelivery = 1;
7243
7244 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7245 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7246 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7247 pcmd += sizeof(uint32_t); /* Port Name */
7248 memcpy(pcmd, &vport->fc_portname, 8);
7249 pcmd += sizeof(uint32_t); /* Node Name */
7250 pcmd += sizeof(uint32_t); /* Node Name */
7251 memcpy(pcmd, &vport->fc_nodename, 8);
7252
7253 lpfc_set_disctmo(vport);
7254
7255 phba->fc_stat.elsXmitFDISC++;
7256 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7257
James Smart858c9f62007-06-17 19:56:39 -05007258 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7259 "Issue FDISC: did:x%x",
7260 did, 0, 0);
7261
James Smart92d7f7b2007-06-17 19:56:38 -05007262 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7263 if (rc == IOCB_ERROR) {
7264 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007265 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007266 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7267 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007268 return 1;
7269 }
7270 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007271 return 0;
7272}
7273
James Smarte59058c2008-08-24 21:49:00 -04007274/**
James Smart3621a712009-04-06 18:47:14 -04007275 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007276 * @phba: pointer to lpfc hba data structure.
7277 * @cmdiocb: pointer to lpfc command iocb data structure.
7278 * @rspiocb: pointer to lpfc response iocb data structure.
7279 *
7280 * This routine is the completion callback function to the issuing of a LOGO
7281 * ELS command off a vport. It frees the command IOCB and then decrement the
7282 * reference count held on ndlp for this completion function, indicating that
7283 * the reference to the ndlp is no long needed. Note that the
7284 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7285 * callback function and an additional explicit ndlp reference decrementation
7286 * will trigger the actual release of the ndlp.
7287 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007288static void
7289lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7290 struct lpfc_iocbq *rspiocb)
7291{
7292 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007293 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007294 struct lpfc_nodelist *ndlp;
James Smart9589b0622011-04-16 11:03:17 -04007295 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05007296
James Smart9589b0622011-04-16 11:03:17 -04007297 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007298 irsp = &rspiocb->iocb;
7299 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7300 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7301 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007302
7303 lpfc_els_free_iocb(phba, cmdiocb);
7304 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007305
7306 /* Trigger the release of the ndlp after logo */
7307 lpfc_nlp_put(ndlp);
James Smart9589b0622011-04-16 11:03:17 -04007308
7309 /* NPIV LOGO completes to NPort <nlp_DID> */
7310 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7311 "2928 NPIV LOGO completes to NPort x%x "
7312 "Data: x%x x%x x%x x%x\n",
7313 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
7314 irsp->ulpTimeout, vport->num_disc_nodes);
7315
7316 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
7317 spin_lock_irq(shost->host_lock);
7318 vport->fc_flag &= ~FC_FABRIC;
7319 spin_unlock_irq(shost->host_lock);
7320 }
James Smart92d7f7b2007-06-17 19:56:38 -05007321}
7322
James Smarte59058c2008-08-24 21:49:00 -04007323/**
James Smart3621a712009-04-06 18:47:14 -04007324 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007325 * @vport: pointer to a virtual N_Port data structure.
7326 * @ndlp: pointer to a node-list data structure.
7327 *
7328 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7329 *
7330 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7331 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7332 * will be stored into the context1 field of the IOCB for the completion
7333 * callback function to the LOGO ELS command.
7334 *
7335 * Return codes
7336 * 0 - Successfully issued logo off the @vport
7337 * 1 - Failed to issue logo off the @vport
7338 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007339int
7340lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7341{
7342 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7343 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007344 IOCB_t *icmd;
7345 struct lpfc_iocbq *elsiocb;
7346 uint8_t *pcmd;
7347 uint16_t cmdsize;
7348
7349 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7350 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7351 ELS_CMD_LOGO);
7352 if (!elsiocb)
7353 return 1;
7354
7355 icmd = &elsiocb->iocb;
7356 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7357 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7358 pcmd += sizeof(uint32_t);
7359
7360 /* Fill in LOGO payload */
7361 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7362 pcmd += sizeof(uint32_t);
7363 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7364
James Smart858c9f62007-06-17 19:56:39 -05007365 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7366 "Issue LOGO npiv did:x%x flg:x%x",
7367 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7368
James Smart92d7f7b2007-06-17 19:56:38 -05007369 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7370 spin_lock_irq(shost->host_lock);
7371 ndlp->nlp_flag |= NLP_LOGO_SND;
7372 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007373 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7374 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007375 spin_lock_irq(shost->host_lock);
7376 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7377 spin_unlock_irq(shost->host_lock);
7378 lpfc_els_free_iocb(phba, elsiocb);
7379 return 1;
7380 }
7381 return 0;
7382}
7383
James Smarte59058c2008-08-24 21:49:00 -04007384/**
James Smart3621a712009-04-06 18:47:14 -04007385 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007386 * @ptr: holder for the timer function associated data.
7387 *
7388 * This routine is invoked by the fabric iocb block timer after
7389 * timeout. It posts the fabric iocb block timeout event by setting the
7390 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7391 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7392 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7393 * posted event WORKER_FABRIC_BLOCK_TMO.
7394 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007395void
7396lpfc_fabric_block_timeout(unsigned long ptr)
7397{
7398 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7399 unsigned long iflags;
7400 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007401
James Smart92d7f7b2007-06-17 19:56:38 -05007402 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7403 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7404 if (!tmo_posted)
7405 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7406 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7407
James Smart5e9d9b82008-06-14 22:52:53 -04007408 if (!tmo_posted)
7409 lpfc_worker_wake_up(phba);
7410 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007411}
7412
James Smarte59058c2008-08-24 21:49:00 -04007413/**
James Smart3621a712009-04-06 18:47:14 -04007414 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007415 * @phba: pointer to lpfc hba data structure.
7416 *
7417 * This routine issues one fabric iocb from the driver internal list to
7418 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7419 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7420 * remove one pending fabric iocb from the driver internal list and invokes
7421 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7422 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007423static void
7424lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7425{
7426 struct lpfc_iocbq *iocb;
7427 unsigned long iflags;
7428 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007429 IOCB_t *cmd;
7430
7431repeat:
7432 iocb = NULL;
7433 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007434 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007435 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7436 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7437 list);
7438 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007439 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007440 atomic_inc(&phba->fabric_iocb_count);
7441 }
7442 spin_unlock_irqrestore(&phba->hbalock, iflags);
7443 if (iocb) {
7444 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7445 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7446 iocb->iocb_flag |= LPFC_IO_FABRIC;
7447
James Smart858c9f62007-06-17 19:56:39 -05007448 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7449 "Fabric sched1: ste:x%x",
7450 iocb->vport->port_state, 0, 0);
7451
James Smart3772a992009-05-22 14:50:54 -04007452 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007453
7454 if (ret == IOCB_ERROR) {
7455 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7456 iocb->fabric_iocb_cmpl = NULL;
7457 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7458 cmd = &iocb->iocb;
7459 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7460 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7461 iocb->iocb_cmpl(phba, iocb, iocb);
7462
7463 atomic_dec(&phba->fabric_iocb_count);
7464 goto repeat;
7465 }
7466 }
7467
7468 return;
7469}
7470
James Smarte59058c2008-08-24 21:49:00 -04007471/**
James Smart3621a712009-04-06 18:47:14 -04007472 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007473 * @phba: pointer to lpfc hba data structure.
7474 *
7475 * This routine unblocks the issuing fabric iocb command. The function
7476 * will clear the fabric iocb block bit and then invoke the routine
7477 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7478 * from the driver internal fabric iocb list.
7479 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007480void
7481lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7482{
7483 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7484
7485 lpfc_resume_fabric_iocbs(phba);
7486 return;
7487}
7488
James Smarte59058c2008-08-24 21:49:00 -04007489/**
James Smart3621a712009-04-06 18:47:14 -04007490 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007491 * @phba: pointer to lpfc hba data structure.
7492 *
7493 * This routine blocks the issuing fabric iocb for a specified amount of
7494 * time (currently 100 ms). This is done by set the fabric iocb block bit
7495 * and set up a timeout timer for 100ms. When the block bit is set, no more
7496 * fabric iocb will be issued out of the HBA.
7497 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007498static void
7499lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7500{
7501 int blocked;
7502
7503 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007504 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007505 if (!blocked)
7506 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7507
7508 return;
7509}
7510
James Smarte59058c2008-08-24 21:49:00 -04007511/**
James Smart3621a712009-04-06 18:47:14 -04007512 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007513 * @phba: pointer to lpfc hba data structure.
7514 * @cmdiocb: pointer to lpfc command iocb data structure.
7515 * @rspiocb: pointer to lpfc response iocb data structure.
7516 *
7517 * This routine is the callback function that is put to the fabric iocb's
7518 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7519 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7520 * function first restores and invokes the original iocb's callback function
7521 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7522 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7523 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007524static void
7525lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7526 struct lpfc_iocbq *rspiocb)
7527{
7528 struct ls_rjt stat;
7529
7530 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7531 BUG();
7532
7533 switch (rspiocb->iocb.ulpStatus) {
7534 case IOSTAT_NPORT_RJT:
7535 case IOSTAT_FABRIC_RJT:
7536 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7537 lpfc_block_fabric_iocbs(phba);
7538 }
7539 break;
7540
7541 case IOSTAT_NPORT_BSY:
7542 case IOSTAT_FABRIC_BSY:
7543 lpfc_block_fabric_iocbs(phba);
7544 break;
7545
7546 case IOSTAT_LS_RJT:
7547 stat.un.lsRjtError =
7548 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7549 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7550 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7551 lpfc_block_fabric_iocbs(phba);
7552 break;
7553 }
7554
7555 if (atomic_read(&phba->fabric_iocb_count) == 0)
7556 BUG();
7557
7558 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7559 cmdiocb->fabric_iocb_cmpl = NULL;
7560 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7561 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7562
7563 atomic_dec(&phba->fabric_iocb_count);
7564 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007565 /* Post any pending iocbs to HBA */
7566 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007567 }
7568}
7569
James Smarte59058c2008-08-24 21:49:00 -04007570/**
James Smart3621a712009-04-06 18:47:14 -04007571 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007572 * @phba: pointer to lpfc hba data structure.
7573 * @iocb: pointer to lpfc command iocb data structure.
7574 *
7575 * This routine is used as the top-level API for issuing a fabric iocb command
7576 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7577 * function makes sure that only one fabric bound iocb will be outstanding at
7578 * any given time. As such, this function will first check to see whether there
7579 * is already an outstanding fabric iocb on the wire. If so, it will put the
7580 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7581 * issued later. Otherwise, it will issue the iocb on the wire and update the
7582 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7583 *
7584 * Note, this implementation has a potential sending out fabric IOCBs out of
7585 * order. The problem is caused by the construction of the "ready" boolen does
7586 * not include the condition that the internal fabric IOCB list is empty. As
7587 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7588 * ahead of the fabric IOCBs in the internal list.
7589 *
7590 * Return code
7591 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7592 * IOCB_ERROR - failed to issue fabric iocb
7593 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007594static int
James Smart92d7f7b2007-06-17 19:56:38 -05007595lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7596{
7597 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007598 int ready;
7599 int ret;
7600
7601 if (atomic_read(&phba->fabric_iocb_count) > 1)
7602 BUG();
7603
7604 spin_lock_irqsave(&phba->hbalock, iflags);
7605 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7606 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7607
James Smart7f5f3d02008-02-08 18:50:14 -05007608 if (ready)
7609 /* Increment fabric iocb count to hold the position */
7610 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007611 spin_unlock_irqrestore(&phba->hbalock, iflags);
7612 if (ready) {
7613 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7614 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7615 iocb->iocb_flag |= LPFC_IO_FABRIC;
7616
James Smart858c9f62007-06-17 19:56:39 -05007617 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7618 "Fabric sched2: ste:x%x",
7619 iocb->vport->port_state, 0, 0);
7620
James Smart3772a992009-05-22 14:50:54 -04007621 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007622
7623 if (ret == IOCB_ERROR) {
7624 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7625 iocb->fabric_iocb_cmpl = NULL;
7626 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7627 atomic_dec(&phba->fabric_iocb_count);
7628 }
7629 } else {
7630 spin_lock_irqsave(&phba->hbalock, iflags);
7631 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7632 spin_unlock_irqrestore(&phba->hbalock, iflags);
7633 ret = IOCB_SUCCESS;
7634 }
7635 return ret;
7636}
7637
James Smarte59058c2008-08-24 21:49:00 -04007638/**
James Smart3621a712009-04-06 18:47:14 -04007639 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007640 * @vport: pointer to a virtual N_Port data structure.
7641 *
7642 * This routine aborts all the IOCBs associated with a @vport from the
7643 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7644 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7645 * list, removes each IOCB associated with the @vport off the list, set the
7646 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7647 * associated with the IOCB.
7648 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007649static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007650{
7651 LIST_HEAD(completions);
7652 struct lpfc_hba *phba = vport->phba;
7653 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007654
7655 spin_lock_irq(&phba->hbalock);
7656 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7657 list) {
7658
7659 if (piocb->vport != vport)
7660 continue;
7661
7662 list_move_tail(&piocb->list, &completions);
7663 }
7664 spin_unlock_irq(&phba->hbalock);
7665
James Smarta257bf92009-04-06 18:48:10 -04007666 /* Cancel all the IOCBs from the completions list */
7667 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7668 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007669}
7670
James Smarte59058c2008-08-24 21:49:00 -04007671/**
James Smart3621a712009-04-06 18:47:14 -04007672 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007673 * @ndlp: pointer to a node-list data structure.
7674 *
7675 * This routine aborts all the IOCBs associated with an @ndlp from the
7676 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7677 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7678 * list, removes each IOCB associated with the @ndlp off the list, set the
7679 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7680 * associated with the IOCB.
7681 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007682void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7683{
7684 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007685 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007686 struct lpfc_iocbq *tmp_iocb, *piocb;
7687 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007688
7689 spin_lock_irq(&phba->hbalock);
7690 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7691 list) {
7692 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7693
7694 list_move_tail(&piocb->list, &completions);
7695 }
7696 }
7697 spin_unlock_irq(&phba->hbalock);
7698
James Smarta257bf92009-04-06 18:48:10 -04007699 /* Cancel all the IOCBs from the completions list */
7700 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7701 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007702}
7703
James Smarte59058c2008-08-24 21:49:00 -04007704/**
James Smart3621a712009-04-06 18:47:14 -04007705 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007706 * @phba: pointer to lpfc hba data structure.
7707 *
7708 * This routine aborts all the IOCBs currently on the driver internal
7709 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7710 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7711 * list, removes IOCBs off the list, set the status feild to
7712 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7713 * the IOCB.
7714 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007715void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7716{
7717 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007718
7719 spin_lock_irq(&phba->hbalock);
7720 list_splice_init(&phba->fabric_iocb_list, &completions);
7721 spin_unlock_irq(&phba->hbalock);
7722
James Smarta257bf92009-04-06 18:48:10 -04007723 /* Cancel all the IOCBs from the completions list */
7724 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7725 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007726}
James Smart6fb120a2009-05-22 14:52:59 -04007727
7728/**
James Smart1151e3e2011-02-16 12:39:35 -05007729 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7730 * @vport: pointer to lpfc vport data structure.
7731 *
7732 * This routine is invoked by the vport cleanup for deletions and the cleanup
7733 * for an ndlp on removal.
7734 **/
7735void
7736lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
7737{
7738 struct lpfc_hba *phba = vport->phba;
7739 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7740 unsigned long iflag = 0;
7741
7742 spin_lock_irqsave(&phba->hbalock, iflag);
7743 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7744 list_for_each_entry_safe(sglq_entry, sglq_next,
7745 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7746 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
7747 sglq_entry->ndlp = NULL;
7748 }
7749 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7750 spin_unlock_irqrestore(&phba->hbalock, iflag);
7751 return;
7752}
7753
7754/**
James Smart6fb120a2009-05-22 14:52:59 -04007755 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7756 * @phba: pointer to lpfc hba data structure.
7757 * @axri: pointer to the els xri abort wcqe structure.
7758 *
7759 * This routine is invoked by the worker thread to process a SLI4 slow-path
7760 * ELS aborted xri.
7761 **/
7762void
7763lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7764 struct sli4_wcqe_xri_aborted *axri)
7765{
7766 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05007767 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
7768
James Smart6fb120a2009-05-22 14:52:59 -04007769 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7770 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05007771 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04007772 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007773
James Smart0f65ff62010-02-26 14:14:23 -05007774 spin_lock_irqsave(&phba->hbalock, iflag);
7775 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007776 list_for_each_entry_safe(sglq_entry, sglq_next,
7777 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7778 if (sglq_entry->sli4_xritag == xri) {
7779 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05007780 ndlp = sglq_entry->ndlp;
7781 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04007782 list_add_tail(&sglq_entry->list,
7783 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007784 sglq_entry->state = SGL_FREED;
7785 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007786 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart19ca7602010-11-20 23:11:55 -05007787 lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04007788
7789 /* Check if TXQ queue needs to be serviced */
7790 if (pring->txq_cnt)
7791 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007792 return;
7793 }
7794 }
James Smart0f65ff62010-02-26 14:14:23 -05007795 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7796 sglq_entry = __lpfc_get_active_sglq(phba, xri);
7797 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7798 spin_unlock_irqrestore(&phba->hbalock, iflag);
7799 return;
7800 }
7801 sglq_entry->state = SGL_XRI_ABORTED;
7802 spin_unlock_irqrestore(&phba->hbalock, iflag);
7803 return;
James Smart6fb120a2009-05-22 14:52:59 -04007804}