blob: 04a5aeb41470d096e97f65a215288f2e5e247ba7 [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 Smart9589b062011-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 Smart9589b062011-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 Smart40426292010-12-15 17:58:10 -05001089 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1090 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1091 LPFC_SLI_INTF_IF_TYPE_0)) {
James Smart6fb120a2009-05-22 14:52:59 -04001092 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 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001098 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001099 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1100 icmd->ulpCt_h = 1;
1101 icmd->ulpCt_l = 0;
1102 }
1103
James Smart76a95d72010-11-20 23:11:48 -05001104 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001105 icmd->un.elsreq64.myID = 0;
1106 icmd->un.elsreq64.fl = 1;
1107 }
1108
dea31012005-04-17 16:05:31 -05001109 tmo = phba->fc_ratov;
1110 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001111 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001112 phba->fc_ratov = tmo;
1113
1114 phba->fc_stat.elsXmitFLOGI++;
1115 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001116
1117 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1118 "Issue FLOGI: opt:x%x",
1119 phba->sli3_options, 0, 0);
1120
James Smart92d7f7b2007-06-17 19:56:38 -05001121 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001122 if (rc == IOCB_ERROR) {
1123 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001124 return 1;
dea31012005-04-17 16:05:31 -05001125 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001126 return 0;
dea31012005-04-17 16:05:31 -05001127}
1128
James Smarte59058c2008-08-24 21:49:00 -04001129/**
James Smart3621a712009-04-06 18:47:14 -04001130 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001131 * @phba: pointer to lpfc hba data structure.
1132 *
1133 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1134 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1135 * list and issues an abort IOCB commond on each outstanding IOCB that
1136 * contains a active Fabric_DID ndlp. Note that this function is to issue
1137 * the abort IOCB command on all the outstanding IOCBs, thus when this
1138 * function returns, it does not guarantee all the IOCBs are actually aborted.
1139 *
1140 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001141 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001142 **/
dea31012005-04-17 16:05:31 -05001143int
James Smart2e0fef82007-06-17 19:56:36 -05001144lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001145{
1146 struct lpfc_sli_ring *pring;
1147 struct lpfc_iocbq *iocb, *next_iocb;
1148 struct lpfc_nodelist *ndlp;
1149 IOCB_t *icmd;
1150
1151 /* Abort outstanding I/O on NPort <nlp_DID> */
1152 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001153 "0201 Abort outstanding I/O on NPort x%x\n",
1154 Fabric_DID);
dea31012005-04-17 16:05:31 -05001155
1156 pring = &phba->sli.ring[LPFC_ELS_RING];
1157
1158 /*
1159 * Check the txcmplq for an iocb that matches the nport the driver is
1160 * searching for.
1161 */
James Smart2e0fef82007-06-17 19:56:36 -05001162 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001163 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1164 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001165 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1166 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001167 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001168 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1169 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001170 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001171 }
1172 }
James Smart2e0fef82007-06-17 19:56:36 -05001173 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001174
1175 return 0;
1176}
1177
James Smarte59058c2008-08-24 21:49:00 -04001178/**
James Smart3621a712009-04-06 18:47:14 -04001179 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001180 * @vport: pointer to a host virtual N_Port data structure.
1181 *
1182 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1183 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1184 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1185 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1186 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1187 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1188 * @vport.
1189 *
1190 * Return code
1191 * 0 - failed to issue initial flogi for @vport
1192 * 1 - successfully issued initial flogi for @vport
1193 **/
dea31012005-04-17 16:05:31 -05001194int
James Smart2e0fef82007-06-17 19:56:36 -05001195lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001196{
James Smart2e0fef82007-06-17 19:56:36 -05001197 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001198 struct lpfc_nodelist *ndlp;
1199
James Smart98c9ea52007-10-27 13:37:33 -04001200 vport->port_state = LPFC_FLOGI;
1201 lpfc_set_disctmo(vport);
1202
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001203 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001204 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001205 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001206 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001207 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1208 if (!ndlp)
1209 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001210 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001211 /* Set the node type */
1212 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001213 /* Put ndlp onto node list */
1214 lpfc_enqueue_node(vport, ndlp);
1215 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1216 /* re-setup ndlp without removing from node list */
1217 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1218 if (!ndlp)
1219 return 0;
dea31012005-04-17 16:05:31 -05001220 }
James Smart87af33f2007-10-27 13:37:43 -04001221
James Smart5ac6b302010-10-22 11:05:36 -04001222 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001223 /* This decrement of reference count to node shall kick off
1224 * the release of the node.
1225 */
James Smart329f9bc2007-04-25 09:53:01 -04001226 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001227 return 0;
1228 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001229 return 1;
dea31012005-04-17 16:05:31 -05001230}
1231
James Smarte59058c2008-08-24 21:49:00 -04001232/**
James Smart3621a712009-04-06 18:47:14 -04001233 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001234 * @vport: pointer to a host virtual N_Port data structure.
1235 *
1236 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1237 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1238 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1239 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1240 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1241 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1242 * @vport.
1243 *
1244 * Return code
1245 * 0 - failed to issue initial fdisc for @vport
1246 * 1 - successfully issued initial fdisc for @vport
1247 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001248int
1249lpfc_initial_fdisc(struct lpfc_vport *vport)
1250{
1251 struct lpfc_hba *phba = vport->phba;
1252 struct lpfc_nodelist *ndlp;
1253
1254 /* First look for the Fabric ndlp */
1255 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1256 if (!ndlp) {
1257 /* Cannot find existing Fabric ndlp, so allocate a new one */
1258 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1259 if (!ndlp)
1260 return 0;
1261 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001262 /* Put ndlp onto node list */
1263 lpfc_enqueue_node(vport, ndlp);
1264 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1265 /* re-setup ndlp without removing from node list */
1266 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1267 if (!ndlp)
1268 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001269 }
James Smarte47c9092008-02-08 18:49:26 -05001270
James Smart92d7f7b2007-06-17 19:56:38 -05001271 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001272 /* decrement node reference count to trigger the release of
1273 * the node.
1274 */
James Smart92d7f7b2007-06-17 19:56:38 -05001275 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001276 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001277 }
1278 return 1;
1279}
James Smart87af33f2007-10-27 13:37:43 -04001280
James Smarte59058c2008-08-24 21:49:00 -04001281/**
James Smart3621a712009-04-06 18:47:14 -04001282 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001283 * @vport: pointer to a host virtual N_Port data structure.
1284 *
1285 * This routine checks whether there are more remaining Port Logins
1286 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1287 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1288 * to issue ELS PLOGIs up to the configured discover threads with the
1289 * @vport (@vport->cfg_discovery_threads). The function also decrement
1290 * the @vport's num_disc_node by 1 if it is not already 0.
1291 **/
James Smart87af33f2007-10-27 13:37:43 -04001292void
James Smart2e0fef82007-06-17 19:56:36 -05001293lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001294{
1295 int sentplogi;
1296
James Smart2e0fef82007-06-17 19:56:36 -05001297 if (vport->num_disc_nodes)
1298 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001299
1300 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001301 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1302 "0232 Continue discovery with %d PLOGIs to go "
1303 "Data: x%x x%x x%x\n",
1304 vport->num_disc_nodes, vport->fc_plogi_cnt,
1305 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001306 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001307 if (vport->fc_flag & FC_NLP_MORE)
1308 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1309 sentplogi = lpfc_els_disc_plogi(vport);
1310
dea31012005-04-17 16:05:31 -05001311 return;
1312}
1313
James Smarte59058c2008-08-24 21:49:00 -04001314/**
James Smart3621a712009-04-06 18:47:14 -04001315 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001316 * @phba: pointer to lpfc hba data structure.
1317 * @prsp: pointer to response IOCB payload.
1318 * @ndlp: pointer to a node-list data structure.
1319 *
1320 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1321 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1322 * The following cases are considered N_Port confirmed:
1323 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1324 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1325 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1326 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1327 * 1) if there is a node on vport list other than the @ndlp with the same
1328 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1329 * on that node to release the RPI associated with the node; 2) if there is
1330 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1331 * into, a new node shall be allocated (or activated). In either case, the
1332 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1333 * be released and the new_ndlp shall be put on to the vport node list and
1334 * its pointer returned as the confirmed node.
1335 *
1336 * Note that before the @ndlp got "released", the keepDID from not-matching
1337 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1338 * of the @ndlp. This is because the release of @ndlp is actually to put it
1339 * into an inactive state on the vport node list and the vport node list
1340 * management algorithm does not allow two node with a same DID.
1341 *
1342 * Return code
1343 * pointer to the PLOGI N_Port @ndlp
1344 **/
James Smart488d1462006-03-07 15:02:37 -05001345static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001346lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001347 struct lpfc_nodelist *ndlp)
1348{
James Smart2e0fef82007-06-17 19:56:36 -05001349 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001350 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001351 struct lpfc_rport_data *rdata;
1352 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001353 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001354 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001355 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001356 int put_node;
1357 int put_rport;
James Smart19ca7602010-11-20 23:11:55 -05001358 struct lpfc_node_rrqs rrq;
James Smart488d1462006-03-07 15:02:37 -05001359
James Smart2fb9bd82006-12-02 13:33:57 -05001360 /* Fabric nodes can have the same WWPN so we don't bother searching
1361 * by WWPN. Just return the ndlp that was given to us.
1362 */
1363 if (ndlp->nlp_type & NLP_FABRIC)
1364 return ndlp;
1365
James Smart92d7f7b2007-06-17 19:56:38 -05001366 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001367 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001368
James Smart685f0bf2007-04-25 09:53:08 -04001369 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001370 * we have for that ndlp. If not, we have some work to do.
1371 */
James Smart2e0fef82007-06-17 19:56:36 -05001372 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001373
James Smarte47c9092008-02-08 18:49:26 -05001374 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001375 return ndlp;
James Smart19ca7602010-11-20 23:11:55 -05001376 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
James Smart488d1462006-03-07 15:02:37 -05001377
1378 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001379 rc = memcmp(&ndlp->nlp_portname, name,
1380 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001381 if (!rc)
1382 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001383 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1384 if (!new_ndlp)
1385 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001386 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001387 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001388 rc = memcmp(&ndlp->nlp_portname, name,
1389 sizeof(struct lpfc_name));
1390 if (!rc)
1391 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001392 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1393 NLP_STE_UNUSED_NODE);
1394 if (!new_ndlp)
1395 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001396 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001397 if (phba->sli_rev == LPFC_SLI_REV4)
1398 memcpy(&rrq.xri_bitmap,
1399 &new_ndlp->active_rrqs.xri_bitmap,
1400 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1401 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001402 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001403 if (phba->sli_rev == LPFC_SLI_REV4)
1404 memcpy(&rrq.xri_bitmap,
1405 &new_ndlp->active_rrqs.xri_bitmap,
1406 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1407 }
James Smart488d1462006-03-07 15:02:37 -05001408
James Smart2e0fef82007-06-17 19:56:36 -05001409 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001410 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001411 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001412 if (phba->sli_rev == LPFC_SLI_REV4)
1413 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1414 &ndlp->active_rrqs.xri_bitmap,
1415 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart0ff10d42008-01-11 01:52:36 -05001416
1417 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1418 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1419 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1420
James Smarte47c9092008-02-08 18:49:26 -05001421 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001422 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001423
James Smart2e0fef82007-06-17 19:56:36 -05001424 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001425 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1426 /* The new_ndlp is replacing ndlp totally, so we need
1427 * to put ndlp on UNUSED list and try to free it.
1428 */
James Smart0ff10d42008-01-11 01:52:36 -05001429
1430 /* Fix up the rport accordingly */
1431 rport = ndlp->rport;
1432 if (rport) {
1433 rdata = rport->dd_data;
1434 if (rdata->pnode == ndlp) {
1435 lpfc_nlp_put(ndlp);
1436 ndlp->rport = NULL;
1437 rdata->pnode = lpfc_nlp_get(new_ndlp);
1438 new_ndlp->rport = rport;
1439 }
1440 new_ndlp->nlp_type = ndlp->nlp_type;
1441 }
James Smart58da1ff2008-04-07 10:15:56 -04001442 /* We shall actually free the ndlp with both nlp_DID and
1443 * nlp_portname fields equals 0 to avoid any ndlp on the
1444 * nodelist never to be used.
1445 */
1446 if (ndlp->nlp_DID == 0) {
1447 spin_lock_irq(&phba->ndlp_lock);
1448 NLP_SET_FREE_REQ(ndlp);
1449 spin_unlock_irq(&phba->ndlp_lock);
1450 }
James Smart0ff10d42008-01-11 01:52:36 -05001451
James Smart58da1ff2008-04-07 10:15:56 -04001452 /* Two ndlps cannot have the same did on the nodelist */
1453 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001454 if (phba->sli_rev == LPFC_SLI_REV4)
1455 memcpy(&ndlp->active_rrqs.xri_bitmap,
1456 &rrq.xri_bitmap,
1457 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001458 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001459 }
James Smart92795652006-07-06 15:50:02 -04001460 else {
James Smart2e0fef82007-06-17 19:56:36 -05001461 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001462 /* Two ndlps cannot have the same did */
1463 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001464 if (phba->sli_rev == LPFC_SLI_REV4)
1465 memcpy(&ndlp->active_rrqs.xri_bitmap,
1466 &rrq.xri_bitmap,
1467 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001468 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart38b92ef2010-08-04 16:11:39 -04001469 /* Since we are swapping the ndlp passed in with the new one
1470 * and the did has already been swapped, copy over the
1471 * state and names.
1472 */
1473 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1474 sizeof(struct lpfc_name));
1475 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1476 sizeof(struct lpfc_name));
1477 new_ndlp->nlp_state = ndlp->nlp_state;
1478 /* Fix up the rport accordingly */
1479 rport = ndlp->rport;
1480 if (rport) {
1481 rdata = rport->dd_data;
1482 put_node = rdata->pnode != NULL;
1483 put_rport = ndlp->rport != NULL;
1484 rdata->pnode = NULL;
1485 ndlp->rport = NULL;
1486 if (put_node)
1487 lpfc_nlp_put(ndlp);
1488 if (put_rport)
1489 put_device(&rport->dev);
1490 }
James Smart92795652006-07-06 15:50:02 -04001491 }
James Smart488d1462006-03-07 15:02:37 -05001492 return new_ndlp;
1493}
1494
James Smarte59058c2008-08-24 21:49:00 -04001495/**
James Smart3621a712009-04-06 18:47:14 -04001496 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001497 * @vport: pointer to a host virtual N_Port data structure.
1498 *
1499 * This routine checks whether more Registration State Change
1500 * Notifications (RSCNs) came in while the discovery state machine was in
1501 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1502 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1503 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1504 * handling the RSCNs.
1505 **/
James Smart87af33f2007-10-27 13:37:43 -04001506void
1507lpfc_end_rscn(struct lpfc_vport *vport)
1508{
1509 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1510
1511 if (vport->fc_flag & FC_RSCN_MODE) {
1512 /*
1513 * Check to see if more RSCNs came in while we were
1514 * processing this one.
1515 */
1516 if (vport->fc_rscn_id_cnt ||
1517 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1518 lpfc_els_handle_rscn(vport);
1519 else {
1520 spin_lock_irq(shost->host_lock);
1521 vport->fc_flag &= ~FC_RSCN_MODE;
1522 spin_unlock_irq(shost->host_lock);
1523 }
1524 }
1525}
1526
James Smarte59058c2008-08-24 21:49:00 -04001527/**
James Smart19ca7602010-11-20 23:11:55 -05001528 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1529 * @phba: pointer to lpfc hba data structure.
1530 * @cmdiocb: pointer to lpfc command iocb data structure.
1531 * @rspiocb: pointer to lpfc response iocb data structure.
1532 *
1533 * This routine will call the clear rrq function to free the rrq and
1534 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1535 * exist then the clear_rrq is still called because the rrq needs to
1536 * be freed.
1537 **/
1538
1539static void
1540lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1541 struct lpfc_iocbq *rspiocb)
1542{
1543 struct lpfc_vport *vport = cmdiocb->vport;
1544 IOCB_t *irsp;
1545 struct lpfc_nodelist *ndlp;
1546 struct lpfc_node_rrq *rrq;
1547
1548 /* we pass cmdiocb to state machine which needs rspiocb as well */
1549 rrq = cmdiocb->context_un.rrq;
1550 cmdiocb->context_un.rsp_iocb = rspiocb;
1551
1552 irsp = &rspiocb->iocb;
1553 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1554 "RRQ cmpl: status:x%x/x%x did:x%x",
1555 irsp->ulpStatus, irsp->un.ulpWord[4],
1556 irsp->un.elsreq64.remoteID);
1557
1558 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1559 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1560 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1561 "2882 RRQ completes to NPort x%x "
1562 "with no ndlp. Data: x%x x%x x%x\n",
1563 irsp->un.elsreq64.remoteID,
1564 irsp->ulpStatus, irsp->un.ulpWord[4],
1565 irsp->ulpIoTag);
1566 goto out;
1567 }
1568
1569 /* rrq completes to NPort <nlp_DID> */
1570 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1571 "2880 RRQ completes to NPort x%x "
1572 "Data: x%x x%x x%x x%x x%x\n",
1573 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1574 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1575
1576 if (irsp->ulpStatus) {
1577 /* Check for retry */
1578 /* RRQ failed Don't print the vport to vport rjts */
1579 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1580 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1581 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1582 (phba)->pport->cfg_log_verbose & LOG_ELS)
1583 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1584 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1585 ndlp->nlp_DID, irsp->ulpStatus,
1586 irsp->un.ulpWord[4]);
1587 }
1588out:
1589 if (rrq)
1590 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1591 lpfc_els_free_iocb(phba, cmdiocb);
1592 return;
1593}
1594/**
James Smart3621a712009-04-06 18:47:14 -04001595 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001596 * @phba: pointer to lpfc hba data structure.
1597 * @cmdiocb: pointer to lpfc command iocb data structure.
1598 * @rspiocb: pointer to lpfc response iocb data structure.
1599 *
1600 * This routine is the completion callback function for issuing the Port
1601 * Login (PLOGI) command. For PLOGI completion, there must be an active
1602 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001603 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001604 * ignored and command IOCB released. The PLOGI response IOCB status is
1605 * checked for error conditons. If there is error status reported, PLOGI
1606 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1607 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1608 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1609 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1610 * there are additional N_Port nodes with the vport that need to perform
1611 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1612 * PLOGIs.
1613 **/
dea31012005-04-17 16:05:31 -05001614static void
James Smart2e0fef82007-06-17 19:56:36 -05001615lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1616 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001617{
James Smart2e0fef82007-06-17 19:56:36 -05001618 struct lpfc_vport *vport = cmdiocb->vport;
1619 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001620 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001621 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001622 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001623 int disc, rc, did, type;
1624
dea31012005-04-17 16:05:31 -05001625 /* we pass cmdiocb to state machine which needs rspiocb as well */
1626 cmdiocb->context_un.rsp_iocb = rspiocb;
1627
1628 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001629 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1630 "PLOGI cmpl: status:x%x/x%x did:x%x",
1631 irsp->ulpStatus, irsp->un.ulpWord[4],
1632 irsp->un.elsreq64.remoteID);
1633
James Smart2e0fef82007-06-17 19:56:36 -05001634 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001635 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001636 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1637 "0136 PLOGI completes to NPort x%x "
1638 "with no ndlp. Data: x%x x%x x%x\n",
1639 irsp->un.elsreq64.remoteID,
1640 irsp->ulpStatus, irsp->un.ulpWord[4],
1641 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001642 goto out;
James Smarted957682007-06-17 19:56:37 -05001643 }
dea31012005-04-17 16:05:31 -05001644
1645 /* Since ndlp can be freed in the disc state machine, note if this node
1646 * is being used during discovery.
1647 */
James Smart2e0fef82007-06-17 19:56:36 -05001648 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001649 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001650 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001651 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001652 rc = 0;
1653
1654 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001655 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1656 "0102 PLOGI completes to NPort x%x "
1657 "Data: x%x x%x x%x x%x x%x\n",
1658 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1659 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001660 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001661 if (lpfc_els_chk_latt(vport)) {
1662 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001663 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001664 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001665 goto out;
1666 }
1667
1668 /* ndlp could be freed in DSM, save these values now */
1669 type = ndlp->nlp_type;
1670 did = ndlp->nlp_DID;
1671
1672 if (irsp->ulpStatus) {
1673 /* Check for retry */
1674 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1675 /* ELS command is being retried */
1676 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001677 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001678 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001679 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001680 }
1681 goto out;
1682 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001683 /* PLOGI failed Don't print the vport to vport rjts */
1684 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1685 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1686 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1687 (phba)->pport->cfg_log_verbose & LOG_ELS)
1688 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001689 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1690 ndlp->nlp_DID, irsp->ulpStatus,
1691 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001692 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001693 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001694 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001695 else
James Smart2e0fef82007-06-17 19:56:36 -05001696 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001697 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001698 } else {
1699 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001700 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001701 cmdiocb->context2)->list.next,
1702 struct lpfc_dmabuf, list);
1703 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001704 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001705 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001706 }
1707
James Smart2e0fef82007-06-17 19:56:36 -05001708 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001709 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001710 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001711
James Smart2e0fef82007-06-17 19:56:36 -05001712 if (vport->num_disc_nodes == 0) {
1713 spin_lock_irq(shost->host_lock);
1714 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1715 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001716
James Smart2e0fef82007-06-17 19:56:36 -05001717 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001718 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001719 }
1720 }
1721
1722out:
1723 lpfc_els_free_iocb(phba, cmdiocb);
1724 return;
1725}
1726
James Smarte59058c2008-08-24 21:49:00 -04001727/**
James Smart3621a712009-04-06 18:47:14 -04001728 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001729 * @vport: pointer to a host virtual N_Port data structure.
1730 * @did: destination port identifier.
1731 * @retry: number of retries to the command IOCB.
1732 *
1733 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1734 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1735 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1736 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1737 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1738 *
1739 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1740 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1741 * will be stored into the context1 field of the IOCB for the completion
1742 * callback function to the PLOGI ELS command.
1743 *
1744 * Return code
1745 * 0 - Successfully issued a plogi for @vport
1746 * 1 - failed to issue a plogi for @vport
1747 **/
dea31012005-04-17 16:05:31 -05001748int
James Smart2e0fef82007-06-17 19:56:36 -05001749lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001750{
James Smart2e0fef82007-06-17 19:56:36 -05001751 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001752 struct serv_parm *sp;
1753 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001754 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001755 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001756 struct lpfc_sli *psli;
1757 uint8_t *pcmd;
1758 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001759 int ret;
dea31012005-04-17 16:05:31 -05001760
1761 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001762
James Smart98c9ea52007-10-27 13:37:33 -04001763 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001764 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1765 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001766
James Smarte47c9092008-02-08 18:49:26 -05001767 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001768 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001769 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001770 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001771 if (!elsiocb)
1772 return 1;
dea31012005-04-17 16:05:31 -05001773
1774 icmd = &elsiocb->iocb;
1775 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1776
1777 /* For PLOGI request, remainder of payload is service parameters */
1778 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001779 pcmd += sizeof(uint32_t);
1780 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001781 sp = (struct serv_parm *) pcmd;
1782
James Smart5ac6b302010-10-22 11:05:36 -04001783 /*
1784 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1785 * to device on remote loops work.
1786 */
1787 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1788 sp->cmn.altBbCredit = 1;
1789
dea31012005-04-17 16:05:31 -05001790 if (sp->cmn.fcphLow < FC_PH_4_3)
1791 sp->cmn.fcphLow = FC_PH_4_3;
1792
1793 if (sp->cmn.fcphHigh < FC_PH3)
1794 sp->cmn.fcphHigh = FC_PH3;
1795
James Smart858c9f62007-06-17 19:56:39 -05001796 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1797 "Issue PLOGI: did:x%x",
1798 did, 0, 0);
1799
dea31012005-04-17 16:05:31 -05001800 phba->fc_stat.elsXmitPLOGI++;
1801 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001802 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001803
1804 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001805 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001806 return 1;
dea31012005-04-17 16:05:31 -05001807 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001808 return 0;
dea31012005-04-17 16:05:31 -05001809}
1810
James Smarte59058c2008-08-24 21:49:00 -04001811/**
James Smart3621a712009-04-06 18:47:14 -04001812 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001813 * @phba: pointer to lpfc hba data structure.
1814 * @cmdiocb: pointer to lpfc command iocb data structure.
1815 * @rspiocb: pointer to lpfc response iocb data structure.
1816 *
1817 * This routine is the completion callback function for a Process Login
1818 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1819 * status. If there is error status reported, PRLI retry shall be attempted
1820 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1821 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1822 * ndlp to mark the PRLI completion.
1823 **/
dea31012005-04-17 16:05:31 -05001824static void
James Smart2e0fef82007-06-17 19:56:36 -05001825lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1826 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001827{
James Smart2e0fef82007-06-17 19:56:36 -05001828 struct lpfc_vport *vport = cmdiocb->vport;
1829 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001830 IOCB_t *irsp;
1831 struct lpfc_sli *psli;
1832 struct lpfc_nodelist *ndlp;
1833
1834 psli = &phba->sli;
1835 /* we pass cmdiocb to state machine which needs rspiocb as well */
1836 cmdiocb->context_un.rsp_iocb = rspiocb;
1837
1838 irsp = &(rspiocb->iocb);
1839 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001840 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001841 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001842 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001843
James Smart858c9f62007-06-17 19:56:39 -05001844 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1845 "PRLI cmpl: status:x%x/x%x did:x%x",
1846 irsp->ulpStatus, irsp->un.ulpWord[4],
1847 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001848 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001849 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1850 "0103 PRLI completes to NPort x%x "
1851 "Data: x%x x%x x%x x%x\n",
1852 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1853 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001854
James Smart2e0fef82007-06-17 19:56:36 -05001855 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001856 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001857 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001858 goto out;
1859
1860 if (irsp->ulpStatus) {
1861 /* Check for retry */
1862 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1863 /* ELS command is being retried */
1864 goto out;
1865 }
1866 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001867 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1868 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1869 ndlp->nlp_DID, irsp->ulpStatus,
1870 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001871 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001872 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001873 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001874 else
James Smart2e0fef82007-06-17 19:56:36 -05001875 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001876 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001877 } else
dea31012005-04-17 16:05:31 -05001878 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001879 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001880 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001881out:
1882 lpfc_els_free_iocb(phba, cmdiocb);
1883 return;
1884}
1885
James Smarte59058c2008-08-24 21:49:00 -04001886/**
James Smart3621a712009-04-06 18:47:14 -04001887 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001888 * @vport: pointer to a host virtual N_Port data structure.
1889 * @ndlp: pointer to a node-list data structure.
1890 * @retry: number of retries to the command IOCB.
1891 *
1892 * This routine issues a Process Login (PRLI) ELS command for the
1893 * @vport. The PRLI service parameters are set up in the payload of the
1894 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1895 * is put to the IOCB completion callback func field before invoking the
1896 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1897 *
1898 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1899 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1900 * will be stored into the context1 field of the IOCB for the completion
1901 * callback function to the PRLI ELS command.
1902 *
1903 * Return code
1904 * 0 - successfully issued prli iocb command for @vport
1905 * 1 - failed to issue prli iocb command for @vport
1906 **/
dea31012005-04-17 16:05:31 -05001907int
James Smart2e0fef82007-06-17 19:56:36 -05001908lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001909 uint8_t retry)
1910{
James Smart2e0fef82007-06-17 19:56:36 -05001911 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1912 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001913 PRLI *npr;
1914 IOCB_t *icmd;
1915 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001916 uint8_t *pcmd;
1917 uint16_t cmdsize;
1918
James Smart92d7f7b2007-06-17 19:56:38 -05001919 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001920 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1921 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001922 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001923 return 1;
dea31012005-04-17 16:05:31 -05001924
1925 icmd = &elsiocb->iocb;
1926 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1927
1928 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001929 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001930 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001931 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001932
1933 /* For PRLI, remainder of payload is PRLI parameter page */
1934 npr = (PRLI *) pcmd;
1935 /*
1936 * If our firmware version is 3.20 or later,
1937 * set the following bits for FC-TAPE support.
1938 */
1939 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1940 npr->ConfmComplAllowed = 1;
1941 npr->Retry = 1;
1942 npr->TaskRetryIdReq = 1;
1943 }
1944 npr->estabImagePair = 1;
1945 npr->readXferRdyDis = 1;
1946
1947 /* For FCP support */
1948 npr->prliType = PRLI_FCP_TYPE;
1949 npr->initiatorFunc = 1;
1950
James Smart858c9f62007-06-17 19:56:39 -05001951 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1952 "Issue PRLI: did:x%x",
1953 ndlp->nlp_DID, 0, 0);
1954
dea31012005-04-17 16:05:31 -05001955 phba->fc_stat.elsXmitPRLI++;
1956 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001957 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001958 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001959 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001960 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1961 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001962 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001963 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001964 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001965 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001966 return 1;
dea31012005-04-17 16:05:31 -05001967 }
James Smart2e0fef82007-06-17 19:56:36 -05001968 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001969 return 0;
dea31012005-04-17 16:05:31 -05001970}
1971
James Smarte59058c2008-08-24 21:49:00 -04001972/**
James Smart3621a712009-04-06 18:47:14 -04001973 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001974 * @vport: pointer to a host virtual N_Port data structure.
1975 *
1976 * This routine performs Registration State Change Notification (RSCN)
1977 * discovery for a @vport. If the @vport's node port recovery count is not
1978 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1979 * the nodes that need recovery. If none of the PLOGI were needed through
1980 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1981 * invoked to check and handle possible more RSCN came in during the period
1982 * of processing the current ones.
1983 **/
1984static void
1985lpfc_rscn_disc(struct lpfc_vport *vport)
1986{
1987 lpfc_can_disctmo(vport);
1988
1989 /* RSCN discovery */
1990 /* go thru NPR nodes and issue ELS PLOGIs */
1991 if (vport->fc_npr_cnt)
1992 if (lpfc_els_disc_plogi(vport))
1993 return;
1994
1995 lpfc_end_rscn(vport);
1996}
1997
1998/**
James Smart3621a712009-04-06 18:47:14 -04001999 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002000 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2001 *
2002 * This function is called when the final ADISC is completed during discovery.
2003 * This function handles clearing link attention or issuing reg_vpi depending
2004 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2005 * discovery.
2006 * This function is called with no locks held.
2007 **/
2008static void
2009lpfc_adisc_done(struct lpfc_vport *vport)
2010{
2011 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2012 struct lpfc_hba *phba = vport->phba;
2013
2014 /*
2015 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2016 * and continue discovery.
2017 */
2018 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002019 !(vport->fc_flag & FC_RSCN_MODE) &&
2020 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04002021 lpfc_issue_reg_vpi(phba, vport);
2022 return;
2023 }
2024 /*
2025 * For SLI2, we need to set port_state to READY
2026 * and continue discovery.
2027 */
2028 if (vport->port_state < LPFC_VPORT_READY) {
2029 /* If we get here, there is nothing to ADISC */
2030 if (vport->port_type == LPFC_PHYSICAL_PORT)
2031 lpfc_issue_clear_la(phba, vport);
2032 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2033 vport->num_disc_nodes = 0;
2034 /* go thru NPR list, issue ELS PLOGIs */
2035 if (vport->fc_npr_cnt)
2036 lpfc_els_disc_plogi(vport);
2037 if (!vport->num_disc_nodes) {
2038 spin_lock_irq(shost->host_lock);
2039 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2040 spin_unlock_irq(shost->host_lock);
2041 lpfc_can_disctmo(vport);
2042 lpfc_end_rscn(vport);
2043 }
2044 }
2045 vport->port_state = LPFC_VPORT_READY;
2046 } else
2047 lpfc_rscn_disc(vport);
2048}
2049
2050/**
James Smart3621a712009-04-06 18:47:14 -04002051 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002052 * @vport: pointer to a host virtual N_Port data structure.
2053 *
2054 * This routine determines whether there are more ndlps on a @vport
2055 * node list need to have Address Discover (ADISC) issued. If so, it will
2056 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2057 * remaining nodes which need to have ADISC sent.
2058 **/
James Smart0ff10d42008-01-11 01:52:36 -05002059void
James Smart2e0fef82007-06-17 19:56:36 -05002060lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002061{
2062 int sentadisc;
2063
James Smart2e0fef82007-06-17 19:56:36 -05002064 if (vport->num_disc_nodes)
2065 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002066 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002067 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2068 "0210 Continue discovery with %d ADISCs to go "
2069 "Data: x%x x%x x%x\n",
2070 vport->num_disc_nodes, vport->fc_adisc_cnt,
2071 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002072 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002073 if (vport->fc_flag & FC_NLP_MORE) {
2074 lpfc_set_disctmo(vport);
2075 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2076 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002077 }
James Smart90160e02008-08-24 21:49:45 -04002078 if (!vport->num_disc_nodes)
2079 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002080 return;
2081}
2082
James Smarte59058c2008-08-24 21:49:00 -04002083/**
James Smart3621a712009-04-06 18:47:14 -04002084 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002085 * @phba: pointer to lpfc hba data structure.
2086 * @cmdiocb: pointer to lpfc command iocb data structure.
2087 * @rspiocb: pointer to lpfc response iocb data structure.
2088 *
2089 * This routine is the completion function for issuing the Address Discover
2090 * (ADISC) command. It first checks to see whether link went down during
2091 * the discovery process. If so, the node will be marked as node port
2092 * recovery for issuing discover IOCB by the link attention handler and
2093 * exit. Otherwise, the response status is checked. If error was reported
2094 * in the response status, the ADISC command shall be retried by invoking
2095 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2096 * the response status, the state machine is invoked to set transition
2097 * with respect to NLP_EVT_CMPL_ADISC event.
2098 **/
dea31012005-04-17 16:05:31 -05002099static void
James Smart2e0fef82007-06-17 19:56:36 -05002100lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2101 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002102{
James Smart2e0fef82007-06-17 19:56:36 -05002103 struct lpfc_vport *vport = cmdiocb->vport;
2104 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002105 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002106 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002107 int disc;
dea31012005-04-17 16:05:31 -05002108
2109 /* we pass cmdiocb to state machine which needs rspiocb as well */
2110 cmdiocb->context_un.rsp_iocb = rspiocb;
2111
2112 irsp = &(rspiocb->iocb);
2113 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002114
James Smart858c9f62007-06-17 19:56:39 -05002115 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2116 "ADISC cmpl: status:x%x/x%x did:x%x",
2117 irsp->ulpStatus, irsp->un.ulpWord[4],
2118 ndlp->nlp_DID);
2119
dea31012005-04-17 16:05:31 -05002120 /* Since ndlp can be freed in the disc state machine, note if this node
2121 * is being used during discovery.
2122 */
James Smart2e0fef82007-06-17 19:56:36 -05002123 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002124 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002125 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002126 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002127 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002128 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2129 "0104 ADISC completes to NPort x%x "
2130 "Data: x%x x%x x%x x%x x%x\n",
2131 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2132 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002133 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002134 if (lpfc_els_chk_latt(vport)) {
2135 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002136 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002137 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002138 goto out;
2139 }
2140
2141 if (irsp->ulpStatus) {
2142 /* Check for retry */
2143 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2144 /* ELS command is being retried */
2145 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002146 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002147 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002148 spin_unlock_irq(shost->host_lock);
2149 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002150 }
2151 goto out;
2152 }
2153 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002154 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2155 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2156 ndlp->nlp_DID, irsp->ulpStatus,
2157 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002158 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002159 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002160 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002161 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002162 } else
dea31012005-04-17 16:05:31 -05002163 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002164 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002165 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002166
James Smart90160e02008-08-24 21:49:45 -04002167 /* Check to see if there are more ADISCs to be sent */
2168 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002169 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002170out:
2171 lpfc_els_free_iocb(phba, cmdiocb);
2172 return;
2173}
2174
James Smarte59058c2008-08-24 21:49:00 -04002175/**
James Smart3621a712009-04-06 18:47:14 -04002176 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002177 * @vport: pointer to a virtual N_Port data structure.
2178 * @ndlp: pointer to a node-list data structure.
2179 * @retry: number of retries to the command IOCB.
2180 *
2181 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2182 * @vport. It prepares the payload of the ADISC ELS command, updates the
2183 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2184 * to issue the ADISC ELS command.
2185 *
2186 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2187 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2188 * will be stored into the context1 field of the IOCB for the completion
2189 * callback function to the ADISC ELS command.
2190 *
2191 * Return code
2192 * 0 - successfully issued adisc
2193 * 1 - failed to issue adisc
2194 **/
dea31012005-04-17 16:05:31 -05002195int
James Smart2e0fef82007-06-17 19:56:36 -05002196lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002197 uint8_t retry)
2198{
James Smart2e0fef82007-06-17 19:56:36 -05002199 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2200 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002201 ADISC *ap;
2202 IOCB_t *icmd;
2203 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002204 uint8_t *pcmd;
2205 uint16_t cmdsize;
2206
James Smart92d7f7b2007-06-17 19:56:38 -05002207 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002208 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2209 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002210 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002211 return 1;
dea31012005-04-17 16:05:31 -05002212
2213 icmd = &elsiocb->iocb;
2214 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2215
2216 /* For ADISC request, remainder of payload is service parameters */
2217 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002218 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002219
2220 /* Fill in ADISC payload */
2221 ap = (ADISC *) pcmd;
2222 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002223 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2224 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002225 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002226
James Smart858c9f62007-06-17 19:56:39 -05002227 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2228 "Issue ADISC: did:x%x",
2229 ndlp->nlp_DID, 0, 0);
2230
dea31012005-04-17 16:05:31 -05002231 phba->fc_stat.elsXmitADISC++;
2232 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002233 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002234 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002235 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002236 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2237 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002238 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002239 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002240 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002241 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002242 return 1;
dea31012005-04-17 16:05:31 -05002243 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002244 return 0;
dea31012005-04-17 16:05:31 -05002245}
2246
James Smarte59058c2008-08-24 21:49:00 -04002247/**
James Smart3621a712009-04-06 18:47:14 -04002248 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002249 * @phba: pointer to lpfc hba data structure.
2250 * @cmdiocb: pointer to lpfc command iocb data structure.
2251 * @rspiocb: pointer to lpfc response iocb data structure.
2252 *
2253 * This routine is the completion function for issuing the ELS Logout (LOGO)
2254 * command. If no error status was reported from the LOGO response, the
2255 * state machine of the associated ndlp shall be invoked for transition with
2256 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2257 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2258 **/
dea31012005-04-17 16:05:31 -05002259static void
James Smart2e0fef82007-06-17 19:56:36 -05002260lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2261 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002262{
James Smart2e0fef82007-06-17 19:56:36 -05002263 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2264 struct lpfc_vport *vport = ndlp->vport;
2265 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002266 IOCB_t *irsp;
2267 struct lpfc_sli *psli;
James Smart92494142011-02-16 12:39:44 -05002268 struct lpfcMboxq *mbox;
dea31012005-04-17 16:05:31 -05002269
2270 psli = &phba->sli;
2271 /* we pass cmdiocb to state machine which needs rspiocb as well */
2272 cmdiocb->context_un.rsp_iocb = rspiocb;
2273
2274 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002275 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002276 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002277 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002278
James Smart858c9f62007-06-17 19:56:39 -05002279 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2280 "LOGO cmpl: status:x%x/x%x did:x%x",
2281 irsp->ulpStatus, irsp->un.ulpWord[4],
2282 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002283 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002284 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2285 "0105 LOGO completes to NPort x%x "
2286 "Data: x%x x%x x%x x%x\n",
2287 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2288 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002289 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002290 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002291 goto out;
2292
James Smart92d7f7b2007-06-17 19:56:38 -05002293 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2294 /* NLP_EVT_DEVICE_RM should unregister the RPI
2295 * which should abort all outstanding IOs.
2296 */
2297 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2298 NLP_EVT_DEVICE_RM);
2299 goto out;
2300 }
2301
dea31012005-04-17 16:05:31 -05002302 if (irsp->ulpStatus) {
2303 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002304 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002305 /* ELS command is being retried */
2306 goto out;
dea31012005-04-17 16:05:31 -05002307 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002308 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2309 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2310 ndlp->nlp_DID, irsp->ulpStatus,
2311 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002312 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002313 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002314 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002315 else
James Smart2e0fef82007-06-17 19:56:36 -05002316 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002317 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002318 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002319 /* Good status, call state machine.
2320 * This will unregister the rpi if needed.
2321 */
James Smart2e0fef82007-06-17 19:56:36 -05002322 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002323 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002324out:
2325 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002326 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2327 if ((vport->fc_flag & FC_PT2PT) &&
2328 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2329 phba->pport->fc_myDID = 0;
2330 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2331 if (mbox) {
2332 lpfc_config_link(phba, mbox);
2333 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2334 mbox->vport = vport;
2335 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2336 MBX_NOT_FINISHED) {
2337 mempool_free(mbox, phba->mbox_mem_pool);
2338 }
2339 }
2340 }
dea31012005-04-17 16:05:31 -05002341 return;
2342}
2343
James Smarte59058c2008-08-24 21:49:00 -04002344/**
James Smart3621a712009-04-06 18:47:14 -04002345 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002346 * @vport: pointer to a virtual N_Port data structure.
2347 * @ndlp: pointer to a node-list data structure.
2348 * @retry: number of retries to the command IOCB.
2349 *
2350 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2351 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2352 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2353 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2354 *
2355 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2356 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2357 * will be stored into the context1 field of the IOCB for the completion
2358 * callback function to the LOGO ELS command.
2359 *
2360 * Return code
2361 * 0 - successfully issued logo
2362 * 1 - failed to issue logo
2363 **/
dea31012005-04-17 16:05:31 -05002364int
James Smart2e0fef82007-06-17 19:56:36 -05002365lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002366 uint8_t retry)
2367{
James Smart2e0fef82007-06-17 19:56:36 -05002368 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2369 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002370 IOCB_t *icmd;
2371 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002372 uint8_t *pcmd;
2373 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002374 int rc;
dea31012005-04-17 16:05:31 -05002375
James Smart98c9ea52007-10-27 13:37:33 -04002376 spin_lock_irq(shost->host_lock);
2377 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2378 spin_unlock_irq(shost->host_lock);
2379 return 0;
2380 }
2381 spin_unlock_irq(shost->host_lock);
2382
James Smart92d7f7b2007-06-17 19:56:38 -05002383 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002384 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2385 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002386 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002387 return 1;
dea31012005-04-17 16:05:31 -05002388
2389 icmd = &elsiocb->iocb;
2390 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2391 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002392 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002393
2394 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002395 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002396 pcmd += sizeof(uint32_t);
2397 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002398
James Smart858c9f62007-06-17 19:56:39 -05002399 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2400 "Issue LOGO: did:x%x",
2401 ndlp->nlp_DID, 0, 0);
2402
dea31012005-04-17 16:05:31 -05002403 phba->fc_stat.elsXmitLOGO++;
2404 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002405 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002406 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002407 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002408 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002409
2410 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002411 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002412 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002413 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002414 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002415 return 1;
dea31012005-04-17 16:05:31 -05002416 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002417 return 0;
dea31012005-04-17 16:05:31 -05002418}
2419
James Smarte59058c2008-08-24 21:49:00 -04002420/**
James Smart3621a712009-04-06 18:47:14 -04002421 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002422 * @phba: pointer to lpfc hba data structure.
2423 * @cmdiocb: pointer to lpfc command iocb data structure.
2424 * @rspiocb: pointer to lpfc response iocb data structure.
2425 *
2426 * This routine is a generic completion callback function for ELS commands.
2427 * Specifically, it is the callback function which does not need to perform
2428 * any command specific operations. It is currently used by the ELS command
2429 * issuing routines for the ELS State Change Request (SCR),
2430 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2431 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2432 * certain debug loggings, this callback function simply invokes the
2433 * lpfc_els_chk_latt() routine to check whether link went down during the
2434 * discovery process.
2435 **/
dea31012005-04-17 16:05:31 -05002436static void
James Smart2e0fef82007-06-17 19:56:36 -05002437lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2438 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002439{
James Smart2e0fef82007-06-17 19:56:36 -05002440 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002441 IOCB_t *irsp;
2442
2443 irsp = &rspiocb->iocb;
2444
James Smart858c9f62007-06-17 19:56:39 -05002445 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2446 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2447 irsp->ulpStatus, irsp->un.ulpWord[4],
2448 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002449 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002450 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2451 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2452 irsp->ulpIoTag, irsp->ulpStatus,
2453 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002454 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002455 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002456 lpfc_els_free_iocb(phba, cmdiocb);
2457 return;
2458}
2459
James Smarte59058c2008-08-24 21:49:00 -04002460/**
James Smart3621a712009-04-06 18:47:14 -04002461 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002462 * @vport: pointer to a host virtual N_Port data structure.
2463 * @nportid: N_Port identifier to the remote node.
2464 * @retry: number of retries to the command IOCB.
2465 *
2466 * This routine issues a State Change Request (SCR) to a fabric node
2467 * on a @vport. The remote node @nportid is passed into the function. It
2468 * first search the @vport node list to find the matching ndlp. If no such
2469 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2470 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2471 * routine is invoked to send the SCR IOCB.
2472 *
2473 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2474 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2475 * will be stored into the context1 field of the IOCB for the completion
2476 * callback function to the SCR ELS command.
2477 *
2478 * Return code
2479 * 0 - Successfully issued scr command
2480 * 1 - Failed to issue scr command
2481 **/
dea31012005-04-17 16:05:31 -05002482int
James Smart2e0fef82007-06-17 19:56:36 -05002483lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002484{
James Smart2e0fef82007-06-17 19:56:36 -05002485 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002486 IOCB_t *icmd;
2487 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002488 struct lpfc_sli *psli;
2489 uint8_t *pcmd;
2490 uint16_t cmdsize;
2491 struct lpfc_nodelist *ndlp;
2492
2493 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002494 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002495
James Smarte47c9092008-02-08 18:49:26 -05002496 ndlp = lpfc_findnode_did(vport, nportid);
2497 if (!ndlp) {
2498 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2499 if (!ndlp)
2500 return 1;
2501 lpfc_nlp_init(vport, ndlp, nportid);
2502 lpfc_enqueue_node(vport, ndlp);
2503 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2504 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2505 if (!ndlp)
2506 return 1;
2507 }
dea31012005-04-17 16:05:31 -05002508
James Smart2e0fef82007-06-17 19:56:36 -05002509 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2510 ndlp->nlp_DID, ELS_CMD_SCR);
2511
James Smart488d1462006-03-07 15:02:37 -05002512 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002513 /* This will trigger the release of the node just
2514 * allocated
2515 */
James Smart329f9bc2007-04-25 09:53:01 -04002516 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002517 return 1;
dea31012005-04-17 16:05:31 -05002518 }
2519
2520 icmd = &elsiocb->iocb;
2521 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2522
2523 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002524 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002525
2526 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002527 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002528 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2529
James Smart858c9f62007-06-17 19:56:39 -05002530 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2531 "Issue SCR: did:x%x",
2532 ndlp->nlp_DID, 0, 0);
2533
dea31012005-04-17 16:05:31 -05002534 phba->fc_stat.elsXmitSCR++;
2535 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002536 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2537 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002538 /* The additional lpfc_nlp_put will cause the following
2539 * lpfc_els_free_iocb routine to trigger the rlease of
2540 * the node.
2541 */
James Smart329f9bc2007-04-25 09:53:01 -04002542 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002543 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002544 return 1;
dea31012005-04-17 16:05:31 -05002545 }
James Smartfa4066b2008-01-11 01:53:27 -05002546 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2547 * trigger the release of node.
2548 */
James Smart329f9bc2007-04-25 09:53:01 -04002549 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002550 return 0;
dea31012005-04-17 16:05:31 -05002551}
2552
James Smarte59058c2008-08-24 21:49:00 -04002553/**
James Smart3621a712009-04-06 18:47:14 -04002554 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002555 * @vport: pointer to a host virtual N_Port data structure.
2556 * @nportid: N_Port identifier to the remote node.
2557 * @retry: number of retries to the command IOCB.
2558 *
2559 * This routine issues a Fibre Channel Address Resolution Response
2560 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2561 * is passed into the function. It first search the @vport node list to find
2562 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2563 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2564 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2565 *
2566 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2567 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2568 * will be stored into the context1 field of the IOCB for the completion
2569 * callback function to the PARPR ELS command.
2570 *
2571 * Return code
2572 * 0 - Successfully issued farpr command
2573 * 1 - Failed to issue farpr command
2574 **/
dea31012005-04-17 16:05:31 -05002575static int
James Smart2e0fef82007-06-17 19:56:36 -05002576lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002577{
James Smart2e0fef82007-06-17 19:56:36 -05002578 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002579 IOCB_t *icmd;
2580 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002581 struct lpfc_sli *psli;
2582 FARP *fp;
2583 uint8_t *pcmd;
2584 uint32_t *lp;
2585 uint16_t cmdsize;
2586 struct lpfc_nodelist *ondlp;
2587 struct lpfc_nodelist *ndlp;
2588
2589 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002590 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002591
James Smarte47c9092008-02-08 18:49:26 -05002592 ndlp = lpfc_findnode_did(vport, nportid);
2593 if (!ndlp) {
2594 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2595 if (!ndlp)
2596 return 1;
2597 lpfc_nlp_init(vport, ndlp, nportid);
2598 lpfc_enqueue_node(vport, ndlp);
2599 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2600 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2601 if (!ndlp)
2602 return 1;
2603 }
James Smart2e0fef82007-06-17 19:56:36 -05002604
2605 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2606 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002607 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002608 /* This will trigger the release of the node just
2609 * allocated
2610 */
James Smart329f9bc2007-04-25 09:53:01 -04002611 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002612 return 1;
dea31012005-04-17 16:05:31 -05002613 }
2614
2615 icmd = &elsiocb->iocb;
2616 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2617
2618 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002619 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002620
2621 /* Fill in FARPR payload */
2622 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002623 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002624 lp = (uint32_t *) pcmd;
2625 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002626 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002627 fp->Rflags = 0;
2628 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2629
James Smart92d7f7b2007-06-17 19:56:38 -05002630 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2631 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002632 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002633 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002634 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002635 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002636 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002637 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002638 }
2639
James Smart858c9f62007-06-17 19:56:39 -05002640 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2641 "Issue FARPR: did:x%x",
2642 ndlp->nlp_DID, 0, 0);
2643
dea31012005-04-17 16:05:31 -05002644 phba->fc_stat.elsXmitFARPR++;
2645 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002646 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2647 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002648 /* The additional lpfc_nlp_put will cause the following
2649 * lpfc_els_free_iocb routine to trigger the release of
2650 * the node.
2651 */
James Smart329f9bc2007-04-25 09:53:01 -04002652 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002653 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002654 return 1;
dea31012005-04-17 16:05:31 -05002655 }
James Smartfa4066b2008-01-11 01:53:27 -05002656 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2657 * trigger the release of the node.
2658 */
James Smart329f9bc2007-04-25 09:53:01 -04002659 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002660 return 0;
dea31012005-04-17 16:05:31 -05002661}
2662
James Smarte59058c2008-08-24 21:49:00 -04002663/**
James Smart3621a712009-04-06 18:47:14 -04002664 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002665 * @vport: pointer to a host virtual N_Port data structure.
2666 * @nlp: pointer to a node-list data structure.
2667 *
2668 * This routine cancels the timer with a delayed IOCB-command retry for
2669 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2670 * removes the ELS retry event if it presents. In addition, if the
2671 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2672 * commands are sent for the @vport's nodes that require issuing discovery
2673 * ADISC.
2674 **/
dea31012005-04-17 16:05:31 -05002675void
James Smart2e0fef82007-06-17 19:56:36 -05002676lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002677{
James Smart2e0fef82007-06-17 19:56:36 -05002678 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002679 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002680
James Smart0d2b6b82008-06-14 22:52:47 -04002681 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2682 return;
James Smart2e0fef82007-06-17 19:56:36 -05002683 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002684 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002685 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002686 del_timer_sync(&nlp->nlp_delayfunc);
2687 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002688 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002689 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002690 /* Decrement nlp reference count held for the delayed retry */
2691 evtp = &nlp->els_retry_evt;
2692 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2693 }
James Smartfdcebe22006-03-07 15:04:01 -05002694 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002695 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002696 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002697 spin_unlock_irq(shost->host_lock);
2698 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002699 if (vport->port_state < LPFC_VPORT_READY) {
2700 /* Check if there are more ADISCs to be sent */
2701 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002702 } else {
2703 /* Check if there are more PLOGIs to be sent */
2704 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002705 if (vport->num_disc_nodes == 0) {
2706 spin_lock_irq(shost->host_lock);
2707 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2708 spin_unlock_irq(shost->host_lock);
2709 lpfc_can_disctmo(vport);
2710 lpfc_end_rscn(vport);
2711 }
James Smartfdcebe22006-03-07 15:04:01 -05002712 }
2713 }
2714 }
2715 return;
2716}
2717
James Smarte59058c2008-08-24 21:49:00 -04002718/**
James Smart3621a712009-04-06 18:47:14 -04002719 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002720 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2721 *
2722 * This routine is invoked by the ndlp delayed-function timer to check
2723 * whether there is any pending ELS retry event(s) with the node. If not, it
2724 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2725 * adds the delayed events to the HBA work list and invokes the
2726 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2727 * event. Note that lpfc_nlp_get() is called before posting the event to
2728 * the work list to hold reference count of ndlp so that it guarantees the
2729 * reference to ndlp will still be available when the worker thread gets
2730 * to the event associated with the ndlp.
2731 **/
James Smartfdcebe22006-03-07 15:04:01 -05002732void
dea31012005-04-17 16:05:31 -05002733lpfc_els_retry_delay(unsigned long ptr)
2734{
James Smart2e0fef82007-06-17 19:56:36 -05002735 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2736 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002737 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002738 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002739 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002740
James Smart92d7f7b2007-06-17 19:56:38 -05002741 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002742 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002743 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002744 return;
2745 }
2746
James Smartfa4066b2008-01-11 01:53:27 -05002747 /* We need to hold the node by incrementing the reference
2748 * count until the queued work is done
2749 */
2750 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002751 if (evtp->evt_arg1) {
2752 evtp->evt = LPFC_EVT_ELS_RETRY;
2753 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002754 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002755 }
James Smart92d7f7b2007-06-17 19:56:38 -05002756 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002757 return;
2758}
2759
James Smarte59058c2008-08-24 21:49:00 -04002760/**
James Smart3621a712009-04-06 18:47:14 -04002761 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002762 * @ndlp: pointer to a node-list data structure.
2763 *
2764 * This routine is the worker-thread handler for processing the @ndlp delayed
2765 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2766 * the last ELS command from the associated ndlp and invokes the proper ELS
2767 * function according to the delayed ELS command to retry the command.
2768 **/
dea31012005-04-17 16:05:31 -05002769void
2770lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2771{
James Smart2e0fef82007-06-17 19:56:36 -05002772 struct lpfc_vport *vport = ndlp->vport;
2773 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2774 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002775
James Smart2e0fef82007-06-17 19:56:36 -05002776 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002777 did = ndlp->nlp_DID;
2778 cmd = ndlp->nlp_last_elscmd;
2779 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002780
2781 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002782 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002783 return;
2784 }
2785
2786 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002787 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002788 /*
2789 * If a discovery event readded nlp_delayfunc after timer
2790 * firing and before processing the timer, cancel the
2791 * nlp_delayfunc.
2792 */
2793 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002794 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002795 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002796
2797 switch (cmd) {
2798 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002799 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002800 break;
2801 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002802 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002803 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002804 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002805 }
dea31012005-04-17 16:05:31 -05002806 break;
2807 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002808 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002809 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002810 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002811 }
dea31012005-04-17 16:05:31 -05002812 break;
2813 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002814 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002815 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002816 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002817 }
dea31012005-04-17 16:05:31 -05002818 break;
2819 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002820 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002821 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002822 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002823 }
dea31012005-04-17 16:05:31 -05002824 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002825 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05002826 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
2827 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05002828 break;
dea31012005-04-17 16:05:31 -05002829 }
2830 return;
2831}
2832
James Smarte59058c2008-08-24 21:49:00 -04002833/**
James Smart3621a712009-04-06 18:47:14 -04002834 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002835 * @phba: pointer to lpfc hba data structure.
2836 * @cmdiocb: pointer to lpfc command iocb data structure.
2837 * @rspiocb: pointer to lpfc response iocb data structure.
2838 *
2839 * This routine makes a retry decision on an ELS command IOCB, which has
2840 * failed. The following ELS IOCBs use this function for retrying the command
2841 * when previously issued command responsed with error status: FLOGI, PLOGI,
2842 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2843 * returned error status, it makes the decision whether a retry shall be
2844 * issued for the command, and whether a retry shall be made immediately or
2845 * delayed. In the former case, the corresponding ELS command issuing-function
2846 * is called to retry the command. In the later case, the ELS command shall
2847 * be posted to the ndlp delayed event and delayed function timer set to the
2848 * ndlp for the delayed command issusing.
2849 *
2850 * Return code
2851 * 0 - No retry of els command is made
2852 * 1 - Immediate or delayed retry of els command is made
2853 **/
dea31012005-04-17 16:05:31 -05002854static int
James Smart2e0fef82007-06-17 19:56:36 -05002855lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2856 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002857{
James Smart2e0fef82007-06-17 19:56:36 -05002858 struct lpfc_vport *vport = cmdiocb->vport;
2859 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2860 IOCB_t *irsp = &rspiocb->iocb;
2861 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2862 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002863 uint32_t *elscmd;
2864 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002865 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002866 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002867 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002868 uint32_t did;
dea31012005-04-17 16:05:31 -05002869
James Smart488d1462006-03-07 15:02:37 -05002870
dea31012005-04-17 16:05:31 -05002871 /* Note: context2 may be 0 for internal driver abort
2872 * of delays ELS command.
2873 */
2874
2875 if (pcmd && pcmd->virt) {
2876 elscmd = (uint32_t *) (pcmd->virt);
2877 cmd = *elscmd++;
2878 }
2879
James Smarte47c9092008-02-08 18:49:26 -05002880 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002881 did = ndlp->nlp_DID;
2882 else {
2883 /* We should only hit this case for retrying PLOGI */
2884 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002885 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002886 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2887 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002888 return 1;
2889 }
2890
James Smart858c9f62007-06-17 19:56:39 -05002891 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2892 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2893 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2894
dea31012005-04-17 16:05:31 -05002895 switch (irsp->ulpStatus) {
2896 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05002897 break;
James Smart1151e3e2011-02-16 12:39:35 -05002898 case IOSTAT_REMOTE_STOP:
2899 if (phba->sli_rev == LPFC_SLI_REV4) {
2900 /* This IO was aborted by the target, we don't
2901 * know the rxid and because we did not send the
2902 * ABTS we cannot generate and RRQ.
2903 */
2904 lpfc_set_rrq_active(phba, ndlp,
2905 cmdiocb->sli4_xritag, 0, 0);
2906 }
2907 break;
dea31012005-04-17 16:05:31 -05002908 case IOSTAT_LOCAL_REJECT:
2909 switch ((irsp->un.ulpWord[4] & 0xff)) {
2910 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002911 if (cmd == ELS_CMD_FLOGI) {
2912 if (PCI_DEVICE_ID_HORNET ==
2913 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05002914 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05002915 phba->pport->fc_myDID = 0;
2916 phba->alpa_map[0] = 0;
2917 phba->alpa_map[1] = 0;
2918 }
2919 }
James Smart2e0fef82007-06-17 19:56:36 -05002920 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002921 delay = 1000;
dea31012005-04-17 16:05:31 -05002922 retry = 1;
2923 break;
2924
James Smart92d7f7b2007-06-17 19:56:38 -05002925 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002926 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2927 "0124 Retry illegal cmd x%x "
2928 "retry:x%x delay:x%x\n",
2929 cmd, cmdiocb->retry, delay);
2930 retry = 1;
2931 /* All command's retry policy */
2932 maxretry = 8;
2933 if (cmdiocb->retry > 2)
2934 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002935 break;
2936
dea31012005-04-17 16:05:31 -05002937 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002938 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002939 retry = 1;
2940 if (cmdiocb->retry > 100)
2941 delay = 100;
2942 maxretry = 250;
2943 break;
2944
2945 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002946 delay = 100;
dea31012005-04-17 16:05:31 -05002947 retry = 1;
2948 break;
2949
James Smart858c9f62007-06-17 19:56:39 -05002950 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002951 case IOERR_INVALID_RPI:
2952 retry = 1;
2953 break;
2954 }
2955 break;
2956
2957 case IOSTAT_NPORT_RJT:
2958 case IOSTAT_FABRIC_RJT:
2959 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2960 retry = 1;
2961 break;
2962 }
2963 break;
2964
2965 case IOSTAT_NPORT_BSY:
2966 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002967 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002968 retry = 1;
2969 break;
2970
2971 case IOSTAT_LS_RJT:
2972 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2973 /* Added for Vendor specifc support
2974 * Just keep retrying for these Rsn / Exp codes
2975 */
2976 switch (stat.un.b.lsRjtRsnCode) {
2977 case LSRJT_UNABLE_TPC:
2978 if (stat.un.b.lsRjtRsnCodeExp ==
2979 LSEXP_CMD_IN_PROGRESS) {
2980 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002981 delay = 1000;
dea31012005-04-17 16:05:31 -05002982 maxretry = 48;
2983 }
2984 retry = 1;
2985 break;
2986 }
James Smartffc95492010-06-07 15:23:17 -04002987 if (stat.un.b.lsRjtRsnCodeExp ==
2988 LSEXP_CANT_GIVE_DATA) {
2989 if (cmd == ELS_CMD_PLOGI) {
2990 delay = 1000;
2991 maxretry = 48;
2992 }
2993 retry = 1;
2994 break;
2995 }
dea31012005-04-17 16:05:31 -05002996 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002997 delay = 1000;
dea31012005-04-17 16:05:31 -05002998 maxretry = lpfc_max_els_tries + 1;
2999 retry = 1;
3000 break;
3001 }
James Smart92d7f7b2007-06-17 19:56:38 -05003002 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3003 (cmd == ELS_CMD_FDISC) &&
3004 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003005 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3006 "0125 FDISC Failed (x%x). "
3007 "Fabric out of resources\n",
3008 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003009 lpfc_vport_set_state(vport,
3010 FC_VPORT_NO_FABRIC_RSCS);
3011 }
dea31012005-04-17 16:05:31 -05003012 break;
3013
3014 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003015 if ((cmd == ELS_CMD_PLOGI) ||
3016 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003017 delay = 1000;
dea31012005-04-17 16:05:31 -05003018 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003019 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003020 /* FDISC retry policy */
3021 maxretry = 48;
3022 if (cmdiocb->retry >= 32)
3023 delay = 1000;
dea31012005-04-17 16:05:31 -05003024 }
3025 retry = 1;
3026 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003027
3028 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003029 /* There are some cases where switches return this
3030 * error when they are not ready and should be returning
3031 * Logical Busy. We should delay every time.
3032 */
3033 if (cmd == ELS_CMD_FDISC &&
3034 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3035 maxretry = 3;
3036 delay = 1000;
3037 retry = 1;
3038 break;
3039 }
James Smart92d7f7b2007-06-17 19:56:38 -05003040 case LSRJT_PROTOCOL_ERR:
3041 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3042 (cmd == ELS_CMD_FDISC) &&
3043 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3044 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3045 ) {
James Smarte8b62012007-08-02 11:10:09 -04003046 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003047 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003048 "Fabric Detected Bad WWN\n",
3049 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003050 lpfc_vport_set_state(vport,
3051 FC_VPORT_FABRIC_REJ_WWN);
3052 }
3053 break;
dea31012005-04-17 16:05:31 -05003054 }
3055 break;
3056
3057 case IOSTAT_INTERMED_RSP:
3058 case IOSTAT_BA_RJT:
3059 break;
3060
3061 default:
3062 break;
3063 }
3064
James Smart488d1462006-03-07 15:02:37 -05003065 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003066 retry = 1;
dea31012005-04-17 16:05:31 -05003067
James Smart695a8142010-01-26 23:08:03 -05003068 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart76a95d72010-11-20 23:11:48 -05003069 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003070 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003071 /* FLOGI retry policy */
3072 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04003073 /* retry forever */
3074 maxretry = 0;
3075 if (cmdiocb->retry >= 100)
3076 delay = 5000;
3077 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003078 delay = 1000;
3079 }
3080
James Smart6669f9b2009-10-02 15:16:45 -04003081 cmdiocb->retry++;
3082 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003083 phba->fc_stat.elsRetryExceeded++;
3084 retry = 0;
3085 }
3086
James Smarted957682007-06-17 19:56:37 -05003087 if ((vport->load_flag & FC_UNLOADING) != 0)
3088 retry = 0;
3089
dea31012005-04-17 16:05:31 -05003090 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003091 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3092 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3093 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3094 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3095 "2849 Stop retry ELS command "
3096 "x%x to remote NPORT x%x, "
3097 "Data: x%x x%x\n", cmd, did,
3098 cmdiocb->retry, delay);
3099 return 0;
3100 }
3101 }
dea31012005-04-17 16:05:31 -05003102
3103 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003104 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3105 "0107 Retry ELS command x%x to remote "
3106 "NPORT x%x Data: x%x x%x\n",
3107 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003108
James Smart858c9f62007-06-17 19:56:39 -05003109 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3110 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3111 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
3112 /* Don't reset timer for no resources */
3113
dea31012005-04-17 16:05:31 -05003114 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003115 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003116 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003117 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003118 }
3119
3120 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003121 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003122 phba->fc_stat.elsDelayRetry++;
3123 ndlp->nlp_retry = cmdiocb->retry;
3124
James Smart92d7f7b2007-06-17 19:56:38 -05003125 /* delay is specified in milliseconds */
3126 mod_timer(&ndlp->nlp_delayfunc,
3127 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003128 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003129 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003130 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003131
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003132 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003133 if (cmd == ELS_CMD_PRLI)
3134 lpfc_nlp_set_state(vport, ndlp,
3135 NLP_STE_REG_LOGIN_ISSUE);
3136 else
3137 lpfc_nlp_set_state(vport, ndlp,
3138 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003139 ndlp->nlp_last_elscmd = cmd;
3140
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003141 return 1;
dea31012005-04-17 16:05:31 -05003142 }
3143 switch (cmd) {
3144 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003145 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003146 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003147 case ELS_CMD_FDISC:
3148 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3149 return 1;
dea31012005-04-17 16:05:31 -05003150 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003151 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003152 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003153 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003154 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003155 }
James Smart2e0fef82007-06-17 19:56:36 -05003156 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003157 return 1;
dea31012005-04-17 16:05:31 -05003158 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003159 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003160 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3161 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003162 return 1;
dea31012005-04-17 16:05:31 -05003163 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003164 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003165 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3166 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003167 return 1;
dea31012005-04-17 16:05:31 -05003168 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003169 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003170 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3171 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003172 return 1;
dea31012005-04-17 16:05:31 -05003173 }
3174 }
dea31012005-04-17 16:05:31 -05003175 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003176 if (logerr) {
3177 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3178 "0137 No retry ELS command x%x to remote "
3179 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3180 cmd, did, irsp->ulpStatus,
3181 irsp->un.ulpWord[4]);
3182 }
3183 else {
3184 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003185 "0108 No retry ELS command x%x to remote "
3186 "NPORT x%x Retried:%d Error:x%x/%x\n",
3187 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3188 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003189 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003190 return 0;
dea31012005-04-17 16:05:31 -05003191}
3192
James Smarte59058c2008-08-24 21:49:00 -04003193/**
James Smart3621a712009-04-06 18:47:14 -04003194 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003195 * @phba: pointer to lpfc hba data structure.
3196 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3197 *
3198 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3199 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3200 * checks to see whether there is a lpfc DMA buffer associated with the
3201 * response of the command IOCB. If so, it will be released before releasing
3202 * the lpfc DMA buffer associated with the IOCB itself.
3203 *
3204 * Return code
3205 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3206 **/
James Smart09372822008-01-11 01:52:54 -05003207static int
James Smart87af33f2007-10-27 13:37:43 -04003208lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3209{
3210 struct lpfc_dmabuf *buf_ptr;
3211
James Smarte59058c2008-08-24 21:49:00 -04003212 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003213 if (!list_empty(&buf_ptr1->list)) {
3214 list_remove_head(&buf_ptr1->list, buf_ptr,
3215 struct lpfc_dmabuf,
3216 list);
3217 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3218 kfree(buf_ptr);
3219 }
3220 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3221 kfree(buf_ptr1);
3222 return 0;
3223}
3224
James Smarte59058c2008-08-24 21:49:00 -04003225/**
James Smart3621a712009-04-06 18:47:14 -04003226 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003227 * @phba: pointer to lpfc hba data structure.
3228 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3229 *
3230 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3231 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3232 * pool.
3233 *
3234 * Return code
3235 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3236 **/
James Smart09372822008-01-11 01:52:54 -05003237static int
James Smart87af33f2007-10-27 13:37:43 -04003238lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3239{
3240 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3241 kfree(buf_ptr);
3242 return 0;
3243}
3244
James Smarte59058c2008-08-24 21:49:00 -04003245/**
James Smart3621a712009-04-06 18:47:14 -04003246 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003247 * @phba: pointer to lpfc hba data structure.
3248 * @elsiocb: pointer to lpfc els command iocb data structure.
3249 *
3250 * This routine frees a command IOCB and its associated resources. The
3251 * command IOCB data structure contains the reference to various associated
3252 * resources, these fields must be set to NULL if the associated reference
3253 * not present:
3254 * context1 - reference to ndlp
3255 * context2 - reference to cmd
3256 * context2->next - reference to rsp
3257 * context3 - reference to bpl
3258 *
3259 * It first properly decrements the reference count held on ndlp for the
3260 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3261 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3262 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3263 * adds the DMA buffer the @phba data structure for the delayed release.
3264 * If reference to the Buffer Pointer List (BPL) is present, the
3265 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3266 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3267 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3268 *
3269 * Return code
3270 * 0 - Success (currently, always return 0)
3271 **/
James Smart87af33f2007-10-27 13:37:43 -04003272int
James Smart329f9bc2007-04-25 09:53:01 -04003273lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003274{
3275 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003276 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003277
James Smarta8adb832007-10-27 13:37:53 -04003278 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3279 if (ndlp) {
3280 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3281 lpfc_nlp_put(ndlp);
3282
3283 /* If the ndlp is not being used by another discovery
3284 * thread, free it.
3285 */
3286 if (!lpfc_nlp_not_used(ndlp)) {
3287 /* If ndlp is being used by another discovery
3288 * thread, just clear NLP_DEFER_RM
3289 */
3290 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3291 }
3292 }
3293 else
3294 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003295 elsiocb->context1 = NULL;
3296 }
dea31012005-04-17 16:05:31 -05003297 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3298 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003299 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3300 /* Firmware could still be in progress of DMAing
3301 * payload, so don't free data buffer till after
3302 * a hbeat.
3303 */
3304 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3305 buf_ptr = elsiocb->context2;
3306 elsiocb->context2 = NULL;
3307 if (buf_ptr) {
3308 buf_ptr1 = NULL;
3309 spin_lock_irq(&phba->hbalock);
3310 if (!list_empty(&buf_ptr->list)) {
3311 list_remove_head(&buf_ptr->list,
3312 buf_ptr1, struct lpfc_dmabuf,
3313 list);
3314 INIT_LIST_HEAD(&buf_ptr1->list);
3315 list_add_tail(&buf_ptr1->list,
3316 &phba->elsbuf);
3317 phba->elsbuf_cnt++;
3318 }
3319 INIT_LIST_HEAD(&buf_ptr->list);
3320 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3321 phba->elsbuf_cnt++;
3322 spin_unlock_irq(&phba->hbalock);
3323 }
3324 } else {
3325 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3326 lpfc_els_free_data(phba, buf_ptr1);
3327 }
dea31012005-04-17 16:05:31 -05003328 }
3329
3330 if (elsiocb->context3) {
3331 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003332 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003333 }
James Bottomley604a3e32005-10-29 10:28:33 -05003334 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003335 return 0;
3336}
3337
James Smarte59058c2008-08-24 21:49:00 -04003338/**
James Smart3621a712009-04-06 18:47:14 -04003339 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003340 * @phba: pointer to lpfc hba data structure.
3341 * @cmdiocb: pointer to lpfc command iocb data structure.
3342 * @rspiocb: pointer to lpfc response iocb data structure.
3343 *
3344 * This routine is the completion callback function to the Logout (LOGO)
3345 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3346 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3347 * release the ndlp if it has the last reference remaining (reference count
3348 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3349 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3350 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3351 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3352 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3353 * IOCB data structure.
3354 **/
dea31012005-04-17 16:05:31 -05003355static void
James Smart2e0fef82007-06-17 19:56:36 -05003356lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3357 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003358{
James Smart2e0fef82007-06-17 19:56:36 -05003359 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3360 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003361 IOCB_t *irsp;
3362
3363 irsp = &rspiocb->iocb;
3364 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3365 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3366 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003367 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003368 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3369 "0109 ACC to LOGO completes to NPort x%x "
3370 "Data: x%x x%x x%x\n",
3371 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3372 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003373
3374 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3375 /* NPort Recovery mode or node is just allocated */
3376 if (!lpfc_nlp_not_used(ndlp)) {
3377 /* If the ndlp is being used by another discovery
3378 * thread, just unregister the RPI.
3379 */
3380 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003381 } else {
3382 /* Indicate the node has already released, should
3383 * not reference to it from within lpfc_els_free_iocb.
3384 */
3385 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003386 }
dea31012005-04-17 16:05:31 -05003387 }
3388 lpfc_els_free_iocb(phba, cmdiocb);
3389 return;
3390}
3391
James Smarte59058c2008-08-24 21:49:00 -04003392/**
James Smart3621a712009-04-06 18:47:14 -04003393 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003394 * @phba: pointer to lpfc hba data structure.
3395 * @pmb: pointer to the driver internal queue element for mailbox command.
3396 *
3397 * This routine is the completion callback function for unregister default
3398 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3399 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3400 * decrements the ndlp reference count held for this completion callback
3401 * function. After that, it invokes the lpfc_nlp_not_used() to check
3402 * whether there is only one reference left on the ndlp. If so, it will
3403 * perform one more decrement and trigger the release of the ndlp.
3404 **/
James Smart858c9f62007-06-17 19:56:39 -05003405void
3406lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3407{
3408 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3409 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3410
3411 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003412 pmb->context2 = NULL;
3413
James Smart858c9f62007-06-17 19:56:39 -05003414 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3415 kfree(mp);
3416 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003417 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003418 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003419 /* This is the end of the default RPI cleanup logic for this
3420 * ndlp. If no other discovery threads are using this ndlp.
3421 * we should free all resources associated with it.
3422 */
3423 lpfc_nlp_not_used(ndlp);
3424 }
James Smart3772a992009-05-22 14:50:54 -04003425
James Smart858c9f62007-06-17 19:56:39 -05003426 return;
3427}
3428
James Smarte59058c2008-08-24 21:49:00 -04003429/**
James Smart3621a712009-04-06 18:47:14 -04003430 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003431 * @phba: pointer to lpfc hba data structure.
3432 * @cmdiocb: pointer to lpfc command iocb data structure.
3433 * @rspiocb: pointer to lpfc response iocb data structure.
3434 *
3435 * This routine is the completion callback function for ELS Response IOCB
3436 * command. In normal case, this callback function just properly sets the
3437 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3438 * field in the command IOCB is not NULL, the referred mailbox command will
3439 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3440 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3441 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3442 * routine shall be invoked trying to release the ndlp if no other threads
3443 * are currently referring it.
3444 **/
dea31012005-04-17 16:05:31 -05003445static void
James Smart858c9f62007-06-17 19:56:39 -05003446lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003447 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003448{
James Smart2e0fef82007-06-17 19:56:36 -05003449 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3450 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3451 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003452 IOCB_t *irsp;
3453 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003454 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003455 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003456 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003457
James Smart33ccf8d2006-08-17 11:57:58 -04003458 irsp = &rspiocb->iocb;
3459
dea31012005-04-17 16:05:31 -05003460 if (cmdiocb->context_un.mbox)
3461 mbox = cmdiocb->context_un.mbox;
3462
James Smartfa4066b2008-01-11 01:53:27 -05003463 /* First determine if this is a LS_RJT cmpl. Note, this callback
3464 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3465 */
James Smart87af33f2007-10-27 13:37:43 -04003466 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003467 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3468 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003469 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003470 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003471 */
3472 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3473 ls_rjt = 1;
3474 }
3475
dea31012005-04-17 16:05:31 -05003476 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003477 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003478 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003479 mp = (struct lpfc_dmabuf *) mbox->context1;
3480 if (mp) {
3481 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3482 kfree(mp);
3483 }
James Smart329f9bc2007-04-25 09:53:01 -04003484 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003485 }
James Smart58da1ff2008-04-07 10:15:56 -04003486 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3487 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003488 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003489 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003490 /* Indicate the node has already released,
3491 * should not reference to it from within
3492 * the routine lpfc_els_free_iocb.
3493 */
3494 cmdiocb->context1 = NULL;
3495 }
dea31012005-04-17 16:05:31 -05003496 goto out;
3497 }
3498
James Smart858c9f62007-06-17 19:56:39 -05003499 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003500 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003501 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003502 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003503 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003504 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3505 "0110 ELS response tag x%x completes "
3506 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3507 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3508 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3509 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3510 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003511 if (mbox) {
3512 if ((rspiocb->iocb.ulpStatus == 0)
3513 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003514 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003515 /* Increment reference count to ndlp to hold the
3516 * reference to ndlp for the callback function.
3517 */
James Smart329f9bc2007-04-25 09:53:01 -04003518 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003519 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003520 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3521 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3522 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3523 }
3524 else {
3525 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3526 ndlp->nlp_prev_state = ndlp->nlp_state;
3527 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003528 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003529 }
James Smart0b727fe2007-10-27 13:37:25 -04003530 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003531 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003532 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003533 else
3534 /* Decrement the ndlp reference count we
3535 * set for this failed mailbox command.
3536 */
3537 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003538
3539 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3540 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3541 "0138 ELS rsp: Cannot issue reg_login for x%x "
3542 "Data: x%x x%x x%x\n",
3543 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3544 ndlp->nlp_rpi);
3545
James Smartfa4066b2008-01-11 01:53:27 -05003546 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003547 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003548 /* Indicate node has already been released,
3549 * should not reference to it from within
3550 * the routine lpfc_els_free_iocb.
3551 */
3552 cmdiocb->context1 = NULL;
3553 }
dea31012005-04-17 16:05:31 -05003554 } else {
James Smart858c9f62007-06-17 19:56:39 -05003555 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3556 if (!lpfc_error_lost_link(irsp) &&
3557 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003558 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003559 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003560 /* Indicate node has already been
3561 * released, should not reference
3562 * to it from within the routine
3563 * lpfc_els_free_iocb.
3564 */
3565 cmdiocb->context1 = NULL;
3566 }
dea31012005-04-17 16:05:31 -05003567 }
3568 }
James Smart14691152006-12-02 13:34:28 -05003569 mp = (struct lpfc_dmabuf *) mbox->context1;
3570 if (mp) {
3571 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3572 kfree(mp);
3573 }
3574 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003575 }
3576out:
James Smart58da1ff2008-04-07 10:15:56 -04003577 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003578 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003579 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003580 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003581
3582 /* If the node is not being used by another discovery thread,
3583 * and we are sending a reject, we are done with it.
3584 * Release driver reference count here and free associated
3585 * resources.
3586 */
3587 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003588 if (lpfc_nlp_not_used(ndlp))
3589 /* Indicate node has already been released,
3590 * should not reference to it from within
3591 * the routine lpfc_els_free_iocb.
3592 */
3593 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003594 }
James Smart87af33f2007-10-27 13:37:43 -04003595
dea31012005-04-17 16:05:31 -05003596 lpfc_els_free_iocb(phba, cmdiocb);
3597 return;
3598}
3599
James Smarte59058c2008-08-24 21:49:00 -04003600/**
James Smart3621a712009-04-06 18:47:14 -04003601 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003602 * @vport: pointer to a host virtual N_Port data structure.
3603 * @flag: the els command code to be accepted.
3604 * @oldiocb: pointer to the original lpfc command iocb data structure.
3605 * @ndlp: pointer to a node-list data structure.
3606 * @mbox: pointer to the driver internal queue element for mailbox command.
3607 *
3608 * This routine prepares and issues an Accept (ACC) response IOCB
3609 * command. It uses the @flag to properly set up the IOCB field for the
3610 * specific ACC response command to be issued and invokes the
3611 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3612 * @mbox pointer is passed in, it will be put into the context_un.mbox
3613 * field of the IOCB for the completion callback function to issue the
3614 * mailbox command to the HBA later when callback is invoked.
3615 *
3616 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3617 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3618 * will be stored into the context1 field of the IOCB for the completion
3619 * callback function to the corresponding response ELS IOCB command.
3620 *
3621 * Return code
3622 * 0 - Successfully issued acc response
3623 * 1 - Failed to issue acc response
3624 **/
dea31012005-04-17 16:05:31 -05003625int
James Smart2e0fef82007-06-17 19:56:36 -05003626lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3627 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003628 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003629{
James Smart2e0fef82007-06-17 19:56:36 -05003630 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3631 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003632 IOCB_t *icmd;
3633 IOCB_t *oldcmd;
3634 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003635 struct lpfc_sli *psli;
3636 uint8_t *pcmd;
3637 uint16_t cmdsize;
3638 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003639 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003640
3641 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003642 oldcmd = &oldiocb->iocb;
3643
3644 switch (flag) {
3645 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003646 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003647 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3648 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003649 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003650 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003651 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003652 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003653 return 1;
dea31012005-04-17 16:05:31 -05003654 }
James Smart2e0fef82007-06-17 19:56:36 -05003655
dea31012005-04-17 16:05:31 -05003656 icmd = &elsiocb->iocb;
3657 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3658 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3659 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003660 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003661
3662 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3663 "Issue ACC: did:x%x flg:x%x",
3664 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003665 break;
3666 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003667 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003668 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3669 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003670 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003671 return 1;
James Smart488d1462006-03-07 15:02:37 -05003672
dea31012005-04-17 16:05:31 -05003673 icmd = &elsiocb->iocb;
3674 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3675 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3676
3677 if (mbox)
3678 elsiocb->context_un.mbox = mbox;
3679
3680 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003681 pcmd += sizeof(uint32_t);
3682 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003683
3684 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3685 "Issue ACC PLOGI: did:x%x flg:x%x",
3686 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003687 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003688 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003689 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003690 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003691 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3692 if (!elsiocb)
3693 return 1;
3694
3695 icmd = &elsiocb->iocb;
3696 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3697 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3698
3699 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003700 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003701 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3702 els_pkt_ptr = (ELS_PKT *) pcmd;
3703 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003704
3705 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3706 "Issue ACC PRLO: did:x%x flg:x%x",
3707 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003708 break;
dea31012005-04-17 16:05:31 -05003709 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003710 return 1;
dea31012005-04-17 16:05:31 -05003711 }
dea31012005-04-17 16:05:31 -05003712 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003713 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3714 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3715 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3716 elsiocb->iotag, elsiocb->iocb.ulpContext,
3717 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3718 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003719 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003720 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003721 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003722 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003723 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3724 } else {
James Smart858c9f62007-06-17 19:56:39 -05003725 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003726 }
3727
3728 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003729 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003730 if (rc == IOCB_ERROR) {
3731 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003732 return 1;
dea31012005-04-17 16:05:31 -05003733 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003734 return 0;
dea31012005-04-17 16:05:31 -05003735}
3736
James Smarte59058c2008-08-24 21:49:00 -04003737/**
James Smart3621a712009-04-06 18:47:14 -04003738 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003739 * @vport: pointer to a virtual N_Port data structure.
3740 * @rejectError:
3741 * @oldiocb: pointer to the original lpfc command iocb data structure.
3742 * @ndlp: pointer to a node-list data structure.
3743 * @mbox: pointer to the driver internal queue element for mailbox command.
3744 *
3745 * This routine prepares and issue an Reject (RJT) response IOCB
3746 * command. If a @mbox pointer is passed in, it will be put into the
3747 * context_un.mbox field of the IOCB for the completion callback function
3748 * to issue to the HBA later.
3749 *
3750 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3751 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3752 * will be stored into the context1 field of the IOCB for the completion
3753 * callback function to the reject response ELS IOCB command.
3754 *
3755 * Return code
3756 * 0 - Successfully issued reject response
3757 * 1 - Failed to issue reject response
3758 **/
dea31012005-04-17 16:05:31 -05003759int
James Smart2e0fef82007-06-17 19:56:36 -05003760lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003761 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3762 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003763{
James Smart2e0fef82007-06-17 19:56:36 -05003764 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003765 IOCB_t *icmd;
3766 IOCB_t *oldcmd;
3767 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003768 struct lpfc_sli *psli;
3769 uint8_t *pcmd;
3770 uint16_t cmdsize;
3771 int rc;
3772
3773 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003774 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003775 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3776 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003777 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003778 return 1;
dea31012005-04-17 16:05:31 -05003779
3780 icmd = &elsiocb->iocb;
3781 oldcmd = &oldiocb->iocb;
3782 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3783 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3784
3785 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003786 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003787 *((uint32_t *) (pcmd)) = rejectError;
3788
James Smart51ef4c22007-08-02 11:10:31 -04003789 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003790 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003791
dea31012005-04-17 16:05:31 -05003792 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003793 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3794 "0129 Xmit ELS RJT x%x response tag x%x "
3795 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3796 "rpi x%x\n",
3797 rejectError, elsiocb->iotag,
3798 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3799 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003800 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3801 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3802 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3803
dea31012005-04-17 16:05:31 -05003804 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003805 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003806 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003807
dea31012005-04-17 16:05:31 -05003808 if (rc == IOCB_ERROR) {
3809 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003810 return 1;
dea31012005-04-17 16:05:31 -05003811 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003812 return 0;
dea31012005-04-17 16:05:31 -05003813}
3814
James Smarte59058c2008-08-24 21:49:00 -04003815/**
James Smart3621a712009-04-06 18:47:14 -04003816 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003817 * @vport: pointer to a virtual N_Port data structure.
3818 * @oldiocb: pointer to the original lpfc command iocb data structure.
3819 * @ndlp: pointer to a node-list data structure.
3820 *
3821 * This routine prepares and issues an Accept (ACC) response to Address
3822 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3823 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3824 *
3825 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3826 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3827 * will be stored into the context1 field of the IOCB for the completion
3828 * callback function to the ADISC Accept response ELS IOCB command.
3829 *
3830 * Return code
3831 * 0 - Successfully issued acc adisc response
3832 * 1 - Failed to issue adisc acc response
3833 **/
dea31012005-04-17 16:05:31 -05003834int
James Smart2e0fef82007-06-17 19:56:36 -05003835lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3836 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003837{
James Smart2e0fef82007-06-17 19:56:36 -05003838 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003839 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003840 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003841 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003842 uint8_t *pcmd;
3843 uint16_t cmdsize;
3844 int rc;
3845
James Smart92d7f7b2007-06-17 19:56:38 -05003846 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003847 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3848 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003849 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003850 return 1;
dea31012005-04-17 16:05:31 -05003851
dea31012005-04-17 16:05:31 -05003852 icmd = &elsiocb->iocb;
3853 oldcmd = &oldiocb->iocb;
3854 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003855
3856 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003857 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3858 "0130 Xmit ADISC ACC response iotag x%x xri: "
3859 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3860 elsiocb->iotag, elsiocb->iocb.ulpContext,
3861 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3862 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003863 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3864
3865 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003866 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003867
3868 ap = (ADISC *) (pcmd);
3869 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003870 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3871 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003872 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003873
James Smart858c9f62007-06-17 19:56:39 -05003874 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3875 "Issue ACC ADISC: did:x%x flg:x%x",
3876 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3877
dea31012005-04-17 16:05:31 -05003878 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003879 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003880 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003881 if (rc == IOCB_ERROR) {
3882 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003883 return 1;
dea31012005-04-17 16:05:31 -05003884 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003885 return 0;
dea31012005-04-17 16:05:31 -05003886}
3887
James Smarte59058c2008-08-24 21:49:00 -04003888/**
James Smart3621a712009-04-06 18:47:14 -04003889 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003890 * @vport: pointer to a virtual N_Port data structure.
3891 * @oldiocb: pointer to the original lpfc command iocb data structure.
3892 * @ndlp: pointer to a node-list data structure.
3893 *
3894 * This routine prepares and issues an Accept (ACC) response to Process
3895 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3896 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3897 *
3898 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3899 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3900 * will be stored into the context1 field of the IOCB for the completion
3901 * callback function to the PRLI Accept response ELS IOCB command.
3902 *
3903 * Return code
3904 * 0 - Successfully issued acc prli response
3905 * 1 - Failed to issue acc prli response
3906 **/
dea31012005-04-17 16:05:31 -05003907int
James Smart2e0fef82007-06-17 19:56:36 -05003908lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003909 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003910{
James Smart2e0fef82007-06-17 19:56:36 -05003911 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003912 PRLI *npr;
3913 lpfc_vpd_t *vpd;
3914 IOCB_t *icmd;
3915 IOCB_t *oldcmd;
3916 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003917 struct lpfc_sli *psli;
3918 uint8_t *pcmd;
3919 uint16_t cmdsize;
3920 int rc;
3921
3922 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003923
James Smart92d7f7b2007-06-17 19:56:38 -05003924 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003925 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003926 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003927 if (!elsiocb)
3928 return 1;
dea31012005-04-17 16:05:31 -05003929
dea31012005-04-17 16:05:31 -05003930 icmd = &elsiocb->iocb;
3931 oldcmd = &oldiocb->iocb;
3932 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003933 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003934 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3935 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3936 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3937 elsiocb->iotag, elsiocb->iocb.ulpContext,
3938 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3939 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003940 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3941
3942 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003943 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003944
3945 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003946 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003947
3948 npr = (PRLI *) pcmd;
3949 vpd = &phba->vpd;
3950 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003951 * If the remote port is a target and our firmware version is 3.20 or
3952 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003953 */
James Smart0d2b6b82008-06-14 22:52:47 -04003954 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3955 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003956 npr->ConfmComplAllowed = 1;
3957 npr->Retry = 1;
3958 npr->TaskRetryIdReq = 1;
3959 }
3960
3961 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3962 npr->estabImagePair = 1;
3963 npr->readXferRdyDis = 1;
3964 npr->ConfmComplAllowed = 1;
3965
3966 npr->prliType = PRLI_FCP_TYPE;
3967 npr->initiatorFunc = 1;
3968
James Smart858c9f62007-06-17 19:56:39 -05003969 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3970 "Issue ACC PRLI: did:x%x flg:x%x",
3971 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3972
dea31012005-04-17 16:05:31 -05003973 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003974 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003975
James Smart3772a992009-05-22 14:50:54 -04003976 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003977 if (rc == IOCB_ERROR) {
3978 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003979 return 1;
dea31012005-04-17 16:05:31 -05003980 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003981 return 0;
dea31012005-04-17 16:05:31 -05003982}
3983
James Smarte59058c2008-08-24 21:49:00 -04003984/**
James Smart3621a712009-04-06 18:47:14 -04003985 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003986 * @vport: pointer to a virtual N_Port data structure.
3987 * @format: rnid command format.
3988 * @oldiocb: pointer to the original lpfc command iocb data structure.
3989 * @ndlp: pointer to a node-list data structure.
3990 *
3991 * This routine issues a Request Node Identification Data (RNID) Accept
3992 * (ACC) response. It constructs the RNID ACC response command according to
3993 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3994 * issue the response. Note that this command does not need to hold the ndlp
3995 * reference count for the callback. So, the ndlp reference count taken by
3996 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3997 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3998 * there is no ndlp reference available.
3999 *
4000 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4001 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4002 * will be stored into the context1 field of the IOCB for the completion
4003 * callback function. However, for the RNID Accept Response ELS command,
4004 * this is undone later by this routine after the IOCB is allocated.
4005 *
4006 * Return code
4007 * 0 - Successfully issued acc rnid response
4008 * 1 - Failed to issue acc rnid response
4009 **/
dea31012005-04-17 16:05:31 -05004010static int
James Smart2e0fef82007-06-17 19:56:36 -05004011lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004012 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004013{
James Smart2e0fef82007-06-17 19:56:36 -05004014 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004015 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004016 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004017 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004018 struct lpfc_sli *psli;
4019 uint8_t *pcmd;
4020 uint16_t cmdsize;
4021 int rc;
4022
4023 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004024 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4025 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004026 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004027 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004028
James Smart2e0fef82007-06-17 19:56:36 -05004029 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4030 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004031 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004032 return 1;
dea31012005-04-17 16:05:31 -05004033
dea31012005-04-17 16:05:31 -05004034 icmd = &elsiocb->iocb;
4035 oldcmd = &oldiocb->iocb;
4036 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04004037 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004038 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4039 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4040 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004041 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004042 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004043 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004044
James Smart92d7f7b2007-06-17 19:56:38 -05004045 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004046 rn = (RNID *) (pcmd);
4047 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004048 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4049 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4050 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004051 switch (format) {
4052 case 0:
4053 rn->SpecificLen = 0;
4054 break;
4055 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004056 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004057 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004058 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004059 rn->un.topologyDisc.unitType = RNID_HBA;
4060 rn->un.topologyDisc.physPort = 0;
4061 rn->un.topologyDisc.attachedNodes = 0;
4062 break;
4063 default:
4064 rn->CommonLen = 0;
4065 rn->SpecificLen = 0;
4066 break;
4067 }
4068
James Smart858c9f62007-06-17 19:56:39 -05004069 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4070 "Issue ACC RNID: did:x%x flg:x%x",
4071 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4072
dea31012005-04-17 16:05:31 -05004073 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004074 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04004075 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004076 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
4077 * it could be freed */
4078
James Smart3772a992009-05-22 14:50:54 -04004079 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004080 if (rc == IOCB_ERROR) {
4081 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004082 return 1;
dea31012005-04-17 16:05:31 -05004083 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004084 return 0;
dea31012005-04-17 16:05:31 -05004085}
4086
James Smarte59058c2008-08-24 21:49:00 -04004087/**
James Smart19ca7602010-11-20 23:11:55 -05004088 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4089 * @vport: pointer to a virtual N_Port data structure.
4090 * @iocb: pointer to the lpfc command iocb data structure.
4091 * @ndlp: pointer to a node-list data structure.
4092 *
4093 * Return
4094 **/
4095static void
4096lpfc_els_clear_rrq(struct lpfc_vport *vport,
4097 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4098{
4099 struct lpfc_hba *phba = vport->phba;
4100 uint8_t *pcmd;
4101 struct RRQ *rrq;
4102 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004103 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004104 struct lpfc_node_rrq *prrq;
4105
4106
4107 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4108 pcmd += sizeof(uint32_t);
4109 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004110 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b062011-04-16 11:03:17 -04004111 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004112
4113 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4114 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4115 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004116 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b062011-04-16 11:03:17 -04004117 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004118 rxid,
4119 iocb->iotag, iocb->iocb.ulpContext);
4120
4121 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4122 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4123 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004124 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b062011-04-16 11:03:17 -04004125 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004126 else
4127 xri = rxid;
4128 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004129 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004130 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004131 return;
4132}
4133
4134/**
James Smart12265f62010-10-22 11:05:53 -04004135 * lpfc_els_rsp_echo_acc - Issue echo acc response
4136 * @vport: pointer to a virtual N_Port data structure.
4137 * @data: pointer to echo data to return in the accept.
4138 * @oldiocb: pointer to the original lpfc command iocb data structure.
4139 * @ndlp: pointer to a node-list data structure.
4140 *
4141 * Return code
4142 * 0 - Successfully issued acc echo response
4143 * 1 - Failed to issue acc echo response
4144 **/
4145static int
4146lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4147 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4148{
4149 struct lpfc_hba *phba = vport->phba;
4150 struct lpfc_iocbq *elsiocb;
4151 struct lpfc_sli *psli;
4152 uint8_t *pcmd;
4153 uint16_t cmdsize;
4154 int rc;
4155
4156 psli = &phba->sli;
4157 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4158
4159 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4160 ndlp->nlp_DID, ELS_CMD_ACC);
4161 if (!elsiocb)
4162 return 1;
4163
4164 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */
4165 /* Xmit ECHO ACC response tag <ulpIoTag> */
4166 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4167 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4168 elsiocb->iotag, elsiocb->iocb.ulpContext);
4169 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4170 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4171 pcmd += sizeof(uint32_t);
4172 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4173
4174 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4175 "Issue ACC ECHO: did:x%x flg:x%x",
4176 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4177
4178 phba->fc_stat.elsXmitACC++;
4179 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4180 lpfc_nlp_put(ndlp);
4181 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
4182 * it could be freed */
4183
4184 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4185 if (rc == IOCB_ERROR) {
4186 lpfc_els_free_iocb(phba, elsiocb);
4187 return 1;
4188 }
4189 return 0;
4190}
4191
4192/**
James Smart3621a712009-04-06 18:47:14 -04004193 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004194 * @vport: pointer to a host virtual N_Port data structure.
4195 *
4196 * This routine issues Address Discover (ADISC) ELS commands to those
4197 * N_Ports which are in node port recovery state and ADISC has not been issued
4198 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4199 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4200 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4201 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4202 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4203 * IOCBs quit for later pick up. On the other hand, after walking through
4204 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4205 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4206 * no more ADISC need to be sent.
4207 *
4208 * Return code
4209 * The number of N_Ports with adisc issued.
4210 **/
dea31012005-04-17 16:05:31 -05004211int
James Smart2e0fef82007-06-17 19:56:36 -05004212lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004213{
James Smart2e0fef82007-06-17 19:56:36 -05004214 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004215 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004216 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004217
James Smart685f0bf2007-04-25 09:53:08 -04004218 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004219 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004220 if (!NLP_CHK_NODE_ACT(ndlp))
4221 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004222 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4223 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4224 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004225 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004226 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004227 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004228 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004229 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4230 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004231 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004232 vport->num_disc_nodes++;
4233 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004234 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004235 spin_lock_irq(shost->host_lock);
4236 vport->fc_flag |= FC_NLP_MORE;
4237 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004238 break;
dea31012005-04-17 16:05:31 -05004239 }
4240 }
4241 }
4242 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004243 spin_lock_irq(shost->host_lock);
4244 vport->fc_flag &= ~FC_NLP_MORE;
4245 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004246 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004247 return sentadisc;
dea31012005-04-17 16:05:31 -05004248}
4249
James Smarte59058c2008-08-24 21:49:00 -04004250/**
James Smart3621a712009-04-06 18:47:14 -04004251 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004252 * @vport: pointer to a host virtual N_Port data structure.
4253 *
4254 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4255 * which are in node port recovery state, with a @vport. Each time an ELS
4256 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4257 * the per @vport number of discover count (num_disc_nodes) shall be
4258 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4259 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4260 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4261 * later pick up. On the other hand, after walking through all the ndlps with
4262 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4263 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4264 * PLOGI need to be sent.
4265 *
4266 * Return code
4267 * The number of N_Ports with plogi issued.
4268 **/
dea31012005-04-17 16:05:31 -05004269int
James Smart2e0fef82007-06-17 19:56:36 -05004270lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004271{
James Smart2e0fef82007-06-17 19:56:36 -05004272 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004273 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004274 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004275
James Smart2e0fef82007-06-17 19:56:36 -05004276 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4277 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004278 if (!NLP_CHK_NODE_ACT(ndlp))
4279 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004280 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4281 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4282 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4283 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4284 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004285 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4286 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004287 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004288 vport->num_disc_nodes++;
4289 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004290 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004291 spin_lock_irq(shost->host_lock);
4292 vport->fc_flag |= FC_NLP_MORE;
4293 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004294 break;
dea31012005-04-17 16:05:31 -05004295 }
4296 }
4297 }
James Smart87af33f2007-10-27 13:37:43 -04004298 if (sentplogi) {
4299 lpfc_set_disctmo(vport);
4300 }
4301 else {
James Smart2e0fef82007-06-17 19:56:36 -05004302 spin_lock_irq(shost->host_lock);
4303 vport->fc_flag &= ~FC_NLP_MORE;
4304 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004305 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004306 return sentplogi;
dea31012005-04-17 16:05:31 -05004307}
4308
James Smarte59058c2008-08-24 21:49:00 -04004309/**
James Smart3621a712009-04-06 18:47:14 -04004310 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004311 * @vport: pointer to a host virtual N_Port data structure.
4312 *
4313 * This routine cleans up any Registration State Change Notification
4314 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4315 * @vport together with the host_lock is used to prevent multiple thread
4316 * trying to access the RSCN array on a same @vport at the same time.
4317 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004318void
James Smart2e0fef82007-06-17 19:56:36 -05004319lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004320{
James Smart2e0fef82007-06-17 19:56:36 -05004321 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4322 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004323 int i;
4324
James Smart7f5f3d02008-02-08 18:50:14 -05004325 spin_lock_irq(shost->host_lock);
4326 if (vport->fc_rscn_flush) {
4327 /* Another thread is walking fc_rscn_id_list on this vport */
4328 spin_unlock_irq(shost->host_lock);
4329 return;
4330 }
4331 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4332 vport->fc_rscn_flush = 1;
4333 spin_unlock_irq(shost->host_lock);
4334
James Smart2e0fef82007-06-17 19:56:36 -05004335 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004336 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004337 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004338 }
James Smart2e0fef82007-06-17 19:56:36 -05004339 spin_lock_irq(shost->host_lock);
4340 vport->fc_rscn_id_cnt = 0;
4341 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4342 spin_unlock_irq(shost->host_lock);
4343 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004344 /* Indicate we are done walking this fc_rscn_id_list */
4345 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004346}
4347
James Smarte59058c2008-08-24 21:49:00 -04004348/**
James Smart3621a712009-04-06 18:47:14 -04004349 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004350 * @vport: pointer to a host virtual N_Port data structure.
4351 * @did: remote destination port identifier.
4352 *
4353 * This routine checks whether there is any pending Registration State
4354 * Configuration Notification (RSCN) to a @did on @vport.
4355 *
4356 * Return code
4357 * None zero - The @did matched with a pending rscn
4358 * 0 - not able to match @did with a pending rscn
4359 **/
dea31012005-04-17 16:05:31 -05004360int
James Smart2e0fef82007-06-17 19:56:36 -05004361lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004362{
4363 D_ID ns_did;
4364 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004365 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004366 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004367 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004368
4369 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004370
4371 /* Never match fabric nodes for RSCNs */
4372 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004373 return 0;
dea31012005-04-17 16:05:31 -05004374
4375 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004376 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004377 return did;
dea31012005-04-17 16:05:31 -05004378
James Smart7f5f3d02008-02-08 18:50:14 -05004379 spin_lock_irq(shost->host_lock);
4380 if (vport->fc_rscn_flush) {
4381 /* Another thread is walking fc_rscn_id_list on this vport */
4382 spin_unlock_irq(shost->host_lock);
4383 return 0;
4384 }
4385 /* Indicate we are walking fc_rscn_id_list on this vport */
4386 vport->fc_rscn_flush = 1;
4387 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004388 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004389 lp = vport->fc_rscn_id_list[i]->virt;
4390 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4391 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004392 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004393 rscn_did.un.word = be32_to_cpu(*lp++);
4394 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004395 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4396 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004397 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4398 && (ns_did.un.b.area == rscn_did.un.b.area)
4399 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004400 goto return_did_out;
dea31012005-04-17 16:05:31 -05004401 break;
James Smarteaf15d52008-12-04 22:39:29 -05004402 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004403 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4404 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004405 goto return_did_out;
dea31012005-04-17 16:05:31 -05004406 break;
James Smarteaf15d52008-12-04 22:39:29 -05004407 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004408 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004409 goto return_did_out;
dea31012005-04-17 16:05:31 -05004410 break;
James Smarteaf15d52008-12-04 22:39:29 -05004411 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004412 goto return_did_out;
dea31012005-04-17 16:05:31 -05004413 }
4414 }
James Smart92d7f7b2007-06-17 19:56:38 -05004415 }
James Smart7f5f3d02008-02-08 18:50:14 -05004416 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4417 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004418 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004419return_did_out:
4420 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4421 vport->fc_rscn_flush = 0;
4422 return did;
dea31012005-04-17 16:05:31 -05004423}
4424
James Smarte59058c2008-08-24 21:49:00 -04004425/**
James Smart3621a712009-04-06 18:47:14 -04004426 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004427 * @vport: pointer to a host virtual N_Port data structure.
4428 *
4429 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4430 * state machine for a @vport's nodes that are with pending RSCN (Registration
4431 * State Change Notification).
4432 *
4433 * Return code
4434 * 0 - Successful (currently alway return 0)
4435 **/
dea31012005-04-17 16:05:31 -05004436static int
James Smart2e0fef82007-06-17 19:56:36 -05004437lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004438{
James Smart685f0bf2007-04-25 09:53:08 -04004439 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004440
James Smart0d2b6b82008-06-14 22:52:47 -04004441 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004442 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004443 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004444 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4445 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004446 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004447 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004448 NLP_EVT_DEVICE_RECOVERY);
4449 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004450 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004451 return 0;
dea31012005-04-17 16:05:31 -05004452}
4453
James Smarte59058c2008-08-24 21:49:00 -04004454/**
James Smart3621a712009-04-06 18:47:14 -04004455 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004456 * @vport: pointer to a host virtual N_Port data structure.
4457 * @cmdiocb: pointer to lpfc command iocb data structure.
4458 *
4459 * lpfc_send_rscn_event sends an RSCN netlink event to management
4460 * applications.
4461 */
4462static void
4463lpfc_send_rscn_event(struct lpfc_vport *vport,
4464 struct lpfc_iocbq *cmdiocb)
4465{
4466 struct lpfc_dmabuf *pcmd;
4467 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4468 uint32_t *payload_ptr;
4469 uint32_t payload_len;
4470 struct lpfc_rscn_event_header *rscn_event_data;
4471
4472 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4473 payload_ptr = (uint32_t *) pcmd->virt;
4474 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4475
4476 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4477 payload_len, GFP_KERNEL);
4478 if (!rscn_event_data) {
4479 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4480 "0147 Failed to allocate memory for RSCN event\n");
4481 return;
4482 }
4483 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4484 rscn_event_data->payload_length = payload_len;
4485 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4486 payload_len);
4487
4488 fc_host_post_vendor_event(shost,
4489 fc_get_event_number(),
4490 sizeof(struct lpfc_els_event_header) + payload_len,
4491 (char *)rscn_event_data,
4492 LPFC_NL_VENDOR_ID);
4493
4494 kfree(rscn_event_data);
4495}
4496
4497/**
James Smart3621a712009-04-06 18:47:14 -04004498 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004499 * @vport: pointer to a host virtual N_Port data structure.
4500 * @cmdiocb: pointer to lpfc command iocb data structure.
4501 * @ndlp: pointer to a node-list data structure.
4502 *
4503 * This routine processes an unsolicited RSCN (Registration State Change
4504 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4505 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4506 * discover state machine is about to begin discovery, it just accepts the
4507 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4508 * contains N_Port IDs for other vports on this HBA, it just accepts the
4509 * RSCN and ignore processing it. If the state machine is in the recovery
4510 * state, the fc_rscn_id_list of this @vport is walked and the
4511 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4512 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4513 * routine is invoked to handle the RSCN event.
4514 *
4515 * Return code
4516 * 0 - Just sent the acc response
4517 * 1 - Sent the acc response and waited for name server completion
4518 **/
dea31012005-04-17 16:05:31 -05004519static int
James Smart2e0fef82007-06-17 19:56:36 -05004520lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004521 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004522{
James Smart2e0fef82007-06-17 19:56:36 -05004523 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4524 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004525 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004526 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004527 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004528 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004529 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004530 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004531 int i;
dea31012005-04-17 16:05:31 -05004532
4533 icmd = &cmdiocb->iocb;
4534 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4535 lp = (uint32_t *) pcmd->virt;
4536
James Smart92d7f7b2007-06-17 19:56:38 -05004537 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4538 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004539 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004540 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4541 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004542 vport->fc_flag, payload_len, *lp,
4543 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004544
4545 /* Send an RSCN event to the management application */
4546 lpfc_send_rscn_event(vport, cmdiocb);
4547
James Smartd2873e42006-08-18 17:46:43 -04004548 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004549 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004550 FCH_EVT_RSCN, lp[i]);
4551
dea31012005-04-17 16:05:31 -05004552 /* If we are about to begin discovery, just ACC the RSCN.
4553 * Discovery processing will satisfy it.
4554 */
James Smart2e0fef82007-06-17 19:56:36 -05004555 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004556 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4557 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4558 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4559
James Smart51ef4c22007-08-02 11:10:31 -04004560 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004561 return 0;
dea31012005-04-17 16:05:31 -05004562 }
4563
James Smart92d7f7b2007-06-17 19:56:38 -05004564 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4565 * just ACC and ignore it.
4566 */
4567 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004568 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004569 i = payload_len;
4570 datap = lp;
4571 while (i > 0) {
4572 nportid = *datap++;
4573 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4574 i -= sizeof(uint32_t);
4575 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004576 if (lpfc_find_vport_by_did(phba, nportid))
4577 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004578 }
4579 if (rscn_id == hba_id) {
4580 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004581 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004582 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004583 "Data: x%x x%x x%x x%x\n",
4584 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004585 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004586 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4587 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4588 ndlp->nlp_DID, vport->port_state,
4589 ndlp->nlp_flag);
4590
James Smart92d7f7b2007-06-17 19:56:38 -05004591 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004592 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004593 return 0;
4594 }
4595 }
4596
James Smart7f5f3d02008-02-08 18:50:14 -05004597 spin_lock_irq(shost->host_lock);
4598 if (vport->fc_rscn_flush) {
4599 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004600 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004601 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004602 /* Send back ACC */
4603 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004604 return 0;
4605 }
4606 /* Indicate we are walking fc_rscn_id_list on this vport */
4607 vport->fc_rscn_flush = 1;
4608 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004609 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004610 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004611 /* If we are already processing an RSCN, save the received
4612 * RSCN payload buffer, cmdiocb->context2 to process later.
4613 */
James Smart2e0fef82007-06-17 19:56:36 -05004614 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004615 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4616 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4617 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4618
James Smart09372822008-01-11 01:52:54 -05004619 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004620 vport->fc_flag |= FC_RSCN_DEFERRED;
4621 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004622 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004623 vport->fc_flag |= FC_RSCN_MODE;
4624 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004625 if (rscn_cnt) {
4626 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4627 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4628 }
4629 if ((rscn_cnt) &&
4630 (payload_len + length <= LPFC_BPL_SIZE)) {
4631 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004632 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004633 memcpy(((uint8_t *)cmd) + length, lp,
4634 payload_len);
4635 } else {
4636 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4637 vport->fc_rscn_id_cnt++;
4638 /* If we zero, cmdiocb->context2, the calling
4639 * routine will not try to free it.
4640 */
4641 cmdiocb->context2 = NULL;
4642 }
dea31012005-04-17 16:05:31 -05004643 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004644 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4645 "0235 Deferred RSCN "
4646 "Data: x%x x%x x%x\n",
4647 vport->fc_rscn_id_cnt, vport->fc_flag,
4648 vport->port_state);
dea31012005-04-17 16:05:31 -05004649 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004650 vport->fc_flag |= FC_RSCN_DISCOVERY;
4651 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004652 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004653 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4654 "0234 ReDiscovery RSCN "
4655 "Data: x%x x%x x%x\n",
4656 vport->fc_rscn_id_cnt, vport->fc_flag,
4657 vport->port_state);
dea31012005-04-17 16:05:31 -05004658 }
James Smart7f5f3d02008-02-08 18:50:14 -05004659 /* Indicate we are done walking fc_rscn_id_list on this vport */
4660 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004661 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004662 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004663 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004664 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004665 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004666 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004667 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004668 return 0;
dea31012005-04-17 16:05:31 -05004669 }
James Smart858c9f62007-06-17 19:56:39 -05004670 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4671 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4672 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4673
James Smart2e0fef82007-06-17 19:56:36 -05004674 spin_lock_irq(shost->host_lock);
4675 vport->fc_flag |= FC_RSCN_MODE;
4676 spin_unlock_irq(shost->host_lock);
4677 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004678 /* Indicate we are done walking fc_rscn_id_list on this vport */
4679 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004680 /*
4681 * If we zero, cmdiocb->context2, the calling routine will
4682 * not try to free it.
4683 */
4684 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004685 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004686 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004687 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004688 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004689 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004690 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004691}
4692
James Smarte59058c2008-08-24 21:49:00 -04004693/**
James Smart3621a712009-04-06 18:47:14 -04004694 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004695 * @vport: pointer to a host virtual N_Port data structure.
4696 *
4697 * This routine handles the Registration State Configuration Notification
4698 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4699 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4700 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4701 * NameServer shall be issued. If CT command to the NameServer fails to be
4702 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4703 * RSCN activities with the @vport.
4704 *
4705 * Return code
4706 * 0 - Cleaned up rscn on the @vport
4707 * 1 - Wait for plogi to name server before proceed
4708 **/
dea31012005-04-17 16:05:31 -05004709int
James Smart2e0fef82007-06-17 19:56:36 -05004710lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004711{
4712 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004713 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004714
James Smart92d7f7b2007-06-17 19:56:38 -05004715 /* Ignore RSCN if the port is being torn down. */
4716 if (vport->load_flag & FC_UNLOADING) {
4717 lpfc_els_flush_rscn(vport);
4718 return 0;
4719 }
4720
dea31012005-04-17 16:05:31 -05004721 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004722 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004723
4724 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004725 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4726 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4727 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4728 vport->port_state);
dea31012005-04-17 16:05:31 -05004729
4730 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004731 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004732 vport->num_disc_nodes = 0;
4733
James Smart2e0fef82007-06-17 19:56:36 -05004734 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004735 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4736 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004737 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004738 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004739 /* Wait for NameServer query cmpl before we can
4740 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004741 return 1;
dea31012005-04-17 16:05:31 -05004742 } else {
4743 /* If login to NameServer does not exist, issue one */
4744 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004745 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004746 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004747 /* Wait for NameServer login cmpl before we can
4748 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004749 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004750
James Smarte47c9092008-02-08 18:49:26 -05004751 if (ndlp) {
4752 ndlp = lpfc_enable_node(vport, ndlp,
4753 NLP_STE_PLOGI_ISSUE);
4754 if (!ndlp) {
4755 lpfc_els_flush_rscn(vport);
4756 return 0;
4757 }
4758 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004759 } else {
James Smarte47c9092008-02-08 18:49:26 -05004760 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4761 if (!ndlp) {
4762 lpfc_els_flush_rscn(vport);
4763 return 0;
4764 }
James Smart2e0fef82007-06-17 19:56:36 -05004765 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004766 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004767 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004768 }
James Smarte47c9092008-02-08 18:49:26 -05004769 ndlp->nlp_type |= NLP_FABRIC;
4770 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4771 /* Wait for NameServer login cmpl before we can
4772 * continue
4773 */
4774 return 1;
dea31012005-04-17 16:05:31 -05004775 }
4776
James Smart2e0fef82007-06-17 19:56:36 -05004777 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004778 return 0;
dea31012005-04-17 16:05:31 -05004779}
4780
James Smarte59058c2008-08-24 21:49:00 -04004781/**
James Smart3621a712009-04-06 18:47:14 -04004782 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004783 * @vport: pointer to a host virtual N_Port data structure.
4784 * @cmdiocb: pointer to lpfc command iocb data structure.
4785 * @ndlp: pointer to a node-list data structure.
4786 *
4787 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4788 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4789 * point topology. As an unsolicited FLOGI should not be received in a loop
4790 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4791 * lpfc_check_sparm() routine is invoked to check the parameters in the
4792 * unsolicited FLOGI. If parameters validation failed, the routine
4793 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4794 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4795 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4796 * will initiate PLOGI. The higher lexicographical value party shall has
4797 * higher priority (as the winning port) and will initiate PLOGI and
4798 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4799 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4800 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4801 *
4802 * Return code
4803 * 0 - Successfully processed the unsolicited flogi
4804 * 1 - Failed to process the unsolicited flogi
4805 **/
dea31012005-04-17 16:05:31 -05004806static int
James Smart2e0fef82007-06-17 19:56:36 -05004807lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004808 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004809{
James Smart2e0fef82007-06-17 19:56:36 -05004810 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4811 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004812 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4813 uint32_t *lp = (uint32_t *) pcmd->virt;
4814 IOCB_t *icmd = &cmdiocb->iocb;
4815 struct serv_parm *sp;
4816 LPFC_MBOXQ_t *mbox;
4817 struct ls_rjt stat;
4818 uint32_t cmd, did;
4819 int rc;
4820
4821 cmd = *lp++;
4822 sp = (struct serv_parm *) lp;
4823
4824 /* FLOGI received */
4825
James Smart2e0fef82007-06-17 19:56:36 -05004826 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004827
James Smart76a95d72010-11-20 23:11:48 -05004828 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004829 /* We should never receive a FLOGI in loop mode, ignore it */
4830 did = icmd->un.elsreq64.remoteID;
4831
4832 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4833 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004834 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4835 "0113 An FLOGI ELS command x%x was "
4836 "received from DID x%x in Loop Mode\n",
4837 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004838 return 1;
dea31012005-04-17 16:05:31 -05004839 }
4840
4841 did = Fabric_DID;
4842
James Smart341af102010-01-26 23:07:37 -05004843 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004844 /* For a FLOGI we accept, then if our portname is greater
4845 * then the remote portname we initiate Nport login.
4846 */
4847
James Smart2e0fef82007-06-17 19:56:36 -05004848 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004849 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004850
4851 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004852 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4853 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004854 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004855
dea31012005-04-17 16:05:31 -05004856 lpfc_linkdown(phba);
4857 lpfc_init_link(phba, mbox,
4858 phba->cfg_topology,
4859 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004860 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004861 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004862 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004863 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004864 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004865 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004866 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004867 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004868 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004869 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004870 spin_lock_irq(shost->host_lock);
4871 vport->fc_flag |= FC_PT2PT_PLOGI;
4872 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004873 }
James Smart2e0fef82007-06-17 19:56:36 -05004874 spin_lock_irq(shost->host_lock);
4875 vport->fc_flag |= FC_PT2PT;
4876 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4877 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004878 } else {
4879 /* Reject this request because invalid parameters */
4880 stat.un.b.lsRjtRsvd0 = 0;
4881 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4882 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4883 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004884 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4885 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004886 return 1;
dea31012005-04-17 16:05:31 -05004887 }
4888
4889 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004890 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004891
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004892 return 0;
dea31012005-04-17 16:05:31 -05004893}
4894
James Smarte59058c2008-08-24 21:49:00 -04004895/**
James Smart3621a712009-04-06 18:47:14 -04004896 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004897 * @vport: pointer to a host virtual N_Port data structure.
4898 * @cmdiocb: pointer to lpfc command iocb data structure.
4899 * @ndlp: pointer to a node-list data structure.
4900 *
4901 * This routine processes Request Node Identification Data (RNID) IOCB
4902 * received as an ELS unsolicited event. Only when the RNID specified format
4903 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4904 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4905 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4906 * rejected by invoking the lpfc_els_rsp_reject() routine.
4907 *
4908 * Return code
4909 * 0 - Successfully processed rnid iocb (currently always return 0)
4910 **/
dea31012005-04-17 16:05:31 -05004911static int
James Smart2e0fef82007-06-17 19:56:36 -05004912lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4913 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004914{
4915 struct lpfc_dmabuf *pcmd;
4916 uint32_t *lp;
4917 IOCB_t *icmd;
4918 RNID *rn;
4919 struct ls_rjt stat;
4920 uint32_t cmd, did;
4921
4922 icmd = &cmdiocb->iocb;
4923 did = icmd->un.elsreq64.remoteID;
4924 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4925 lp = (uint32_t *) pcmd->virt;
4926
4927 cmd = *lp++;
4928 rn = (RNID *) lp;
4929
4930 /* RNID received */
4931
4932 switch (rn->Format) {
4933 case 0:
4934 case RNID_TOPOLOGY_DISC:
4935 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004936 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004937 break;
4938 default:
4939 /* Reject this request because format not supported */
4940 stat.un.b.lsRjtRsvd0 = 0;
4941 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4942 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4943 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004944 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4945 NULL);
dea31012005-04-17 16:05:31 -05004946 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004947 return 0;
dea31012005-04-17 16:05:31 -05004948}
4949
James Smarte59058c2008-08-24 21:49:00 -04004950/**
James Smart12265f62010-10-22 11:05:53 -04004951 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4952 * @vport: pointer to a host virtual N_Port data structure.
4953 * @cmdiocb: pointer to lpfc command iocb data structure.
4954 * @ndlp: pointer to a node-list data structure.
4955 *
4956 * Return code
4957 * 0 - Successfully processed echo iocb (currently always return 0)
4958 **/
4959static int
4960lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4961 struct lpfc_nodelist *ndlp)
4962{
4963 uint8_t *pcmd;
4964
4965 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4966
4967 /* skip over first word of echo command to find echo data */
4968 pcmd += sizeof(uint32_t);
4969
4970 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
4971 return 0;
4972}
4973
4974/**
James Smart3621a712009-04-06 18:47:14 -04004975 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004976 * @vport: pointer to a host virtual N_Port data structure.
4977 * @cmdiocb: pointer to lpfc command iocb data structure.
4978 * @ndlp: pointer to a node-list data structure.
4979 *
4980 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4981 * received as an ELS unsolicited event. Currently, this function just invokes
4982 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4983 *
4984 * Return code
4985 * 0 - Successfully processed lirr iocb (currently always return 0)
4986 **/
dea31012005-04-17 16:05:31 -05004987static int
James Smart2e0fef82007-06-17 19:56:36 -05004988lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4989 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004990{
4991 struct ls_rjt stat;
4992
4993 /* For now, unconditionally reject this command */
4994 stat.un.b.lsRjtRsvd0 = 0;
4995 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4996 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4997 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004998 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004999 return 0;
5000}
5001
James Smarte59058c2008-08-24 21:49:00 -04005002/**
James Smart5ffc2662009-11-18 15:39:44 -05005003 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5004 * @vport: pointer to a host virtual N_Port data structure.
5005 * @cmdiocb: pointer to lpfc command iocb data structure.
5006 * @ndlp: pointer to a node-list data structure.
5007 *
5008 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5009 * received as an ELS unsolicited event. A request to RRQ shall only
5010 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5011 * Nx_Port N_Port_ID of the target Exchange is the same as the
5012 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5013 * not accepted, an LS_RJT with reason code "Unable to perform
5014 * command request" and reason code explanation "Invalid Originator
5015 * S_ID" shall be returned. For now, we just unconditionally accept
5016 * RRQ from the target.
5017 **/
5018static void
5019lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5020 struct lpfc_nodelist *ndlp)
5021{
5022 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05005023 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5024 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05005025}
5026
5027/**
James Smart12265f62010-10-22 11:05:53 -04005028 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5029 * @phba: pointer to lpfc hba data structure.
5030 * @pmb: pointer to the driver internal queue element for mailbox command.
5031 *
5032 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5033 * mailbox command. This callback function is to actually send the Accept
5034 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5035 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5036 * mailbox command, constructs the RPS response with the link statistics
5037 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5038 * response to the RPS.
5039 *
5040 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5041 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5042 * will be stored into the context1 field of the IOCB for the completion
5043 * callback function to the RPS Accept Response ELS IOCB command.
5044 *
5045 **/
5046static void
5047lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5048{
5049 MAILBOX_t *mb;
5050 IOCB_t *icmd;
5051 struct RLS_RSP *rls_rsp;
5052 uint8_t *pcmd;
5053 struct lpfc_iocbq *elsiocb;
5054 struct lpfc_nodelist *ndlp;
5055 uint16_t xri;
5056 uint32_t cmdsize;
5057
5058 mb = &pmb->u.mb;
5059
5060 ndlp = (struct lpfc_nodelist *) pmb->context2;
5061 xri = (uint16_t) ((unsigned long)(pmb->context1));
5062 pmb->context1 = NULL;
5063 pmb->context2 = NULL;
5064
5065 if (mb->mbxStatus) {
5066 mempool_free(pmb, phba->mbox_mem_pool);
5067 return;
5068 }
5069
5070 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
5071 mempool_free(pmb, phba->mbox_mem_pool);
5072 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5073 lpfc_max_els_tries, ndlp,
5074 ndlp->nlp_DID, ELS_CMD_ACC);
5075
5076 /* Decrement the ndlp reference count from previous mbox command */
5077 lpfc_nlp_put(ndlp);
5078
5079 if (!elsiocb)
5080 return;
5081
5082 icmd = &elsiocb->iocb;
5083 icmd->ulpContext = xri;
5084
5085 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5086 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5087 pcmd += sizeof(uint32_t); /* Skip past command */
5088 rls_rsp = (struct RLS_RSP *)pcmd;
5089
5090 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5091 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5092 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5093 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5094 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5095 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
5096
5097 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5098 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5099 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5100 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5101 elsiocb->iotag, elsiocb->iocb.ulpContext,
5102 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5103 ndlp->nlp_rpi);
5104 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5105 phba->fc_stat.elsXmitACC++;
5106 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5107 lpfc_els_free_iocb(phba, elsiocb);
5108}
5109
5110/**
James Smart3621a712009-04-06 18:47:14 -04005111 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005112 * @phba: pointer to lpfc hba data structure.
5113 * @pmb: pointer to the driver internal queue element for mailbox command.
5114 *
5115 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5116 * mailbox command. This callback function is to actually send the Accept
5117 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5118 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5119 * mailbox command, constructs the RPS response with the link statistics
5120 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5121 * response to the RPS.
5122 *
5123 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5124 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5125 * will be stored into the context1 field of the IOCB for the completion
5126 * callback function to the RPS Accept Response ELS IOCB command.
5127 *
5128 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005129static void
James Smart329f9bc2007-04-25 09:53:01 -04005130lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005131{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005132 MAILBOX_t *mb;
5133 IOCB_t *icmd;
5134 RPS_RSP *rps_rsp;
5135 uint8_t *pcmd;
5136 struct lpfc_iocbq *elsiocb;
5137 struct lpfc_nodelist *ndlp;
5138 uint16_t xri, status;
5139 uint32_t cmdsize;
5140
James Smart04c68492009-05-22 14:52:52 -04005141 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005142
5143 ndlp = (struct lpfc_nodelist *) pmb->context2;
5144 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07005145 pmb->context1 = NULL;
5146 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005147
5148 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005149 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005150 return;
5151 }
5152
5153 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005154 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005155 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5156 lpfc_max_els_tries, ndlp,
5157 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005158
5159 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005160 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005161
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005162 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005163 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005164
5165 icmd = &elsiocb->iocb;
5166 icmd->ulpContext = xri;
5167
5168 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5169 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005170 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005171 rps_rsp = (RPS_RSP *)pcmd;
5172
James Smart76a95d72010-11-20 23:11:48 -05005173 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005174 status = 0x10;
5175 else
5176 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005177 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005178 status |= 0x4;
5179
5180 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005181 rps_rsp->portStatus = cpu_to_be16(status);
5182 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5183 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5184 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5185 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5186 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5187 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005188 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005189 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5190 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5191 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5192 elsiocb->iotag, elsiocb->iocb.ulpContext,
5193 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5194 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005195 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005196 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005197 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005198 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005199 return;
5200}
5201
James Smarte59058c2008-08-24 21:49:00 -04005202/**
James Smart12265f62010-10-22 11:05:53 -04005203 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5204 * @vport: pointer to a host virtual N_Port data structure.
5205 * @cmdiocb: pointer to lpfc command iocb data structure.
5206 * @ndlp: pointer to a node-list data structure.
5207 *
5208 * This routine processes Read Port Status (RPL) IOCB received as an
5209 * ELS unsolicited event. It first checks the remote port state. If the
5210 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5211 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5212 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5213 * for reading the HBA link statistics. It is for the callback function,
5214 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5215 * to actually sending out RPL Accept (ACC) response.
5216 *
5217 * Return codes
5218 * 0 - Successfully processed rls iocb (currently always return 0)
5219 **/
5220static int
5221lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5222 struct lpfc_nodelist *ndlp)
5223{
5224 struct lpfc_hba *phba = vport->phba;
5225 LPFC_MBOXQ_t *mbox;
5226 struct lpfc_dmabuf *pcmd;
5227 struct ls_rjt stat;
5228
5229 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5230 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5231 /* reject the unsolicited RPS request and done with it */
5232 goto reject_out;
5233
5234 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5235
5236 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5237 if (mbox) {
5238 lpfc_read_lnk_stat(phba, mbox);
5239 mbox->context1 =
5240 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
5241 mbox->context2 = lpfc_nlp_get(ndlp);
5242 mbox->vport = vport;
5243 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5244 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5245 != MBX_NOT_FINISHED)
5246 /* Mbox completion will send ELS Response */
5247 return 0;
5248 /* Decrement reference count used for the failed mbox
5249 * command.
5250 */
5251 lpfc_nlp_put(ndlp);
5252 mempool_free(mbox, phba->mbox_mem_pool);
5253 }
5254reject_out:
5255 /* issue rejection response */
5256 stat.un.b.lsRjtRsvd0 = 0;
5257 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5258 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5259 stat.un.b.vendorUnique = 0;
5260 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5261 return 0;
5262}
5263
5264/**
5265 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5266 * @vport: pointer to a host virtual N_Port data structure.
5267 * @cmdiocb: pointer to lpfc command iocb data structure.
5268 * @ndlp: pointer to a node-list data structure.
5269 *
5270 * This routine processes Read Timout Value (RTV) IOCB received as an
5271 * ELS unsolicited event. It first checks the remote port state. If the
5272 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5273 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5274 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5275 * Value (RTV) unsolicited IOCB event.
5276 *
5277 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5278 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5279 * will be stored into the context1 field of the IOCB for the completion
5280 * callback function to the RPS Accept Response ELS IOCB command.
5281 *
5282 * Return codes
5283 * 0 - Successfully processed rtv iocb (currently always return 0)
5284 **/
5285static int
5286lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5287 struct lpfc_nodelist *ndlp)
5288{
5289 struct lpfc_hba *phba = vport->phba;
5290 struct ls_rjt stat;
5291 struct RTV_RSP *rtv_rsp;
5292 uint8_t *pcmd;
5293 struct lpfc_iocbq *elsiocb;
5294 uint32_t cmdsize;
5295
5296
5297 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5298 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5299 /* reject the unsolicited RPS request and done with it */
5300 goto reject_out;
5301
5302 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5303 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5304 lpfc_max_els_tries, ndlp,
5305 ndlp->nlp_DID, ELS_CMD_ACC);
5306
5307 if (!elsiocb)
5308 return 1;
5309
5310 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5311 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5312 pcmd += sizeof(uint32_t); /* Skip past command */
5313
5314 /* use the command's xri in the response */
5315 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext;
5316
5317 rtv_rsp = (struct RTV_RSP *)pcmd;
5318
5319 /* populate RTV payload */
5320 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5321 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5322 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5323 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5324 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5325
5326 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5327 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5328 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5329 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5330 "Data: x%x x%x x%x\n",
5331 elsiocb->iotag, elsiocb->iocb.ulpContext,
5332 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5333 ndlp->nlp_rpi,
5334 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5335 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5336 phba->fc_stat.elsXmitACC++;
5337 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5338 lpfc_els_free_iocb(phba, elsiocb);
5339 return 0;
5340
5341reject_out:
5342 /* issue rejection response */
5343 stat.un.b.lsRjtRsvd0 = 0;
5344 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5345 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5346 stat.un.b.vendorUnique = 0;
5347 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5348 return 0;
5349}
5350
5351/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005352 * @vport: pointer to a host virtual N_Port data structure.
5353 * @cmdiocb: pointer to lpfc command iocb data structure.
5354 * @ndlp: pointer to a node-list data structure.
5355 *
5356 * This routine processes Read Port Status (RPS) IOCB received as an
5357 * ELS unsolicited event. It first checks the remote port state. If the
5358 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5359 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5360 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5361 * for reading the HBA link statistics. It is for the callback function,
5362 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5363 * to actually sending out RPS Accept (ACC) response.
5364 *
5365 * Return codes
5366 * 0 - Successfully processed rps iocb (currently always return 0)
5367 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005368static int
James Smart2e0fef82007-06-17 19:56:36 -05005369lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5370 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005371{
James Smart2e0fef82007-06-17 19:56:36 -05005372 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005373 uint32_t *lp;
5374 uint8_t flag;
5375 LPFC_MBOXQ_t *mbox;
5376 struct lpfc_dmabuf *pcmd;
5377 RPS *rps;
5378 struct ls_rjt stat;
5379
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005380 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005381 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5382 /* reject the unsolicited RPS request and done with it */
5383 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005384
5385 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5386 lp = (uint32_t *) pcmd->virt;
5387 flag = (be32_to_cpu(*lp++) & 0xf);
5388 rps = (RPS *) lp;
5389
5390 if ((flag == 0) ||
5391 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005392 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005393 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005394
James Smart92d7f7b2007-06-17 19:56:38 -05005395 printk("Fix me....\n");
5396 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005397 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5398 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005399 lpfc_read_lnk_stat(phba, mbox);
5400 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05005401 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04005402 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005403 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005404 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005405 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005406 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005407 /* Mbox completion will send ELS Response */
5408 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005409 /* Decrement reference count used for the failed mbox
5410 * command.
5411 */
James Smart329f9bc2007-04-25 09:53:01 -04005412 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005413 mempool_free(mbox, phba->mbox_mem_pool);
5414 }
5415 }
James Smart90160e02008-08-24 21:49:45 -04005416
5417reject_out:
5418 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005419 stat.un.b.lsRjtRsvd0 = 0;
5420 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5421 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5422 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005423 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005424 return 0;
5425}
5426
James Smart19ca7602010-11-20 23:11:55 -05005427/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5428 * @vport: pointer to a host virtual N_Port data structure.
5429 * @ndlp: pointer to a node-list data structure.
5430 * @did: DID of the target.
5431 * @rrq: Pointer to the rrq struct.
5432 *
5433 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5434 * Successful the the completion handler will clear the RRQ.
5435 *
5436 * Return codes
5437 * 0 - Successfully sent rrq els iocb.
5438 * 1 - Failed to send rrq els iocb.
5439 **/
5440static int
5441lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5442 uint32_t did, struct lpfc_node_rrq *rrq)
5443{
5444 struct lpfc_hba *phba = vport->phba;
5445 struct RRQ *els_rrq;
5446 IOCB_t *icmd;
5447 struct lpfc_iocbq *elsiocb;
5448 uint8_t *pcmd;
5449 uint16_t cmdsize;
5450 int ret;
5451
5452
5453 if (ndlp != rrq->ndlp)
5454 ndlp = rrq->ndlp;
5455 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5456 return 1;
5457
5458 /* If ndlp is not NULL, we will bump the reference count on it */
5459 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5460 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5461 ELS_CMD_RRQ);
5462 if (!elsiocb)
5463 return 1;
5464
5465 icmd = &elsiocb->iocb;
5466 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5467
5468 /* For RRQ request, remainder of payload is Exchange IDs */
5469 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5470 pcmd += sizeof(uint32_t);
5471 els_rrq = (struct RRQ *) pcmd;
5472
5473 bf_set(rrq_oxid, els_rrq, rrq->xritag);
5474 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5475 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5476 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5477 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5478
5479
5480 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5481 "Issue RRQ: did:x%x",
5482 did, rrq->xritag, rrq->rxid);
5483 elsiocb->context_un.rrq = rrq;
5484 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5485 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5486
5487 if (ret == IOCB_ERROR) {
5488 lpfc_els_free_iocb(phba, elsiocb);
5489 return 1;
5490 }
5491 return 0;
5492}
5493
5494/**
5495 * lpfc_send_rrq - Sends ELS RRQ if needed.
5496 * @phba: pointer to lpfc hba data structure.
5497 * @rrq: pointer to the active rrq.
5498 *
5499 * This routine will call the lpfc_issue_els_rrq if the rrq is
5500 * still active for the xri. If this function returns a failure then
5501 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5502 *
5503 * Returns 0 Success.
5504 * 1 Failure.
5505 **/
5506int
5507lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5508{
5509 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5510 rrq->nlp_DID);
5511 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5512 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5513 rrq->nlp_DID, rrq);
5514 else
5515 return 1;
5516}
5517
James Smarte59058c2008-08-24 21:49:00 -04005518/**
James Smart3621a712009-04-06 18:47:14 -04005519 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005520 * @vport: pointer to a host virtual N_Port data structure.
5521 * @cmdsize: size of the ELS command.
5522 * @oldiocb: pointer to the original lpfc command iocb data structure.
5523 * @ndlp: pointer to a node-list data structure.
5524 *
5525 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5526 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5527 *
5528 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5529 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5530 * will be stored into the context1 field of the IOCB for the completion
5531 * callback function to the RPL Accept Response ELS command.
5532 *
5533 * Return code
5534 * 0 - Successfully issued ACC RPL ELS command
5535 * 1 - Failed to issue ACC RPL ELS command
5536 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005537static int
James Smart2e0fef82007-06-17 19:56:36 -05005538lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5539 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005540{
James Smart2e0fef82007-06-17 19:56:36 -05005541 struct lpfc_hba *phba = vport->phba;
5542 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005543 RPL_RSP rpl_rsp;
5544 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005545 uint8_t *pcmd;
5546
James Smart2e0fef82007-06-17 19:56:36 -05005547 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5548 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005549
James Smart488d1462006-03-07 15:02:37 -05005550 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005551 return 1;
James Smart488d1462006-03-07 15:02:37 -05005552
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005553 icmd = &elsiocb->iocb;
5554 oldcmd = &oldiocb->iocb;
5555 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
5556
5557 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5558 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005559 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005560 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5561 pcmd += sizeof(uint16_t);
5562
5563 /* Setup the RPL ACC payload */
5564 rpl_rsp.listLen = be32_to_cpu(1);
5565 rpl_rsp.index = 0;
5566 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005567 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5568 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005569 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005570 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005571 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005572 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5573 "0120 Xmit ELS RPL ACC response tag x%x "
5574 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5575 "rpi x%x\n",
5576 elsiocb->iotag, elsiocb->iocb.ulpContext,
5577 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5578 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005579 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005580 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005581 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5582 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005583 lpfc_els_free_iocb(phba, elsiocb);
5584 return 1;
5585 }
5586 return 0;
5587}
5588
James Smarte59058c2008-08-24 21:49:00 -04005589/**
James Smart3621a712009-04-06 18:47:14 -04005590 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005591 * @vport: pointer to a host virtual N_Port data structure.
5592 * @cmdiocb: pointer to lpfc command iocb data structure.
5593 * @ndlp: pointer to a node-list data structure.
5594 *
5595 * This routine processes Read Port List (RPL) IOCB received as an ELS
5596 * unsolicited event. It first checks the remote port state. If the remote
5597 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5598 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5599 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5600 * to accept the RPL.
5601 *
5602 * Return code
5603 * 0 - Successfully processed rpl iocb (currently always return 0)
5604 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005605static int
James Smart2e0fef82007-06-17 19:56:36 -05005606lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5607 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005608{
5609 struct lpfc_dmabuf *pcmd;
5610 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005611 uint32_t maxsize;
5612 uint16_t cmdsize;
5613 RPL *rpl;
5614 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005615
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005616 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5617 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005618 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005619 stat.un.b.lsRjtRsvd0 = 0;
5620 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5621 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5622 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005623 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5624 NULL);
James Smart90160e02008-08-24 21:49:45 -04005625 /* rejected the unsolicited RPL request and done with it */
5626 return 0;
dea31012005-04-17 16:05:31 -05005627 }
5628
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005629 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5630 lp = (uint32_t *) pcmd->virt;
5631 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005632 maxsize = be32_to_cpu(rpl->maxsize);
5633
5634 /* We support only one port */
5635 if ((rpl->index == 0) &&
5636 ((maxsize == 0) ||
5637 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5638 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005639 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005640 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5641 }
James Smart2e0fef82007-06-17 19:56:36 -05005642 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005643
5644 return 0;
5645}
5646
James Smarte59058c2008-08-24 21:49:00 -04005647/**
James Smart3621a712009-04-06 18:47:14 -04005648 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005649 * @vport: pointer to a virtual N_Port data structure.
5650 * @cmdiocb: pointer to lpfc command iocb data structure.
5651 * @ndlp: pointer to a node-list data structure.
5652 *
5653 * This routine processes Fibre Channel Address Resolution Protocol
5654 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5655 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5656 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5657 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5658 * remote PortName is compared against the FC PortName stored in the @vport
5659 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5660 * compared against the FC NodeName stored in the @vport data structure.
5661 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5662 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5663 * invoked to send out FARP Response to the remote node. Before sending the
5664 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5665 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5666 * routine is invoked to log into the remote port first.
5667 *
5668 * Return code
5669 * 0 - Either the FARP Match Mode not supported or successfully processed
5670 **/
dea31012005-04-17 16:05:31 -05005671static int
James Smart2e0fef82007-06-17 19:56:36 -05005672lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5673 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005674{
5675 struct lpfc_dmabuf *pcmd;
5676 uint32_t *lp;
5677 IOCB_t *icmd;
5678 FARP *fp;
5679 uint32_t cmd, cnt, did;
5680
5681 icmd = &cmdiocb->iocb;
5682 did = icmd->un.elsreq64.remoteID;
5683 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5684 lp = (uint32_t *) pcmd->virt;
5685
5686 cmd = *lp++;
5687 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005688 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005689 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5690 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005691 /* We will only support match on WWPN or WWNN */
5692 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005693 return 0;
dea31012005-04-17 16:05:31 -05005694 }
5695
5696 cnt = 0;
5697 /* If this FARP command is searching for my portname */
5698 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005699 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005700 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005701 cnt = 1;
5702 }
5703
5704 /* If this FARP command is searching for my nodename */
5705 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005706 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005707 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005708 cnt = 1;
5709 }
5710
5711 if (cnt) {
5712 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5713 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5714 /* Log back into the node before sending the FARP. */
5715 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005716 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005717 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005718 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005719 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005720 }
5721
5722 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005723 if (fp->Rflags & FARP_REQUEST_FARPR)
5724 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005725 }
5726 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005727 return 0;
dea31012005-04-17 16:05:31 -05005728}
5729
James Smarte59058c2008-08-24 21:49:00 -04005730/**
James Smart3621a712009-04-06 18:47:14 -04005731 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005732 * @vport: pointer to a host virtual N_Port data structure.
5733 * @cmdiocb: pointer to lpfc command iocb data structure.
5734 * @ndlp: pointer to a node-list data structure.
5735 *
5736 * This routine processes Fibre Channel Address Resolution Protocol
5737 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5738 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5739 * the FARP response request.
5740 *
5741 * Return code
5742 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5743 **/
dea31012005-04-17 16:05:31 -05005744static int
James Smart2e0fef82007-06-17 19:56:36 -05005745lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5746 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005747{
5748 struct lpfc_dmabuf *pcmd;
5749 uint32_t *lp;
5750 IOCB_t *icmd;
5751 uint32_t cmd, did;
5752
5753 icmd = &cmdiocb->iocb;
5754 did = icmd->un.elsreq64.remoteID;
5755 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5756 lp = (uint32_t *) pcmd->virt;
5757
5758 cmd = *lp++;
5759 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005760 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5761 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005762 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005763 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005764
5765 return 0;
5766}
5767
James Smarte59058c2008-08-24 21:49:00 -04005768/**
James Smart3621a712009-04-06 18:47:14 -04005769 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005770 * @vport: pointer to a host virtual N_Port data structure.
5771 * @cmdiocb: pointer to lpfc command iocb data structure.
5772 * @fan_ndlp: pointer to a node-list data structure.
5773 *
5774 * This routine processes a Fabric Address Notification (FAN) IOCB
5775 * command received as an ELS unsolicited event. The FAN ELS command will
5776 * only be processed on a physical port (i.e., the @vport represents the
5777 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5778 * compared against those in the phba data structure. If any of those is
5779 * different, the lpfc_initial_flogi() routine is invoked to initialize
5780 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5781 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5782 * is invoked to register login to the fabric.
5783 *
5784 * Return code
5785 * 0 - Successfully processed fan iocb (currently always return 0).
5786 **/
dea31012005-04-17 16:05:31 -05005787static int
James Smart2e0fef82007-06-17 19:56:36 -05005788lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5789 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005790{
James Smart2e0fef82007-06-17 19:56:36 -05005791 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005792 uint32_t *lp;
5793 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005794
James Smart0d2b6b82008-06-14 22:52:47 -04005795 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5796 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5797 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005798 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005799 if ((vport == phba->pport) &&
5800 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005801 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005802 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005803 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005804 sizeof(struct lpfc_name)))) {
5805 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05005806 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005807 } else {
5808 /* FAN verified - skip FLOGI */
5809 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005810 if (phba->sli_rev < LPFC_SLI_REV4)
5811 lpfc_issue_fabric_reglogin(vport);
5812 else
5813 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005814 }
dea31012005-04-17 16:05:31 -05005815 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005816 return 0;
dea31012005-04-17 16:05:31 -05005817}
5818
James Smarte59058c2008-08-24 21:49:00 -04005819/**
James Smart3621a712009-04-06 18:47:14 -04005820 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005821 * @ptr: holder for the timer function associated data.
5822 *
5823 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5824 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5825 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5826 * up the worker thread. It is for the worker thread to invoke the routine
5827 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5828 **/
dea31012005-04-17 16:05:31 -05005829void
5830lpfc_els_timeout(unsigned long ptr)
5831{
James Smart2e0fef82007-06-17 19:56:36 -05005832 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5833 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005834 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005835 unsigned long iflag;
5836
James Smart2e0fef82007-06-17 19:56:36 -05005837 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005838 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5839 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005840 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005841 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005842
James Smart5e9d9b82008-06-14 22:52:53 -04005843 if (!tmo_posted)
5844 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005845 return;
5846}
5847
James Smart2a9bf3d2010-06-07 15:24:45 -04005848
James Smarte59058c2008-08-24 21:49:00 -04005849/**
James Smart3621a712009-04-06 18:47:14 -04005850 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005851 * @vport: pointer to a virtual N_Port data structure.
5852 *
5853 * This routine is the actual handler function that processes an ELS timeout
5854 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5855 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5856 * invoking the lpfc_sli_issue_abort_iotag() routine.
5857 **/
dea31012005-04-17 16:05:31 -05005858void
James Smart2e0fef82007-06-17 19:56:36 -05005859lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005860{
James Smart2e0fef82007-06-17 19:56:36 -05005861 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005862 struct lpfc_sli_ring *pring;
5863 struct lpfc_iocbq *tmp_iocb, *piocb;
5864 IOCB_t *cmd = NULL;
5865 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005866 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005867 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005868 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005869 LIST_HEAD(txcmplq_completions);
5870 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005871
James Smart2a9bf3d2010-06-07 15:24:45 -04005872
dea31012005-04-17 16:05:31 -05005873 timeout = (uint32_t)(phba->fc_ratov << 1);
5874
5875 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005876
James Smart2a9bf3d2010-06-07 15:24:45 -04005877 spin_lock_irq(&phba->hbalock);
5878 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5879 spin_unlock_irq(&phba->hbalock);
5880
5881 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005882 cmd = &piocb->iocb;
5883
James Smart2e0fef82007-06-17 19:56:36 -05005884 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5885 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5886 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005887 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005888
5889 if (piocb->vport != vport)
5890 continue;
5891
dea31012005-04-17 16:05:31 -05005892 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005893 if (pcmd)
5894 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005895
James Smart92d7f7b2007-06-17 19:56:38 -05005896 if (els_command == ELS_CMD_FARP ||
5897 els_command == ELS_CMD_FARPR ||
5898 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005899 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005900
dea31012005-04-17 16:05:31 -05005901 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005902 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005903 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005904 else
dea31012005-04-17 16:05:31 -05005905 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005906 continue;
5907 }
5908
James Smart2e0fef82007-06-17 19:56:36 -05005909 remote_ID = 0xffffffff;
5910 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005911 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005912 else {
5913 struct lpfc_nodelist *ndlp;
5914 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005915 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005916 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005917 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005918 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05005919 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005920 spin_lock_irq(&phba->hbalock);
5921 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05005922 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005923
James Smart2a9bf3d2010-06-07 15:24:45 -04005924 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5925 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5926 "0127 ELS timeout Data: x%x x%x x%x "
5927 "x%x\n", els_command,
5928 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5929 spin_lock_irq(&phba->hbalock);
5930 list_del_init(&piocb->dlist);
5931 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5932 spin_unlock_irq(&phba->hbalock);
5933 }
5934
James Smart2e0fef82007-06-17 19:56:36 -05005935 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5936 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005937}
5938
James Smarte59058c2008-08-24 21:49:00 -04005939/**
James Smart3621a712009-04-06 18:47:14 -04005940 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005941 * @vport: pointer to a host virtual N_Port data structure.
5942 *
5943 * This routine is used to clean up all the outstanding ELS commands on a
5944 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5945 * routine. After that, it walks the ELS transmit queue to remove all the
5946 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5947 * the IOCBs with a non-NULL completion callback function, the callback
5948 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5949 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5950 * callback function, the IOCB will simply be released. Finally, it walks
5951 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5952 * completion queue IOCB that is associated with the @vport and is not
5953 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5954 * part of the discovery state machine) out to HBA by invoking the
5955 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5956 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5957 * the IOCBs are aborted when this function returns.
5958 **/
dea31012005-04-17 16:05:31 -05005959void
James Smart2e0fef82007-06-17 19:56:36 -05005960lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005961{
James Smart2534ba72007-04-25 09:52:20 -04005962 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005963 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005964 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005965 struct lpfc_iocbq *tmp_iocb, *piocb;
5966 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005967
5968 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005969
James Smart2e0fef82007-06-17 19:56:36 -05005970 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005971 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5972 cmd = &piocb->iocb;
5973
5974 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5975 continue;
5976 }
5977
5978 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005979 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5980 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5981 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5982 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005983 continue;
dea31012005-04-17 16:05:31 -05005984
James Smart2e0fef82007-06-17 19:56:36 -05005985 if (piocb->vport != vport)
5986 continue;
5987
James Smart2534ba72007-04-25 09:52:20 -04005988 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005989 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005990 }
5991
5992 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005993 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5994 continue;
5995 }
dea31012005-04-17 16:05:31 -05005996
James Smart2e0fef82007-06-17 19:56:36 -05005997 if (piocb->vport != vport)
5998 continue;
5999
James Smart07951072007-04-25 09:51:38 -04006000 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05006001 }
James Smart2e0fef82007-06-17 19:56:36 -05006002 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04006003
James Smarta257bf92009-04-06 18:48:10 -04006004 /* Cancell all the IOCBs from the completions list */
6005 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6006 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04006007
dea31012005-04-17 16:05:31 -05006008 return;
6009}
6010
James Smarte59058c2008-08-24 21:49:00 -04006011/**
James Smart3621a712009-04-06 18:47:14 -04006012 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04006013 * @phba: pointer to lpfc hba data structure.
6014 *
6015 * This routine is used to clean up all the outstanding ELS commands on a
6016 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6017 * routine. After that, it walks the ELS transmit queue to remove all the
6018 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6019 * the IOCBs with the completion callback function associated, the callback
6020 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6021 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6022 * callback function associated, the IOCB will simply be released. Finally,
6023 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6024 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6025 * management plane IOCBs that are not part of the discovery state machine)
6026 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6027 **/
James Smart549e55c2007-08-02 11:09:51 -04006028void
6029lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6030{
6031 LIST_HEAD(completions);
6032 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6033 struct lpfc_iocbq *tmp_iocb, *piocb;
6034 IOCB_t *cmd = NULL;
6035
6036 lpfc_fabric_abort_hba(phba);
6037 spin_lock_irq(&phba->hbalock);
6038 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6039 cmd = &piocb->iocb;
6040 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6041 continue;
6042 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6043 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6044 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6045 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6046 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6047 continue;
6048 list_move_tail(&piocb->list, &completions);
6049 pring->txq_cnt--;
6050 }
6051 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6052 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6053 continue;
6054 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6055 }
6056 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04006057
6058 /* Cancel all the IOCBs from the completions list */
6059 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6060 IOERR_SLI_ABORTED);
6061
James Smart549e55c2007-08-02 11:09:51 -04006062 return;
6063}
6064
James Smarte59058c2008-08-24 21:49:00 -04006065/**
James Smart3621a712009-04-06 18:47:14 -04006066 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04006067 * @phba: Pointer to hba context object.
6068 * @cmdiocbp: Pointer to command iocb which reported error.
6069 * @rspiocbp: Pointer to response iocb which reported error.
6070 *
6071 * This function sends an event when there is an ELS command
6072 * failure.
6073 **/
6074void
6075lpfc_send_els_failure_event(struct lpfc_hba *phba,
6076 struct lpfc_iocbq *cmdiocbp,
6077 struct lpfc_iocbq *rspiocbp)
6078{
6079 struct lpfc_vport *vport = cmdiocbp->vport;
6080 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6081 struct lpfc_lsrjt_event lsrjt_event;
6082 struct lpfc_fabric_event_header fabric_event;
6083 struct ls_rjt stat;
6084 struct lpfc_nodelist *ndlp;
6085 uint32_t *pcmd;
6086
6087 ndlp = cmdiocbp->context1;
6088 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6089 return;
6090
6091 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6092 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6093 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6094 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6095 sizeof(struct lpfc_name));
6096 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6097 sizeof(struct lpfc_name));
6098 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6099 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006100 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006101 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6102 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6103 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6104 fc_host_post_vendor_event(shost,
6105 fc_get_event_number(),
6106 sizeof(lsrjt_event),
6107 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006108 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006109 return;
6110 }
6111 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6112 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6113 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6114 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6115 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6116 else
6117 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6118 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6119 sizeof(struct lpfc_name));
6120 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6121 sizeof(struct lpfc_name));
6122 fc_host_post_vendor_event(shost,
6123 fc_get_event_number(),
6124 sizeof(fabric_event),
6125 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006126 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006127 return;
6128 }
6129
6130}
6131
6132/**
James Smart3621a712009-04-06 18:47:14 -04006133 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006134 * @vport: Pointer to vport object.
6135 * @ndlp: Pointer FC node object.
6136 * @cmd: ELS command code.
6137 *
6138 * This function posts an event when there is an incoming
6139 * unsolicited ELS command.
6140 **/
6141static void
6142lpfc_send_els_event(struct lpfc_vport *vport,
6143 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006144 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006145{
James Smartddcc50f2008-12-04 22:38:46 -05006146 struct lpfc_els_event_header *els_data = NULL;
6147 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006148 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6149
James Smartddcc50f2008-12-04 22:38:46 -05006150 if (*payload == ELS_CMD_LOGO) {
6151 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6152 if (!logo_data) {
6153 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6154 "0148 Failed to allocate memory "
6155 "for LOGO event\n");
6156 return;
6157 }
6158 els_data = &logo_data->header;
6159 } else {
6160 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6161 GFP_KERNEL);
6162 if (!els_data) {
6163 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6164 "0149 Failed to allocate memory "
6165 "for ELS event\n");
6166 return;
6167 }
6168 }
6169 els_data->event_type = FC_REG_ELS_EVENT;
6170 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006171 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006172 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006173 break;
6174 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006175 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006176 break;
6177 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006178 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6179 break;
6180 case ELS_CMD_LOGO:
6181 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6182 /* Copy the WWPN in the LOGO payload */
6183 memcpy(logo_data->logo_wwpn, &payload[2],
6184 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006185 break;
6186 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006187 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006188 return;
6189 }
James Smartddcc50f2008-12-04 22:38:46 -05006190 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6191 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6192 if (*payload == ELS_CMD_LOGO) {
6193 fc_host_post_vendor_event(shost,
6194 fc_get_event_number(),
6195 sizeof(struct lpfc_logo_event),
6196 (char *)logo_data,
6197 LPFC_NL_VENDOR_ID);
6198 kfree(logo_data);
6199 } else {
6200 fc_host_post_vendor_event(shost,
6201 fc_get_event_number(),
6202 sizeof(struct lpfc_els_event_header),
6203 (char *)els_data,
6204 LPFC_NL_VENDOR_ID);
6205 kfree(els_data);
6206 }
James Smartea2151b2008-09-07 11:52:10 -04006207
6208 return;
6209}
6210
6211
6212/**
James Smart3621a712009-04-06 18:47:14 -04006213 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006214 * @phba: pointer to lpfc hba data structure.
6215 * @pring: pointer to a SLI ring.
6216 * @vport: pointer to a host virtual N_Port data structure.
6217 * @elsiocb: pointer to lpfc els command iocb data structure.
6218 *
6219 * This routine is used for processing the IOCB associated with a unsolicited
6220 * event. It first determines whether there is an existing ndlp that matches
6221 * the DID from the unsolicited IOCB. If not, it will create a new one with
6222 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6223 * IOCB is then used to invoke the proper routine and to set up proper state
6224 * of the discovery state machine.
6225 **/
James Smarted957682007-06-17 19:56:37 -05006226static void
6227lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006228 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006229{
James Smart87af33f2007-10-27 13:37:43 -04006230 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006231 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006232 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006233 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05006234 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006235 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006236
James Smarte47c9092008-02-08 18:49:26 -05006237 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006238 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006239
dea31012005-04-17 16:05:31 -05006240 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006241 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6242 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006243 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006244 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006245
James Smart858c9f62007-06-17 19:56:39 -05006246 did = icmd->un.rcvels.remoteID;
6247 if (icmd->ulpStatus) {
6248 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6249 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6250 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006251 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006252 }
dea31012005-04-17 16:05:31 -05006253
6254 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006255 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006256 goto dropit;
dea31012005-04-17 16:05:31 -05006257
James Smartc8685952009-11-18 15:39:16 -05006258 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006259 if (vport->load_flag & FC_UNLOADING)
6260 goto dropit;
6261
James Smart92494142011-02-16 12:39:44 -05006262 /* If NPort discovery is delayed drop incoming ELS */
6263 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6264 (cmd != ELS_CMD_PLOGI))
6265 goto dropit;
6266
James Smart2e0fef82007-06-17 19:56:36 -05006267 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006268 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006269 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006270 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006271 if (!ndlp)
dea31012005-04-17 16:05:31 -05006272 goto dropit;
dea31012005-04-17 16:05:31 -05006273
James Smart2e0fef82007-06-17 19:56:36 -05006274 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006275 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006276 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006277 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006278 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006279 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6280 ndlp = lpfc_enable_node(vport, ndlp,
6281 NLP_STE_UNUSED_NODE);
6282 if (!ndlp)
6283 goto dropit;
6284 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6285 newnode = 1;
6286 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6287 ndlp->nlp_type |= NLP_FABRIC;
6288 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6289 /* This is similar to the new node path */
6290 ndlp = lpfc_nlp_get(ndlp);
6291 if (!ndlp)
6292 goto dropit;
6293 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6294 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006295 }
dea31012005-04-17 16:05:31 -05006296
6297 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006298
James Smart329f9bc2007-04-25 09:53:01 -04006299 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006300 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006301
6302 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6303 cmd &= ELS_CMD_MASK;
6304 }
6305 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006306 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6307 "0112 ELS command x%x received from NPORT x%x "
6308 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006309 switch (cmd) {
6310 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006311 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6312 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6313 did, vport->port_state, ndlp->nlp_flag);
6314
dea31012005-04-17 16:05:31 -05006315 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006316 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6317
James Smartddcc50f2008-12-04 22:38:46 -05006318 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05006319
6320 /* If Nport discovery is delayed, reject PLOGIs */
6321 if (vport->fc_flag & FC_DISC_DELAYED) {
6322 rjt_err = LSRJT_UNABLE_TPC;
6323 break;
6324 }
James Smart858c9f62007-06-17 19:56:39 -05006325 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006326 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6327 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6328 rjt_err = LSRJT_UNABLE_TPC;
6329 break;
6330 }
6331 /* We get here, and drop thru, if we are PT2PT with
6332 * another NPort and the other side has initiated
6333 * the PLOGI before responding to our FLOGI.
6334 */
dea31012005-04-17 16:05:31 -05006335 }
James Smart87af33f2007-10-27 13:37:43 -04006336
6337 shost = lpfc_shost_from_vport(vport);
6338 spin_lock_irq(shost->host_lock);
6339 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6340 spin_unlock_irq(shost->host_lock);
6341
James Smart2e0fef82007-06-17 19:56:36 -05006342 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6343 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006344
dea31012005-04-17 16:05:31 -05006345 break;
6346 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006347 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6348 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6349 did, vport->port_state, ndlp->nlp_flag);
6350
dea31012005-04-17 16:05:31 -05006351 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006352 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006353 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006354 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006355 break;
6356 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006357 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6358 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6359 did, vport->port_state, ndlp->nlp_flag);
6360
dea31012005-04-17 16:05:31 -05006361 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006362 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006363 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006364 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006365 break;
6366 }
James Smart2e0fef82007-06-17 19:56:36 -05006367 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006368 break;
6369 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006370 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6371 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6372 did, vport->port_state, ndlp->nlp_flag);
6373
dea31012005-04-17 16:05:31 -05006374 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006375 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006376 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006377 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006378 break;
6379 }
James Smart2e0fef82007-06-17 19:56:36 -05006380 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006381 break;
6382 case ELS_CMD_RSCN:
6383 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006384 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006385 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006386 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006387 break;
6388 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006389 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6390 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6391 did, vport->port_state, ndlp->nlp_flag);
6392
James Smartddcc50f2008-12-04 22:38:46 -05006393 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006394 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006395 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006396 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006397 break;
6398 }
James Smart2e0fef82007-06-17 19:56:36 -05006399 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6400 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006401 break;
6402 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006403 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6404 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6405 did, vport->port_state, ndlp->nlp_flag);
6406
dea31012005-04-17 16:05:31 -05006407 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006408 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006409 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006410 break;
6411 }
James Smart2e0fef82007-06-17 19:56:36 -05006412 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6413 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006414 break;
6415 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006416 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6417 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6418 did, vport->port_state, ndlp->nlp_flag);
6419
dea31012005-04-17 16:05:31 -05006420 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006421 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006422 break;
6423 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006424 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6425 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6426 did, vport->port_state, ndlp->nlp_flag);
6427
dea31012005-04-17 16:05:31 -05006428 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006429 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006430 break;
6431 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006432 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6433 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6434 did, vport->port_state, ndlp->nlp_flag);
6435
dea31012005-04-17 16:05:31 -05006436 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006437 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006438 break;
dea31012005-04-17 16:05:31 -05006439 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006440 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6441 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6442 did, vport->port_state, ndlp->nlp_flag);
6443
dea31012005-04-17 16:05:31 -05006444 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006445 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006446 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006447 break;
6448 }
James Smart2e0fef82007-06-17 19:56:36 -05006449 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006450 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006451 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006452 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6453 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6454 did, vport->port_state, ndlp->nlp_flag);
6455
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006456 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006457 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006458 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006459 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006460 break;
James Smart12265f62010-10-22 11:05:53 -04006461 case ELS_CMD_RLS:
6462 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6463 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6464 did, vport->port_state, ndlp->nlp_flag);
6465
6466 phba->fc_stat.elsRcvRLS++;
6467 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6468 if (newnode)
6469 lpfc_nlp_put(ndlp);
6470 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006471 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006472 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6473 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6474 did, vport->port_state, ndlp->nlp_flag);
6475
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006476 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006477 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006478 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006479 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006480 break;
6481 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006482 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6483 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6484 did, vport->port_state, ndlp->nlp_flag);
6485
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006486 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006487 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006488 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006489 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006490 break;
dea31012005-04-17 16:05:31 -05006491 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006492 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6493 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6494 did, vport->port_state, ndlp->nlp_flag);
6495
dea31012005-04-17 16:05:31 -05006496 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006497 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006498 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006499 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006500 break;
James Smart12265f62010-10-22 11:05:53 -04006501 case ELS_CMD_RTV:
6502 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6503 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6504 did, vport->port_state, ndlp->nlp_flag);
6505 phba->fc_stat.elsRcvRTV++;
6506 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6507 if (newnode)
6508 lpfc_nlp_put(ndlp);
6509 break;
James Smart5ffc2662009-11-18 15:39:44 -05006510 case ELS_CMD_RRQ:
6511 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6512 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6513 did, vport->port_state, ndlp->nlp_flag);
6514
6515 phba->fc_stat.elsRcvRRQ++;
6516 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6517 if (newnode)
6518 lpfc_nlp_put(ndlp);
6519 break;
James Smart12265f62010-10-22 11:05:53 -04006520 case ELS_CMD_ECHO:
6521 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6522 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6523 did, vport->port_state, ndlp->nlp_flag);
6524
6525 phba->fc_stat.elsRcvECHO++;
6526 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6527 if (newnode)
6528 lpfc_nlp_put(ndlp);
6529 break;
dea31012005-04-17 16:05:31 -05006530 default:
James Smart858c9f62007-06-17 19:56:39 -05006531 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6532 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6533 cmd, did, vport->port_state);
6534
dea31012005-04-17 16:05:31 -05006535 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006536 rjt_err = LSRJT_CMD_UNSUPPORTED;
dea31012005-04-17 16:05:31 -05006537
6538 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006539 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6540 "0115 Unknown ELS command x%x "
6541 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006542 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006543 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006544 break;
6545 }
6546
6547 /* check if need to LS_RJT received ELS cmd */
6548 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006549 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006550 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006551 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006552 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6553 NULL);
dea31012005-04-17 16:05:31 -05006554 }
6555
James Smartd7c255b2008-08-24 21:50:00 -04006556 lpfc_nlp_put(elsiocb->context1);
6557 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006558 return;
6559
6560dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006561 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006562 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6563 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006564 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006565 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006566 phba->fc_stat.elsRcvDrop++;
6567}
6568
James Smarte59058c2008-08-24 21:49:00 -04006569/**
James Smart3621a712009-04-06 18:47:14 -04006570 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04006571 * @phba: pointer to lpfc hba data structure.
6572 * @vpi: host virtual N_Port identifier.
6573 *
6574 * This routine finds a vport on a HBA (referred by @phba) through a
6575 * @vpi. The function walks the HBA's vport list and returns the address
6576 * of the vport with the matching @vpi.
6577 *
6578 * Return code
6579 * NULL - No vport with the matching @vpi found
6580 * Otherwise - Address to the vport with the matching @vpi.
6581 **/
James Smart6669f9b2009-10-02 15:16:45 -04006582struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05006583lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6584{
6585 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04006586 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05006587
James Smart549e55c2007-08-02 11:09:51 -04006588 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006589 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04006590 if (vport->vpi == vpi) {
6591 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006592 return vport;
James Smart549e55c2007-08-02 11:09:51 -04006593 }
James Smart92d7f7b2007-06-17 19:56:38 -05006594 }
James Smart549e55c2007-08-02 11:09:51 -04006595 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006596 return NULL;
6597}
James Smarted957682007-06-17 19:56:37 -05006598
James Smarte59058c2008-08-24 21:49:00 -04006599/**
James Smart3621a712009-04-06 18:47:14 -04006600 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006601 * @phba: pointer to lpfc hba data structure.
6602 * @pring: pointer to a SLI ring.
6603 * @elsiocb: pointer to lpfc els iocb data structure.
6604 *
6605 * This routine is used to process an unsolicited event received from a SLI
6606 * (Service Level Interface) ring. The actual processing of the data buffer
6607 * associated with the unsolicited event is done by invoking the routine
6608 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6609 * SLI ring on which the unsolicited event was received.
6610 **/
James Smarted957682007-06-17 19:56:37 -05006611void
6612lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6613 struct lpfc_iocbq *elsiocb)
6614{
6615 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006616 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006617 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006618 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6619 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006620
James Smartd7c255b2008-08-24 21:50:00 -04006621 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006622 elsiocb->context2 = NULL;
6623 elsiocb->context3 = NULL;
6624
6625 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6626 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6627 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6628 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006629 phba->fc_stat.NoRcvBuf++;
6630 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006631 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006632 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006633 return;
6634 }
6635
James Smart92d7f7b2007-06-17 19:56:38 -05006636 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6637 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6638 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6639 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6640 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006641 else
6642 vport = lpfc_find_vport_by_vpid(phba,
6643 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05006644 }
James Smart7f5f3d02008-02-08 18:50:14 -05006645 /* If there are no BDEs associated
6646 * with this IOCB, there is nothing to do.
6647 */
James Smarted957682007-06-17 19:56:37 -05006648 if (icmd->ulpBdeCount == 0)
6649 return;
6650
James Smart7f5f3d02008-02-08 18:50:14 -05006651 /* type of ELS cmd is first 32bit word
6652 * in packet
6653 */
James Smarted957682007-06-17 19:56:37 -05006654 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006655 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006656 } else {
6657 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6658 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006659 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6660 paddr);
James Smarted957682007-06-17 19:56:37 -05006661 }
6662
James Smart92d7f7b2007-06-17 19:56:38 -05006663 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6664 /*
6665 * The different unsolicited event handlers would tell us
6666 * if they are done with "mp" by setting context2 to NULL.
6667 */
dea31012005-04-17 16:05:31 -05006668 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006669 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6670 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006671 }
James Smarted957682007-06-17 19:56:37 -05006672
6673 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006674 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006675 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006676 elsiocb->context2 = bdeBuf2;
6677 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006678 /* free mp if we are done with it */
6679 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006680 lpfc_in_buf_free(phba, elsiocb->context2);
6681 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006682 }
dea31012005-04-17 16:05:31 -05006683 }
dea31012005-04-17 16:05:31 -05006684}
James Smart92d7f7b2007-06-17 19:56:38 -05006685
James Smarte59058c2008-08-24 21:49:00 -04006686/**
James Smart3621a712009-04-06 18:47:14 -04006687 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006688 * @phba: pointer to lpfc hba data structure.
6689 * @vport: pointer to a virtual N_Port data structure.
6690 *
6691 * This routine issues a Port Login (PLOGI) to the Name Server with
6692 * State Change Request (SCR) for a @vport. This routine will create an
6693 * ndlp for the Name Server associated to the @vport if such node does
6694 * not already exist. The PLOGI to Name Server is issued by invoking the
6695 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6696 * (FDMI) is configured to the @vport, a FDMI node will be created and
6697 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6698 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006699void
6700lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6701{
6702 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05006703 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6704
6705 /*
6706 * If lpfc_delay_discovery parameter is set and the clean address
6707 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6708 * discovery.
6709 */
6710 spin_lock_irq(shost->host_lock);
6711 if (vport->fc_flag & FC_DISC_DELAYED) {
6712 spin_unlock_irq(shost->host_lock);
6713 mod_timer(&vport->delayed_disc_tmo,
6714 jiffies + HZ * phba->fc_ratov);
6715 return;
6716 }
6717 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006718
6719 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6720 if (!ndlp) {
6721 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6722 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006723 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05006724 lpfc_disc_start(vport);
6725 return;
6726 }
6727 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006728 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6729 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006730 return;
6731 }
6732 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006733 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6734 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6735 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006736 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05006737 lpfc_disc_start(vport);
6738 return;
6739 }
6740 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6741 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6742 "0348 NameServer login: node freed\n");
6743 return;
6744 }
James Smart92d7f7b2007-06-17 19:56:38 -05006745 }
James Smart58da1ff2008-04-07 10:15:56 -04006746 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006747
6748 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6749
6750 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6751 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006752 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6753 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006754 return;
6755 }
6756
James Smart3de2a652007-08-02 11:09:59 -04006757 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05006758 /* If this is the first time, allocate an ndlp and initialize
6759 * it. Otherwise, make sure the node is enabled and then do the
6760 * login.
6761 */
6762 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
6763 if (!ndlp_fdmi) {
6764 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6765 GFP_KERNEL);
6766 if (ndlp_fdmi) {
6767 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6768 ndlp_fdmi->nlp_type |= NLP_FABRIC;
6769 } else
6770 return;
6771 }
6772 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
6773 ndlp_fdmi = lpfc_enable_node(vport,
6774 ndlp_fdmi,
6775 NLP_STE_NPR_NODE);
6776
James Smart92d7f7b2007-06-17 19:56:38 -05006777 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04006778 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05006779 NLP_STE_PLOGI_ISSUE);
6780 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006781 }
6782 }
James Smart92d7f7b2007-06-17 19:56:38 -05006783}
6784
James Smarte59058c2008-08-24 21:49:00 -04006785/**
James Smart3621a712009-04-06 18:47:14 -04006786 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006787 * @phba: pointer to lpfc hba data structure.
6788 * @pmb: pointer to the driver internal queue element for mailbox command.
6789 *
6790 * This routine is the completion callback function to register new vport
6791 * mailbox command. If the new vport mailbox command completes successfully,
6792 * the fabric registration login shall be performed on physical port (the
6793 * new vport created is actually a physical port, with VPI 0) or the port
6794 * login to Name Server for State Change Request (SCR) will be performed
6795 * on virtual port (real virtual port, with VPI greater than 0).
6796 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006797static void
6798lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6799{
6800 struct lpfc_vport *vport = pmb->vport;
6801 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6802 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006803 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006804 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006805
James Smart09372822008-01-11 01:52:54 -05006806 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006807 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006808 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006809
6810 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006811 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006812 "0915 Register VPI failed : Status: x%x"
6813 " upd bit: x%x \n", mb->mbxStatus,
6814 mb->un.varRegVpi.upd);
6815 if (phba->sli_rev == LPFC_SLI_REV4 &&
6816 mb->un.varRegVpi.upd)
6817 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006818
6819 switch (mb->mbxStatus) {
6820 case 0x11: /* unsupported feature */
6821 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006822 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006823 /* giving up on vport registration */
6824 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6825 spin_lock_irq(shost->host_lock);
6826 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6827 spin_unlock_irq(shost->host_lock);
6828 lpfc_can_disctmo(vport);
6829 break;
James Smart695a8142010-01-26 23:08:03 -05006830 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6831 case 0x20:
6832 spin_lock_irq(shost->host_lock);
6833 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6834 spin_unlock_irq(shost->host_lock);
6835 lpfc_init_vpi(phba, pmb, vport->vpi);
6836 pmb->vport = vport;
6837 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6838 rc = lpfc_sli_issue_mbox(phba, pmb,
6839 MBX_NOWAIT);
6840 if (rc == MBX_NOT_FINISHED) {
6841 lpfc_printf_vlog(vport,
6842 KERN_ERR, LOG_MBOX,
6843 "2732 Failed to issue INIT_VPI"
6844 " mailbox command\n");
6845 } else {
6846 lpfc_nlp_put(ndlp);
6847 return;
6848 }
6849
James Smart92d7f7b2007-06-17 19:56:38 -05006850 default:
6851 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04006852 if (phba->sli_rev == LPFC_SLI_REV4)
6853 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006854 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006855 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006856 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006857 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006858 if (vport->port_type == LPFC_PHYSICAL_PORT
6859 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05006860 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05006861 else
6862 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006863 break;
6864 }
James Smart92d7f7b2007-06-17 19:56:38 -05006865 } else {
James Smart695a8142010-01-26 23:08:03 -05006866 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006867 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006868 spin_unlock_irq(shost->host_lock);
6869 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006870 if (phba->sli_rev < LPFC_SLI_REV4)
6871 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006872 else {
James Smartfc2b9892010-02-26 14:15:29 -05006873 /*
6874 * If the physical port is instantiated using
6875 * FDISC, do not start vport discovery.
6876 */
6877 if (vport->port_state != LPFC_FDISC)
6878 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006879 lpfc_do_scr_ns_plogi(phba, vport);
6880 }
6881 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006882 lpfc_do_scr_ns_plogi(phba, vport);
6883 }
James Smart38b92ef2010-08-04 16:11:39 -04006884mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05006885 /* Now, we decrement the ndlp reference count held for this
6886 * callback function
6887 */
6888 lpfc_nlp_put(ndlp);
6889
James Smart92d7f7b2007-06-17 19:56:38 -05006890 mempool_free(pmb, phba->mbox_mem_pool);
6891 return;
6892}
6893
James Smarte59058c2008-08-24 21:49:00 -04006894/**
James Smart3621a712009-04-06 18:47:14 -04006895 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006896 * @phba: pointer to lpfc hba data structure.
6897 * @vport: pointer to a host virtual N_Port data structure.
6898 * @ndlp: pointer to a node-list data structure.
6899 *
6900 * This routine registers the @vport as a new virtual port with a HBA.
6901 * It is done through a registering vpi mailbox command.
6902 **/
James Smart695a8142010-01-26 23:08:03 -05006903void
James Smart92d7f7b2007-06-17 19:56:38 -05006904lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6905 struct lpfc_nodelist *ndlp)
6906{
James Smart09372822008-01-11 01:52:54 -05006907 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006908 LPFC_MBOXQ_t *mbox;
6909
6910 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6911 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006912 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006913 mbox->vport = vport;
6914 mbox->context2 = lpfc_nlp_get(ndlp);
6915 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006916 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006917 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006918 /* mailbox command not success, decrement ndlp
6919 * reference count for this command
6920 */
6921 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006922 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006923
James Smarte8b62012007-08-02 11:10:09 -04006924 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6925 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006926 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006927 }
6928 } else {
James Smarte8b62012007-08-02 11:10:09 -04006929 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6930 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006931 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006932 }
James Smartfa4066b2008-01-11 01:53:27 -05006933 return;
6934
6935mbox_err_exit:
6936 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6937 spin_lock_irq(shost->host_lock);
6938 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6939 spin_unlock_irq(shost->host_lock);
6940 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006941}
6942
James Smarte59058c2008-08-24 21:49:00 -04006943/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006944 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006945 * @phba: pointer to lpfc hba data structure.
6946 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006947 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006948 **/
6949void
James Smart0c9ab6f2010-02-26 14:15:57 -05006950lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006951{
6952 struct lpfc_vport **vports;
6953 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006954 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006955 int i;
James Smart695a8142010-01-26 23:08:03 -05006956
6957 /* Treat this failure as linkdown for all vports */
6958 link_state = phba->link_state;
6959 lpfc_linkdown(phba);
6960 phba->link_state = link_state;
6961
6962 vports = lpfc_create_vport_work_array(phba);
6963
6964 if (vports) {
6965 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6966 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6967 if (ndlp)
6968 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6969 lpfc_els_flush_cmd(vports[i]);
6970 }
6971 lpfc_destroy_vport_work_array(phba, vports);
6972 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006973}
6974
6975/**
6976 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6977 * @phba: pointer to lpfc hba data structure.
6978 *
6979 * This routine abort all pending discovery commands and
6980 * start a timer to retry FLOGI for the physical port
6981 * discovery.
6982 **/
6983void
6984lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6985{
6986 struct lpfc_nodelist *ndlp;
6987 struct Scsi_Host *shost;
6988
6989 /* Cancel the all vports retry delay retry timers */
6990 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05006991
6992 /* If fabric require FLOGI, then re-instantiate physical login */
6993 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6994 if (!ndlp)
6995 return;
6996
James Smart695a8142010-01-26 23:08:03 -05006997 shost = lpfc_shost_from_vport(phba->pport);
6998 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6999 spin_lock_irq(shost->host_lock);
7000 ndlp->nlp_flag |= NLP_DELAY_TMO;
7001 spin_unlock_irq(shost->host_lock);
7002 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7003 phba->pport->port_state = LPFC_FLOGI;
7004 return;
7005}
7006
7007/**
7008 * lpfc_fabric_login_reqd - Check if FLOGI required.
7009 * @phba: pointer to lpfc hba data structure.
7010 * @cmdiocb: pointer to FDISC command iocb.
7011 * @rspiocb: pointer to FDISC response iocb.
7012 *
7013 * This routine checks if a FLOGI is reguired for FDISC
7014 * to succeed.
7015 **/
7016static int
7017lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7018 struct lpfc_iocbq *cmdiocb,
7019 struct lpfc_iocbq *rspiocb)
7020{
7021
7022 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7023 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7024 return 0;
7025 else
7026 return 1;
7027}
7028
7029/**
James Smart3621a712009-04-06 18:47:14 -04007030 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007031 * @phba: pointer to lpfc hba data structure.
7032 * @cmdiocb: pointer to lpfc command iocb data structure.
7033 * @rspiocb: pointer to lpfc response iocb data structure.
7034 *
7035 * This routine is the completion callback function to a Fabric Discover
7036 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7037 * single threaded, each FDISC completion callback function will reset
7038 * the discovery timer for all vports such that the timers will not get
7039 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7040 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7041 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7042 * assigned to the vport has been changed with the completion of the FDISC
7043 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7044 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7045 * routine is invoked to register new vport with the HBA. Otherwise, the
7046 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7047 * Server for State Change Request (SCR).
7048 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007049static void
7050lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7051 struct lpfc_iocbq *rspiocb)
7052{
7053 struct lpfc_vport *vport = cmdiocb->vport;
7054 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7055 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7056 struct lpfc_nodelist *np;
7057 struct lpfc_nodelist *next_np;
7058 IOCB_t *irsp = &rspiocb->iocb;
7059 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05007060 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7061 struct serv_parm *sp;
7062 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05007063
James Smarte8b62012007-08-02 11:10:09 -04007064 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7065 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7066 irsp->ulpStatus, irsp->un.ulpWord[4],
7067 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05007068 /* Since all FDISCs are being single threaded, we
7069 * must reset the discovery timer for ALL vports
7070 * waiting to send FDISC when one completes.
7071 */
7072 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7073 lpfc_set_disctmo(piocb->vport);
7074 }
7075
James Smart858c9f62007-06-17 19:56:39 -05007076 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7077 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7078 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7079
James Smart92d7f7b2007-06-17 19:56:38 -05007080 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05007081
7082 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7083 lpfc_retry_pport_discovery(phba);
7084 goto out;
7085 }
7086
James Smart92d7f7b2007-06-17 19:56:38 -05007087 /* Check for retry */
7088 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7089 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007090 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04007091 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04007092 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04007093 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04007094 goto fdisc_failed;
7095 }
James Smartd7c255b2008-08-24 21:50:00 -04007096 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05007097 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04007098 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04007099 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05007100 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04007101 vport->fc_flag |= FC_PUBLIC_LOOP;
7102 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007103
James Smartd7c255b2008-08-24 21:50:00 -04007104 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7105 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05007106 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7107 sp = prsp->virt + sizeof(uint32_t);
7108 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7109 memcpy(&vport->fabric_portname, &sp->portName,
7110 sizeof(struct lpfc_name));
7111 memcpy(&vport->fabric_nodename, &sp->nodeName,
7112 sizeof(struct lpfc_name));
7113 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04007114 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7115 /* If our NportID changed, we need to ensure all
7116 * remaining NPORTs get unreg_login'ed so we can
7117 * issue unreg_vpi.
7118 */
7119 list_for_each_entry_safe(np, next_np,
7120 &vport->fc_nodes, nlp_listp) {
7121 if (!NLP_CHK_NODE_ACT(ndlp) ||
7122 (np->nlp_state != NLP_STE_NPR_NODE) ||
7123 !(np->nlp_flag & NLP_NPR_ADISC))
7124 continue;
James Smart09372822008-01-11 01:52:54 -05007125 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007126 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007127 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007128 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007129 }
James Smart78730cf2010-04-06 15:06:30 -04007130 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007131
7132 if (phba->sli_rev == LPFC_SLI_REV4)
7133 lpfc_sli4_unreg_all_rpis(vport);
7134
James Smartd7c255b2008-08-24 21:50:00 -04007135 lpfc_mbx_unreg_vpi(vport);
7136 spin_lock_irq(shost->host_lock);
7137 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007138 if (phba->sli_rev == LPFC_SLI_REV4)
7139 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007140 else
7141 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007142 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007143 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7144 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7145 /*
7146 * Driver needs to re-reg VPI in order for f/w
7147 * to update the MAC address.
7148 */
7149 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007150 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007151 }
7152
James Smartecfd03c2010-02-12 14:41:27 -05007153 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7154 lpfc_issue_init_vpi(vport);
7155 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007156 lpfc_register_new_vport(phba, vport, ndlp);
7157 else
7158 lpfc_do_scr_ns_plogi(phba, vport);
7159 goto out;
7160fdisc_failed:
7161 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7162 /* Cancel discovery timer */
7163 lpfc_can_disctmo(vport);
7164 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007165out:
7166 lpfc_els_free_iocb(phba, cmdiocb);
7167}
7168
James Smarte59058c2008-08-24 21:49:00 -04007169/**
James Smart3621a712009-04-06 18:47:14 -04007170 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007171 * @vport: pointer to a virtual N_Port data structure.
7172 * @ndlp: pointer to a node-list data structure.
7173 * @retry: number of retries to the command IOCB.
7174 *
7175 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7176 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7177 * routine to issue the IOCB, which makes sure only one outstanding fabric
7178 * IOCB will be sent off HBA at any given time.
7179 *
7180 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7181 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7182 * will be stored into the context1 field of the IOCB for the completion
7183 * callback function to the FDISC ELS command.
7184 *
7185 * Return code
7186 * 0 - Successfully issued fdisc iocb command
7187 * 1 - Failed to issue fdisc iocb command
7188 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007189static int
James Smart92d7f7b2007-06-17 19:56:38 -05007190lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7191 uint8_t retry)
7192{
7193 struct lpfc_hba *phba = vport->phba;
7194 IOCB_t *icmd;
7195 struct lpfc_iocbq *elsiocb;
7196 struct serv_parm *sp;
7197 uint8_t *pcmd;
7198 uint16_t cmdsize;
7199 int did = ndlp->nlp_DID;
7200 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007201
James Smart5ffc2662009-11-18 15:39:44 -05007202 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05007203 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7204 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7205 ELS_CMD_FDISC);
7206 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007207 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007208 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7209 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007210 return 1;
7211 }
7212
7213 icmd = &elsiocb->iocb;
7214 icmd->un.elsreq64.myID = 0;
7215 icmd->un.elsreq64.fl = 1;
7216
James Smart40426292010-12-15 17:58:10 -05007217 if ((phba->sli_rev == LPFC_SLI_REV4) &&
7218 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
7219 LPFC_SLI_INTF_IF_TYPE_0)) {
James Smartf1126682009-06-10 17:22:44 -04007220 /* FDISC needs to be 1 for WQE VPI */
7221 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
7222 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
7223 /* Set the ulpContext to the vpi */
7224 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
7225 } else {
7226 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
7227 icmd->ulpCt_h = 1;
7228 icmd->ulpCt_l = 0;
7229 }
James Smart92d7f7b2007-06-17 19:56:38 -05007230
7231 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7232 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7233 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7234 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7235 sp = (struct serv_parm *) pcmd;
7236 /* Setup CSPs accordingly for Fabric */
7237 sp->cmn.e_d_tov = 0;
7238 sp->cmn.w2.r_a_tov = 0;
7239 sp->cls1.classValid = 0;
7240 sp->cls2.seqDelivery = 1;
7241 sp->cls3.seqDelivery = 1;
7242
7243 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7244 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7245 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7246 pcmd += sizeof(uint32_t); /* Port Name */
7247 memcpy(pcmd, &vport->fc_portname, 8);
7248 pcmd += sizeof(uint32_t); /* Node Name */
7249 pcmd += sizeof(uint32_t); /* Node Name */
7250 memcpy(pcmd, &vport->fc_nodename, 8);
7251
7252 lpfc_set_disctmo(vport);
7253
7254 phba->fc_stat.elsXmitFDISC++;
7255 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7256
James Smart858c9f62007-06-17 19:56:39 -05007257 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7258 "Issue FDISC: did:x%x",
7259 did, 0, 0);
7260
James Smart92d7f7b2007-06-17 19:56:38 -05007261 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7262 if (rc == IOCB_ERROR) {
7263 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007264 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007265 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7266 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007267 return 1;
7268 }
7269 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007270 return 0;
7271}
7272
James Smarte59058c2008-08-24 21:49:00 -04007273/**
James Smart3621a712009-04-06 18:47:14 -04007274 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007275 * @phba: pointer to lpfc hba data structure.
7276 * @cmdiocb: pointer to lpfc command iocb data structure.
7277 * @rspiocb: pointer to lpfc response iocb data structure.
7278 *
7279 * This routine is the completion callback function to the issuing of a LOGO
7280 * ELS command off a vport. It frees the command IOCB and then decrement the
7281 * reference count held on ndlp for this completion function, indicating that
7282 * the reference to the ndlp is no long needed. Note that the
7283 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7284 * callback function and an additional explicit ndlp reference decrementation
7285 * will trigger the actual release of the ndlp.
7286 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007287static void
7288lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7289 struct lpfc_iocbq *rspiocb)
7290{
7291 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007292 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007293 struct lpfc_nodelist *ndlp;
James Smart9589b062011-04-16 11:03:17 -04007294 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05007295
James Smart9589b062011-04-16 11:03:17 -04007296 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007297 irsp = &rspiocb->iocb;
7298 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7299 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7300 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007301
7302 lpfc_els_free_iocb(phba, cmdiocb);
7303 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007304
7305 /* Trigger the release of the ndlp after logo */
7306 lpfc_nlp_put(ndlp);
James Smart9589b062011-04-16 11:03:17 -04007307
7308 /* NPIV LOGO completes to NPort <nlp_DID> */
7309 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7310 "2928 NPIV LOGO completes to NPort x%x "
7311 "Data: x%x x%x x%x x%x\n",
7312 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
7313 irsp->ulpTimeout, vport->num_disc_nodes);
7314
7315 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
7316 spin_lock_irq(shost->host_lock);
7317 vport->fc_flag &= ~FC_FABRIC;
7318 spin_unlock_irq(shost->host_lock);
7319 }
James Smart92d7f7b2007-06-17 19:56:38 -05007320}
7321
James Smarte59058c2008-08-24 21:49:00 -04007322/**
James Smart3621a712009-04-06 18:47:14 -04007323 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007324 * @vport: pointer to a virtual N_Port data structure.
7325 * @ndlp: pointer to a node-list data structure.
7326 *
7327 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7328 *
7329 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7330 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7331 * will be stored into the context1 field of the IOCB for the completion
7332 * callback function to the LOGO ELS command.
7333 *
7334 * Return codes
7335 * 0 - Successfully issued logo off the @vport
7336 * 1 - Failed to issue logo off the @vport
7337 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007338int
7339lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7340{
7341 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7342 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007343 IOCB_t *icmd;
7344 struct lpfc_iocbq *elsiocb;
7345 uint8_t *pcmd;
7346 uint16_t cmdsize;
7347
7348 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7349 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7350 ELS_CMD_LOGO);
7351 if (!elsiocb)
7352 return 1;
7353
7354 icmd = &elsiocb->iocb;
7355 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7356 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7357 pcmd += sizeof(uint32_t);
7358
7359 /* Fill in LOGO payload */
7360 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7361 pcmd += sizeof(uint32_t);
7362 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7363
James Smart858c9f62007-06-17 19:56:39 -05007364 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7365 "Issue LOGO npiv did:x%x flg:x%x",
7366 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7367
James Smart92d7f7b2007-06-17 19:56:38 -05007368 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7369 spin_lock_irq(shost->host_lock);
7370 ndlp->nlp_flag |= NLP_LOGO_SND;
7371 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007372 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7373 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007374 spin_lock_irq(shost->host_lock);
7375 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7376 spin_unlock_irq(shost->host_lock);
7377 lpfc_els_free_iocb(phba, elsiocb);
7378 return 1;
7379 }
7380 return 0;
7381}
7382
James Smarte59058c2008-08-24 21:49:00 -04007383/**
James Smart3621a712009-04-06 18:47:14 -04007384 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007385 * @ptr: holder for the timer function associated data.
7386 *
7387 * This routine is invoked by the fabric iocb block timer after
7388 * timeout. It posts the fabric iocb block timeout event by setting the
7389 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7390 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7391 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7392 * posted event WORKER_FABRIC_BLOCK_TMO.
7393 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007394void
7395lpfc_fabric_block_timeout(unsigned long ptr)
7396{
7397 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7398 unsigned long iflags;
7399 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007400
James Smart92d7f7b2007-06-17 19:56:38 -05007401 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7402 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7403 if (!tmo_posted)
7404 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7405 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7406
James Smart5e9d9b82008-06-14 22:52:53 -04007407 if (!tmo_posted)
7408 lpfc_worker_wake_up(phba);
7409 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007410}
7411
James Smarte59058c2008-08-24 21:49:00 -04007412/**
James Smart3621a712009-04-06 18:47:14 -04007413 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007414 * @phba: pointer to lpfc hba data structure.
7415 *
7416 * This routine issues one fabric iocb from the driver internal list to
7417 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7418 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7419 * remove one pending fabric iocb from the driver internal list and invokes
7420 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7421 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007422static void
7423lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7424{
7425 struct lpfc_iocbq *iocb;
7426 unsigned long iflags;
7427 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007428 IOCB_t *cmd;
7429
7430repeat:
7431 iocb = NULL;
7432 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007433 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007434 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7435 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7436 list);
7437 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007438 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007439 atomic_inc(&phba->fabric_iocb_count);
7440 }
7441 spin_unlock_irqrestore(&phba->hbalock, iflags);
7442 if (iocb) {
7443 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7444 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7445 iocb->iocb_flag |= LPFC_IO_FABRIC;
7446
James Smart858c9f62007-06-17 19:56:39 -05007447 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7448 "Fabric sched1: ste:x%x",
7449 iocb->vport->port_state, 0, 0);
7450
James Smart3772a992009-05-22 14:50:54 -04007451 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007452
7453 if (ret == IOCB_ERROR) {
7454 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7455 iocb->fabric_iocb_cmpl = NULL;
7456 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7457 cmd = &iocb->iocb;
7458 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7459 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7460 iocb->iocb_cmpl(phba, iocb, iocb);
7461
7462 atomic_dec(&phba->fabric_iocb_count);
7463 goto repeat;
7464 }
7465 }
7466
7467 return;
7468}
7469
James Smarte59058c2008-08-24 21:49:00 -04007470/**
James Smart3621a712009-04-06 18:47:14 -04007471 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007472 * @phba: pointer to lpfc hba data structure.
7473 *
7474 * This routine unblocks the issuing fabric iocb command. The function
7475 * will clear the fabric iocb block bit and then invoke the routine
7476 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7477 * from the driver internal fabric iocb list.
7478 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007479void
7480lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7481{
7482 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7483
7484 lpfc_resume_fabric_iocbs(phba);
7485 return;
7486}
7487
James Smarte59058c2008-08-24 21:49:00 -04007488/**
James Smart3621a712009-04-06 18:47:14 -04007489 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007490 * @phba: pointer to lpfc hba data structure.
7491 *
7492 * This routine blocks the issuing fabric iocb for a specified amount of
7493 * time (currently 100 ms). This is done by set the fabric iocb block bit
7494 * and set up a timeout timer for 100ms. When the block bit is set, no more
7495 * fabric iocb will be issued out of the HBA.
7496 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007497static void
7498lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7499{
7500 int blocked;
7501
7502 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007503 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007504 if (!blocked)
7505 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7506
7507 return;
7508}
7509
James Smarte59058c2008-08-24 21:49:00 -04007510/**
James Smart3621a712009-04-06 18:47:14 -04007511 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007512 * @phba: pointer to lpfc hba data structure.
7513 * @cmdiocb: pointer to lpfc command iocb data structure.
7514 * @rspiocb: pointer to lpfc response iocb data structure.
7515 *
7516 * This routine is the callback function that is put to the fabric iocb's
7517 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7518 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7519 * function first restores and invokes the original iocb's callback function
7520 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7521 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7522 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007523static void
7524lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7525 struct lpfc_iocbq *rspiocb)
7526{
7527 struct ls_rjt stat;
7528
7529 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7530 BUG();
7531
7532 switch (rspiocb->iocb.ulpStatus) {
7533 case IOSTAT_NPORT_RJT:
7534 case IOSTAT_FABRIC_RJT:
7535 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7536 lpfc_block_fabric_iocbs(phba);
7537 }
7538 break;
7539
7540 case IOSTAT_NPORT_BSY:
7541 case IOSTAT_FABRIC_BSY:
7542 lpfc_block_fabric_iocbs(phba);
7543 break;
7544
7545 case IOSTAT_LS_RJT:
7546 stat.un.lsRjtError =
7547 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7548 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7549 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7550 lpfc_block_fabric_iocbs(phba);
7551 break;
7552 }
7553
7554 if (atomic_read(&phba->fabric_iocb_count) == 0)
7555 BUG();
7556
7557 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7558 cmdiocb->fabric_iocb_cmpl = NULL;
7559 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7560 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7561
7562 atomic_dec(&phba->fabric_iocb_count);
7563 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007564 /* Post any pending iocbs to HBA */
7565 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007566 }
7567}
7568
James Smarte59058c2008-08-24 21:49:00 -04007569/**
James Smart3621a712009-04-06 18:47:14 -04007570 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007571 * @phba: pointer to lpfc hba data structure.
7572 * @iocb: pointer to lpfc command iocb data structure.
7573 *
7574 * This routine is used as the top-level API for issuing a fabric iocb command
7575 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7576 * function makes sure that only one fabric bound iocb will be outstanding at
7577 * any given time. As such, this function will first check to see whether there
7578 * is already an outstanding fabric iocb on the wire. If so, it will put the
7579 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7580 * issued later. Otherwise, it will issue the iocb on the wire and update the
7581 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7582 *
7583 * Note, this implementation has a potential sending out fabric IOCBs out of
7584 * order. The problem is caused by the construction of the "ready" boolen does
7585 * not include the condition that the internal fabric IOCB list is empty. As
7586 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7587 * ahead of the fabric IOCBs in the internal list.
7588 *
7589 * Return code
7590 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7591 * IOCB_ERROR - failed to issue fabric iocb
7592 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007593static int
James Smart92d7f7b2007-06-17 19:56:38 -05007594lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7595{
7596 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007597 int ready;
7598 int ret;
7599
7600 if (atomic_read(&phba->fabric_iocb_count) > 1)
7601 BUG();
7602
7603 spin_lock_irqsave(&phba->hbalock, iflags);
7604 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7605 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7606
James Smart7f5f3d02008-02-08 18:50:14 -05007607 if (ready)
7608 /* Increment fabric iocb count to hold the position */
7609 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007610 spin_unlock_irqrestore(&phba->hbalock, iflags);
7611 if (ready) {
7612 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7613 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7614 iocb->iocb_flag |= LPFC_IO_FABRIC;
7615
James Smart858c9f62007-06-17 19:56:39 -05007616 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7617 "Fabric sched2: ste:x%x",
7618 iocb->vport->port_state, 0, 0);
7619
James Smart3772a992009-05-22 14:50:54 -04007620 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007621
7622 if (ret == IOCB_ERROR) {
7623 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7624 iocb->fabric_iocb_cmpl = NULL;
7625 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7626 atomic_dec(&phba->fabric_iocb_count);
7627 }
7628 } else {
7629 spin_lock_irqsave(&phba->hbalock, iflags);
7630 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7631 spin_unlock_irqrestore(&phba->hbalock, iflags);
7632 ret = IOCB_SUCCESS;
7633 }
7634 return ret;
7635}
7636
James Smarte59058c2008-08-24 21:49:00 -04007637/**
James Smart3621a712009-04-06 18:47:14 -04007638 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007639 * @vport: pointer to a virtual N_Port data structure.
7640 *
7641 * This routine aborts all the IOCBs associated with a @vport from the
7642 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7643 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7644 * list, removes each IOCB associated with the @vport off the list, set the
7645 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7646 * associated with the IOCB.
7647 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007648static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007649{
7650 LIST_HEAD(completions);
7651 struct lpfc_hba *phba = vport->phba;
7652 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007653
7654 spin_lock_irq(&phba->hbalock);
7655 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7656 list) {
7657
7658 if (piocb->vport != vport)
7659 continue;
7660
7661 list_move_tail(&piocb->list, &completions);
7662 }
7663 spin_unlock_irq(&phba->hbalock);
7664
James Smarta257bf92009-04-06 18:48:10 -04007665 /* Cancel all the IOCBs from the completions list */
7666 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7667 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007668}
7669
James Smarte59058c2008-08-24 21:49:00 -04007670/**
James Smart3621a712009-04-06 18:47:14 -04007671 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007672 * @ndlp: pointer to a node-list data structure.
7673 *
7674 * This routine aborts all the IOCBs associated with an @ndlp from the
7675 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7676 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7677 * list, removes each IOCB associated with the @ndlp off the list, set the
7678 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7679 * associated with the IOCB.
7680 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007681void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7682{
7683 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007684 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007685 struct lpfc_iocbq *tmp_iocb, *piocb;
7686 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007687
7688 spin_lock_irq(&phba->hbalock);
7689 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7690 list) {
7691 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7692
7693 list_move_tail(&piocb->list, &completions);
7694 }
7695 }
7696 spin_unlock_irq(&phba->hbalock);
7697
James Smarta257bf92009-04-06 18:48:10 -04007698 /* Cancel all the IOCBs from the completions list */
7699 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7700 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007701}
7702
James Smarte59058c2008-08-24 21:49:00 -04007703/**
James Smart3621a712009-04-06 18:47:14 -04007704 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007705 * @phba: pointer to lpfc hba data structure.
7706 *
7707 * This routine aborts all the IOCBs currently on the driver internal
7708 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7709 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7710 * list, removes IOCBs off the list, set the status feild to
7711 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7712 * the IOCB.
7713 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007714void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7715{
7716 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007717
7718 spin_lock_irq(&phba->hbalock);
7719 list_splice_init(&phba->fabric_iocb_list, &completions);
7720 spin_unlock_irq(&phba->hbalock);
7721
James Smarta257bf92009-04-06 18:48:10 -04007722 /* Cancel all the IOCBs from the completions list */
7723 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7724 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007725}
James Smart6fb120a2009-05-22 14:52:59 -04007726
7727/**
James Smart1151e3e2011-02-16 12:39:35 -05007728 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7729 * @vport: pointer to lpfc vport data structure.
7730 *
7731 * This routine is invoked by the vport cleanup for deletions and the cleanup
7732 * for an ndlp on removal.
7733 **/
7734void
7735lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
7736{
7737 struct lpfc_hba *phba = vport->phba;
7738 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7739 unsigned long iflag = 0;
7740
7741 spin_lock_irqsave(&phba->hbalock, iflag);
7742 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7743 list_for_each_entry_safe(sglq_entry, sglq_next,
7744 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7745 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
7746 sglq_entry->ndlp = NULL;
7747 }
7748 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7749 spin_unlock_irqrestore(&phba->hbalock, iflag);
7750 return;
7751}
7752
7753/**
James Smart6fb120a2009-05-22 14:52:59 -04007754 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7755 * @phba: pointer to lpfc hba data structure.
7756 * @axri: pointer to the els xri abort wcqe structure.
7757 *
7758 * This routine is invoked by the worker thread to process a SLI4 slow-path
7759 * ELS aborted xri.
7760 **/
7761void
7762lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7763 struct sli4_wcqe_xri_aborted *axri)
7764{
7765 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05007766 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
7767
James Smart6fb120a2009-05-22 14:52:59 -04007768 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7769 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05007770 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04007771 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007772
James Smart0f65ff62010-02-26 14:14:23 -05007773 spin_lock_irqsave(&phba->hbalock, iflag);
7774 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007775 list_for_each_entry_safe(sglq_entry, sglq_next,
7776 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7777 if (sglq_entry->sli4_xritag == xri) {
7778 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05007779 ndlp = sglq_entry->ndlp;
7780 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04007781 list_add_tail(&sglq_entry->list,
7782 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007783 sglq_entry->state = SGL_FREED;
7784 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007785 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart19ca7602010-11-20 23:11:55 -05007786 lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04007787
7788 /* Check if TXQ queue needs to be serviced */
7789 if (pring->txq_cnt)
7790 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007791 return;
7792 }
7793 }
James Smart0f65ff62010-02-26 14:14:23 -05007794 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7795 sglq_entry = __lpfc_get_active_sglq(phba, xri);
7796 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7797 spin_unlock_irqrestore(&phba->hbalock, iflag);
7798 return;
7799 }
7800 sglq_entry->state = SGL_XRI_ABORTED;
7801 spin_unlock_irqrestore(&phba->hbalock, iflag);
7802 return;
James Smart6fb120a2009-05-22 14:52:59 -04007803}