blob: 3c624a5494afde79b3185c44cb6e29adbc7d2a98 [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 Smartd4379ac2012-03-01 22:37:07 -05004 * Copyright (C) 2004-2012 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
dea31012005-04-17 16:05:31 -0500233 if (expectRsp) {
James Smart939723a2012-05-09 21:19:03 -0400234 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
235 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
236 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart92d7f7b2007-06-17 19:56:38 -0500237 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
James Smart939723a2012-05-09 21:19:03 -0400238
239 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500240 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400241 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500242 } else {
James Smart939723a2012-05-09 21:19:03 -0400243 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
244 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
245 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
246 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
247 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500248 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
249 }
dea31012005-04-17 16:05:31 -0500250 icmd->ulpBdeCount = 1;
251 icmd->ulpLe = 1;
252 icmd->ulpClass = CLASS3;
253
James Smart939723a2012-05-09 21:19:03 -0400254 /*
255 * If we have NPIV enabled, we want to send ELS traffic by VPI.
256 * For SLI4, since the driver controls VPIs we also want to include
257 * all ELS pt2pt protocol traffic as well.
258 */
259 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
260 ((phba->sli_rev == LPFC_SLI_REV4) &&
261 (vport->fc_flag & FC_PT2PT))) {
James Smart92d7f7b2007-06-17 19:56:38 -0500262
James Smart939723a2012-05-09 21:19:03 -0400263 if (expectRsp) {
264 icmd->un.elsreq64.myID = vport->fc_myDID;
265
266 /* For ELS_REQUEST64_CR, use the VPI by default */
267 icmd->ulpContext = phba->vpi_ids[vport->vpi];
268 }
269
James Smart92d7f7b2007-06-17 19:56:38 -0500270 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500271 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
272 if (elscmd == ELS_CMD_ECHO)
273 icmd->ulpCt_l = 0; /* context = invalid RPI */
274 else
275 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500276 }
277
dea31012005-04-17 16:05:31 -0500278 bpl = (struct ulp_bde64 *) pbuflist->virt;
279 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
280 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
281 bpl->tus.f.bdeSize = cmdSize;
282 bpl->tus.f.bdeFlags = 0;
283 bpl->tus.w = le32_to_cpu(bpl->tus.w);
284
285 if (expectRsp) {
286 bpl++;
287 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
288 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
289 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400290 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500291 bpl->tus.w = le32_to_cpu(bpl->tus.w);
292 }
293
James Smartfa4066b2008-01-11 01:53:27 -0500294 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400295 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500296 if (!elsiocb->context1)
297 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400298 elsiocb->context2 = pcmd;
299 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500300 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500301 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500302 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
303
304 if (prsp) {
305 list_add(&prsp->list, &pcmd->list);
306 }
dea31012005-04-17 16:05:31 -0500307 if (expectRsp) {
308 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400309 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
310 "0116 Xmit ELS command x%x to remote "
311 "NPORT x%x I/O tag: x%x, port state: x%x\n",
312 elscmd, did, elsiocb->iotag,
313 vport->port_state);
dea31012005-04-17 16:05:31 -0500314 } else {
315 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400316 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
317 "0117 Xmit ELS response x%x to remote "
318 "NPORT x%x I/O tag: x%x, size: x%x\n",
319 elscmd, ndlp->nlp_DID, elsiocb->iotag,
320 cmdSize);
dea31012005-04-17 16:05:31 -0500321 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500322 return elsiocb;
dea31012005-04-17 16:05:31 -0500323
James Smartfa4066b2008-01-11 01:53:27 -0500324els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500325 if (expectRsp)
326 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500327 kfree(pbuflist);
328
329els_iocb_free_prsp_exit:
330 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
331 kfree(prsp);
332
333els_iocb_free_pcmb_exit:
334 kfree(pcmd);
335 lpfc_sli_release_iocbq(phba, elsiocb);
336 return NULL;
337}
dea31012005-04-17 16:05:31 -0500338
James Smarte59058c2008-08-24 21:49:00 -0400339/**
James Smart3621a712009-04-06 18:47:14 -0400340 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400341 * @vport: pointer to a host virtual N_Port data structure.
342 *
343 * This routine issues a fabric registration login for a @vport. An
344 * active ndlp node with Fabric_DID must already exist for this @vport.
345 * The routine invokes two mailbox commands to carry out fabric registration
346 * login through the HBA firmware: the first mailbox command requests the
347 * HBA to perform link configuration for the @vport; and the second mailbox
348 * command requests the HBA to perform the actual fabric registration login
349 * with the @vport.
350 *
351 * Return code
352 * 0 - successfully issued fabric registration login for @vport
353 * -ENXIO -- failed to issue fabric registration login for @vport
354 **/
James Smart3772a992009-05-22 14:50:54 -0400355int
James Smart92d7f7b2007-06-17 19:56:38 -0500356lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
357{
358 struct lpfc_hba *phba = vport->phba;
359 LPFC_MBOXQ_t *mbox;
360 struct lpfc_dmabuf *mp;
361 struct lpfc_nodelist *ndlp;
362 struct serv_parm *sp;
363 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400364 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500365
366 sp = &phba->fc_fabparam;
367 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500368 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400369 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500370 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400371 }
James Smart92d7f7b2007-06-17 19:56:38 -0500372
373 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400374 if (!mbox) {
375 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500376 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400377 }
James Smart92d7f7b2007-06-17 19:56:38 -0500378
379 vport->port_state = LPFC_FABRIC_CFG_LINK;
380 lpfc_config_link(phba, mbox);
381 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
382 mbox->vport = vport;
383
James Smart0b727fe2007-10-27 13:37:25 -0400384 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400385 if (rc == MBX_NOT_FINISHED) {
386 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500387 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400388 }
James Smart92d7f7b2007-06-17 19:56:38 -0500389
390 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400391 if (!mbox) {
392 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500393 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400394 }
James Smart40426292010-12-15 17:58:10 -0500395 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
396 ndlp->nlp_rpi);
James Smart98c9ea52007-10-27 13:37:33 -0400397 if (rc) {
398 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500399 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400400 }
James Smart92d7f7b2007-06-17 19:56:38 -0500401
402 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
403 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500404 /* increment the reference count on ndlp to hold reference
405 * for the callback routine.
406 */
James Smart92d7f7b2007-06-17 19:56:38 -0500407 mbox->context2 = lpfc_nlp_get(ndlp);
408
James Smart0b727fe2007-10-27 13:37:25 -0400409 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400410 if (rc == MBX_NOT_FINISHED) {
411 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500412 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400413 }
James Smart92d7f7b2007-06-17 19:56:38 -0500414
415 return 0;
416
417fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500418 /* decrement the reference count on ndlp just incremented
419 * for the failed mbox command.
420 */
James Smart92d7f7b2007-06-17 19:56:38 -0500421 lpfc_nlp_put(ndlp);
422 mp = (struct lpfc_dmabuf *) mbox->context1;
423 lpfc_mbuf_free(phba, mp->virt, mp->phys);
424 kfree(mp);
425fail_free_mbox:
426 mempool_free(mbox, phba->mbox_mem_pool);
427
428fail:
429 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400430 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400431 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500432 return -ENXIO;
433}
434
James Smarte59058c2008-08-24 21:49:00 -0400435/**
James Smart6fb120a2009-05-22 14:52:59 -0400436 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
437 * @vport: pointer to a host virtual N_Port data structure.
438 *
439 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
James Smart1b511972011-12-13 13:23:09 -0500440 * the @vport. This mailbox command is necessary for SLI4 port only.
James Smart6fb120a2009-05-22 14:52:59 -0400441 *
442 * Return code
443 * 0 - successfully issued REG_VFI for @vport
444 * A failure code otherwise.
445 **/
James Smart1b511972011-12-13 13:23:09 -0500446int
James Smart6fb120a2009-05-22 14:52:59 -0400447lpfc_issue_reg_vfi(struct lpfc_vport *vport)
448{
449 struct lpfc_hba *phba = vport->phba;
450 LPFC_MBOXQ_t *mboxq;
451 struct lpfc_nodelist *ndlp;
452 struct serv_parm *sp;
453 struct lpfc_dmabuf *dmabuf;
454 int rc = 0;
455
456 sp = &phba->fc_fabparam;
James Smart939723a2012-05-09 21:19:03 -0400457 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
James Smart1b511972011-12-13 13:23:09 -0500458 if ((phba->sli_rev == LPFC_SLI_REV4) &&
James Smart939723a2012-05-09 21:19:03 -0400459 !(phba->link_flag & LS_LOOPBACK_MODE) &&
460 !(vport->fc_flag & FC_PT2PT)) {
James Smart1b511972011-12-13 13:23:09 -0500461 ndlp = lpfc_findnode_did(vport, Fabric_DID);
462 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
463 rc = -ENODEV;
464 goto fail;
465 }
James Smart6fb120a2009-05-22 14:52:59 -0400466 }
467
468 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
469 if (!dmabuf) {
470 rc = -ENOMEM;
471 goto fail;
472 }
473 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
474 if (!dmabuf->virt) {
475 rc = -ENOMEM;
476 goto fail_free_dmabuf;
477 }
James Smart6d368e52011-05-24 11:44:12 -0400478
James Smart6fb120a2009-05-22 14:52:59 -0400479 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
480 if (!mboxq) {
481 rc = -ENOMEM;
482 goto fail_free_coherent;
483 }
484 vport->port_state = LPFC_FABRIC_CFG_LINK;
485 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
486 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
487 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
488 mboxq->vport = vport;
489 mboxq->context1 = dmabuf;
490 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
491 if (rc == MBX_NOT_FINISHED) {
492 rc = -ENXIO;
493 goto fail_free_mbox;
494 }
495 return 0;
496
497fail_free_mbox:
498 mempool_free(mboxq, phba->mbox_mem_pool);
499fail_free_coherent:
500 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
501fail_free_dmabuf:
502 kfree(dmabuf);
503fail:
504 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
505 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
506 "0289 Issue Register VFI failed: Err %d\n", rc);
507 return rc;
508}
509
510/**
James Smart1b511972011-12-13 13:23:09 -0500511 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
512 * @vport: pointer to a host virtual N_Port data structure.
513 *
514 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
515 * the @vport. This mailbox command is necessary for SLI4 port only.
516 *
517 * Return code
518 * 0 - successfully issued REG_VFI for @vport
519 * A failure code otherwise.
520 **/
521int
522lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
523{
524 struct lpfc_hba *phba = vport->phba;
525 struct Scsi_Host *shost;
526 LPFC_MBOXQ_t *mboxq;
527 int rc;
528
529 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
530 if (!mboxq) {
531 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
532 "2556 UNREG_VFI mbox allocation failed"
533 "HBA state x%x\n", phba->pport->port_state);
534 return -ENOMEM;
535 }
536
537 lpfc_unreg_vfi(mboxq, vport);
538 mboxq->vport = vport;
539 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
540
541 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
542 if (rc == MBX_NOT_FINISHED) {
543 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
544 "2557 UNREG_VFI issue mbox failed rc x%x "
545 "HBA state x%x\n",
546 rc, phba->pport->port_state);
547 mempool_free(mboxq, phba->mbox_mem_pool);
548 return -EIO;
549 }
550
551 shost = lpfc_shost_from_vport(vport);
552 spin_lock_irq(shost->host_lock);
553 vport->fc_flag &= ~FC_VFI_REGISTERED;
554 spin_unlock_irq(shost->host_lock);
555 return 0;
556}
557
558/**
James Smart92494142011-02-16 12:39:44 -0500559 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
560 * @vport: pointer to a host virtual N_Port data structure.
561 * @sp: pointer to service parameter data structure.
562 *
563 * This routine is called from FLOGI/FDISC completion handler functions.
564 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
565 * node nodename is changed in the completion service parameter else return
566 * 0. This function also set flag in the vport data structure to delay
567 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
568 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
569 * node nodename is changed in the completion service parameter.
570 *
571 * Return code
572 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
573 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
574 *
575 **/
576static uint8_t
577lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
578 struct serv_parm *sp)
579{
580 uint8_t fabric_param_changed = 0;
581 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
582
583 if ((vport->fc_prevDID != vport->fc_myDID) ||
584 memcmp(&vport->fabric_portname, &sp->portName,
585 sizeof(struct lpfc_name)) ||
586 memcmp(&vport->fabric_nodename, &sp->nodeName,
587 sizeof(struct lpfc_name)))
588 fabric_param_changed = 1;
589
590 /*
591 * Word 1 Bit 31 in common service parameter is overloaded.
592 * Word 1 Bit 31 in FLOGI request is multiple NPort request
593 * Word 1 Bit 31 in FLOGI response is clean address bit
594 *
595 * If fabric parameter is changed and clean address bit is
596 * cleared delay nport discovery if
597 * - vport->fc_prevDID != 0 (not initial discovery) OR
598 * - lpfc_delay_discovery module parameter is set.
599 */
600 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
601 (vport->fc_prevDID || lpfc_delay_discovery)) {
602 spin_lock_irq(shost->host_lock);
603 vport->fc_flag |= FC_DISC_DELAYED;
604 spin_unlock_irq(shost->host_lock);
605 }
606
607 return fabric_param_changed;
608}
609
610
611/**
James Smart3621a712009-04-06 18:47:14 -0400612 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400613 * @vport: pointer to a host virtual N_Port data structure.
614 * @ndlp: pointer to a node-list data structure.
615 * @sp: pointer to service parameter data structure.
616 * @irsp: pointer to the IOCB within the lpfc response IOCB.
617 *
618 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
619 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
620 * port in a fabric topology. It properly sets up the parameters to the @ndlp
621 * from the IOCB response. It also check the newly assigned N_Port ID to the
622 * @vport against the previously assigned N_Port ID. If it is different from
623 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
624 * is invoked on all the remaining nodes with the @vport to unregister the
625 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
626 * is invoked to register login to the fabric.
627 *
628 * Return code
629 * 0 - Success (currently, always return 0)
630 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500631static int
James Smart2e0fef82007-06-17 19:56:36 -0500632lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
633 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500634{
James Smart2e0fef82007-06-17 19:56:36 -0500635 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
636 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500637 struct lpfc_nodelist *np;
638 struct lpfc_nodelist *next_np;
James Smart92494142011-02-16 12:39:44 -0500639 uint8_t fabric_param_changed;
dea31012005-04-17 16:05:31 -0500640
James Smart2e0fef82007-06-17 19:56:36 -0500641 spin_lock_irq(shost->host_lock);
642 vport->fc_flag |= FC_FABRIC;
643 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500644
645 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
646 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
647 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
648
James Smart12265f62010-10-22 11:05:53 -0400649 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500650 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
651
James Smart76a95d72010-11-20 23:11:48 -0500652 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500653 spin_lock_irq(shost->host_lock);
654 vport->fc_flag |= FC_PUBLIC_LOOP;
655 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500656 }
657
James Smart2e0fef82007-06-17 19:56:36 -0500658 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500659 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500660 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500661 ndlp->nlp_class_sup = 0;
662 if (sp->cls1.classValid)
663 ndlp->nlp_class_sup |= FC_COS_CLASS1;
664 if (sp->cls2.classValid)
665 ndlp->nlp_class_sup |= FC_COS_CLASS2;
666 if (sp->cls3.classValid)
667 ndlp->nlp_class_sup |= FC_COS_CLASS3;
668 if (sp->cls4.classValid)
669 ndlp->nlp_class_sup |= FC_COS_CLASS4;
670 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
671 sp->cmn.bbRcvSizeLsb;
James Smart92494142011-02-16 12:39:44 -0500672
673 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
674 memcpy(&vport->fabric_portname, &sp->portName,
675 sizeof(struct lpfc_name));
676 memcpy(&vport->fabric_nodename, &sp->nodeName,
677 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500678 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
679
James Smart92d7f7b2007-06-17 19:56:38 -0500680 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
681 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400682 lpfc_printf_vlog(vport, KERN_WARNING,
683 LOG_ELS | LOG_VPORT,
684 "1816 FLOGI NPIV supported, "
685 "response data 0x%x\n",
686 sp->cmn.response_multiple_NPort);
James Smart1b511972011-12-13 13:23:09 -0500687 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500688 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500689 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500690 } else {
691 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400692 to call reg_vnpid atleast for the physcial host */
693 lpfc_printf_vlog(vport, KERN_WARNING,
694 LOG_ELS | LOG_VPORT,
695 "1817 Fabric does not support NPIV "
696 "- configuring single port mode.\n");
James Smart1b511972011-12-13 13:23:09 -0500697 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500698 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500699 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500700 }
701 }
702
James Smart92494142011-02-16 12:39:44 -0500703 if (fabric_param_changed &&
James Smart92d7f7b2007-06-17 19:56:38 -0500704 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
705
706 /* If our NportID changed, we need to ensure all
707 * remaining NPORTs get unreg_login'ed.
708 */
709 list_for_each_entry_safe(np, next_np,
710 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400711 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500712 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500713 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
714 !(np->nlp_flag & NLP_NPR_ADISC))
715 continue;
716 spin_lock_irq(shost->host_lock);
717 np->nlp_flag &= ~NLP_NPR_ADISC;
718 spin_unlock_irq(shost->host_lock);
719 lpfc_unreg_rpi(vport, np);
720 }
James Smart78730cf2010-04-06 15:06:30 -0400721 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400722
James Smart5248a742011-07-22 18:37:06 -0400723 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart5af5eee2010-10-22 11:06:38 -0400724 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500725 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500726 spin_lock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -0500727 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
728 spin_unlock_irq(shost->host_lock);
729 }
James Smart27aa1b72012-05-09 21:18:49 -0400730
731 /*
732 * For SLI3 and SLI4, the VPI needs to be reregistered in
733 * response to this fabric parameter change event.
734 */
735 spin_lock_irq(shost->host_lock);
736 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
737 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -0400738 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
739 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
740 /*
741 * Driver needs to re-reg VPI in order for f/w
742 * to update the MAC address.
743 */
James Smart9589b062011-04-16 11:03:17 -0400744 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400745 lpfc_register_new_vport(phba, vport, ndlp);
746 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500747 }
748
James Smart6fb120a2009-05-22 14:52:59 -0400749 if (phba->sli_rev < LPFC_SLI_REV4) {
750 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
751 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
752 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
753 lpfc_register_new_vport(phba, vport, ndlp);
754 else
755 lpfc_issue_fabric_reglogin(vport);
756 } else {
757 ndlp->nlp_type |= NLP_FABRIC;
758 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500759 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
760 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400761 lpfc_start_fdiscs(phba);
762 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500763 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500764 lpfc_issue_init_vpi(vport);
James Smart1b511972011-12-13 13:23:09 -0500765 else {
766 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
767 "3135 Need register VFI: (x%x/%x)\n",
768 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -0400769 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -0500770 }
James Smart92d7f7b2007-06-17 19:56:38 -0500771 }
dea31012005-04-17 16:05:31 -0500772 return 0;
dea31012005-04-17 16:05:31 -0500773}
James Smart1b511972011-12-13 13:23:09 -0500774
James Smarte59058c2008-08-24 21:49:00 -0400775/**
James Smart3621a712009-04-06 18:47:14 -0400776 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400777 * @vport: pointer to a host virtual N_Port data structure.
778 * @ndlp: pointer to a node-list data structure.
779 * @sp: pointer to service parameter data structure.
780 *
781 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
782 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
783 * in a point-to-point topology. First, the @vport's N_Port Name is compared
784 * with the received N_Port Name: if the @vport's N_Port Name is greater than
785 * the received N_Port Name lexicographically, this node shall assign local
786 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
787 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
788 * this node shall just wait for the remote node to issue PLOGI and assign
789 * N_Port IDs.
790 *
791 * Return code
792 * 0 - Success
793 * -ENXIO - Fail
794 **/
dea31012005-04-17 16:05:31 -0500795static int
James Smart2e0fef82007-06-17 19:56:36 -0500796lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
797 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500798{
James Smart2e0fef82007-06-17 19:56:36 -0500799 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
800 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500801 LPFC_MBOXQ_t *mbox;
802 int rc;
803
James Smart2e0fef82007-06-17 19:56:36 -0500804 spin_lock_irq(shost->host_lock);
805 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
806 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500807
808 phba->fc_edtov = FF_DEF_EDTOV;
809 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500810 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500811 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500812 if (rc >= 0) {
813 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500814 spin_lock_irq(shost->host_lock);
815 vport->fc_flag |= FC_PT2PT_PLOGI;
816 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500817
818 /*
819 * N_Port ID cannot be 0, set our to LocalID the other
820 * side will be RemoteID.
821 */
822
823 /* not equal */
824 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500825 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500826
827 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
828 if (!mbox)
829 goto fail;
830
831 lpfc_config_link(phba, mbox);
832
833 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500834 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400835 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500836 if (rc == MBX_NOT_FINISHED) {
837 mempool_free(mbox, phba->mbox_mem_pool);
838 goto fail;
839 }
James Smart939723a2012-05-09 21:19:03 -0400840
841 /*
842 * For SLI4, the VFI/VPI are registered AFTER the
843 * Nport with the higher WWPN sends the PLOGI with
844 * an assigned NPortId.
845 */
846
847 /* not equal */
848 if ((phba->sli_rev == LPFC_SLI_REV4) && rc)
849 lpfc_issue_reg_vfi(vport);
850
James Smarte47c9092008-02-08 18:49:26 -0500851 /* Decrement ndlp reference count indicating that ndlp can be
852 * safely released when other references to it are done.
853 */
James Smart329f9bc2007-04-25 09:53:01 -0400854 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500855
James Smart2e0fef82007-06-17 19:56:36 -0500856 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500857 if (!ndlp) {
858 /*
859 * Cannot find existing Fabric ndlp, so allocate a
860 * new one
861 */
862 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
863 if (!ndlp)
864 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500865 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500866 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
867 ndlp = lpfc_enable_node(vport, ndlp,
868 NLP_STE_UNUSED_NODE);
869 if(!ndlp)
870 goto fail;
dea31012005-04-17 16:05:31 -0500871 }
872
873 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500874 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500875 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500876 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500877 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500878 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
879 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500880 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500881 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500882 } else
883 /* This side will wait for the PLOGI, decrement ndlp reference
884 * count indicating that ndlp can be released when other
885 * references to it are done.
886 */
James Smart329f9bc2007-04-25 09:53:01 -0400887 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500888
James Smart09372822008-01-11 01:52:54 -0500889 /* If we are pt2pt with another NPort, force NPIV off! */
890 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
891
James Smart2e0fef82007-06-17 19:56:36 -0500892 spin_lock_irq(shost->host_lock);
893 vport->fc_flag |= FC_PT2PT;
894 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500895
896 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500897 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500898 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500899fail:
dea31012005-04-17 16:05:31 -0500900 return -ENXIO;
901}
902
James Smarte59058c2008-08-24 21:49:00 -0400903/**
James Smart3621a712009-04-06 18:47:14 -0400904 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400905 * @phba: pointer to lpfc hba data structure.
906 * @cmdiocb: pointer to lpfc command iocb data structure.
907 * @rspiocb: pointer to lpfc response iocb data structure.
908 *
909 * This routine is the top-level completion callback function for issuing
910 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
911 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
912 * retry has been made (either immediately or delayed with lpfc_els_retry()
913 * returning 1), the command IOCB will be released and function returned.
914 * If the retry attempt has been given up (possibly reach the maximum
915 * number of retries), one additional decrement of ndlp reference shall be
916 * invoked before going out after releasing the command IOCB. This will
917 * actually release the remote node (Note, lpfc_els_free_iocb() will also
918 * invoke one decrement of ndlp reference count). If no error reported in
919 * the IOCB status, the command Port ID field is used to determine whether
920 * this is a point-to-point topology or a fabric topology: if the Port ID
921 * field is assigned, it is a fabric topology; otherwise, it is a
922 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
923 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
924 * specific topology completion conditions.
925 **/
dea31012005-04-17 16:05:31 -0500926static void
James Smart329f9bc2007-04-25 09:53:01 -0400927lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
928 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500929{
James Smart2e0fef82007-06-17 19:56:36 -0500930 struct lpfc_vport *vport = cmdiocb->vport;
931 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500932 IOCB_t *irsp = &rspiocb->iocb;
933 struct lpfc_nodelist *ndlp = cmdiocb->context1;
934 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
935 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500936 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500937 int rc;
938
939 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500940 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500941 /* One additional decrement on node reference count to
942 * trigger the release of the node
943 */
James Smart329f9bc2007-04-25 09:53:01 -0400944 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500945 goto out;
946 }
947
James Smart858c9f62007-06-17 19:56:39 -0500948 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
949 "FLOGI cmpl: status:x%x/x%x state:x%x",
950 irsp->ulpStatus, irsp->un.ulpWord[4],
951 vport->port_state);
952
dea31012005-04-17 16:05:31 -0500953 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500954 /*
James Smarta93ff372010-10-22 11:06:08 -0400955 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500956 * due to new FCF discovery
957 */
958 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart80c17842012-03-01 22:35:45 -0500959 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
960 if (phba->link_state < LPFC_LINK_UP)
961 goto stop_rr_fcf_flogi;
962 if ((phba->fcoe_cvl_eventtag_attn ==
963 phba->fcoe_cvl_eventtag) &&
964 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
965 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))
966 goto stop_rr_fcf_flogi;
967 else
968 phba->fcoe_cvl_eventtag_attn =
969 phba->fcoe_cvl_eventtag;
James Smart0c9ab6f2010-02-26 14:15:57 -0500970 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400971 "2611 FLOGI failed on FCF (x%x), "
972 "status:x%x/x%x, tmo:x%x, perform "
973 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -0400974 phba->fcf.current_rec.fcf_indx,
975 irsp->ulpStatus, irsp->un.ulpWord[4],
976 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -0400977 lpfc_sli4_set_fcf_flogi_fail(phba,
978 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500979 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -0400980 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
981 if (rc)
982 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500983 }
984
James Smart80c17842012-03-01 22:35:45 -0500985stop_rr_fcf_flogi:
James Smart38b92ef2010-08-04 16:11:39 -0400986 /* FLOGI failure */
987 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
988 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
989 irsp->ulpStatus, irsp->un.ulpWord[4],
990 irsp->ulpTimeout);
991
dea31012005-04-17 16:05:31 -0500992 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500993 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500994 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500995
James Smart76a95d72010-11-20 23:11:48 -0500996 /* FLOGI failure */
997 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
998 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
999 irsp->ulpStatus, irsp->un.ulpWord[4],
1000 irsp->ulpTimeout);
1001
dea31012005-04-17 16:05:31 -05001002 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -05001003 spin_lock_irq(shost->host_lock);
1004 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1005 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001006
James Smart329f9bc2007-04-25 09:53:01 -04001007 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -05001008 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1009 * alpa map would take too long otherwise.
1010 */
James Smart1b511972011-12-13 13:23:09 -05001011 if (phba->alpa_map[0] == 0)
James Smart3de2a652007-08-02 11:09:59 -04001012 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -05001013 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1014 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1015 (vport->fc_prevDID != vport->fc_myDID))) {
1016 if (vport->fc_flag & FC_VFI_REGISTERED)
1017 lpfc_sli4_unreg_all_rpis(vport);
1018 lpfc_issue_reg_vfi(vport);
1019 lpfc_nlp_put(ndlp);
1020 goto out;
dea31012005-04-17 16:05:31 -05001021 }
dea31012005-04-17 16:05:31 -05001022 goto flogifail;
1023 }
James Smart695a8142010-01-26 23:08:03 -05001024 spin_lock_irq(shost->host_lock);
1025 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04001026 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -05001027 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001028
1029 /*
1030 * The FLogI succeeded. Sync the data for the CPU before
1031 * accessing it.
1032 */
1033 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1034
1035 sp = prsp->virt + sizeof(uint32_t);
1036
1037 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -04001038 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001039 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -04001040 "Data: x%x x%x x%x x%x\n",
1041 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1042 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -05001043
James Smart2e0fef82007-06-17 19:56:36 -05001044 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -05001045 /*
1046 * If Common Service Parameters indicate Nport
1047 * we are point to point, if Fport we are Fabric.
1048 */
1049 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -05001050 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -05001051 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001052 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -04001053 else {
1054 lpfc_printf_vlog(vport, KERN_ERR,
1055 LOG_FIP | LOG_ELS,
1056 "2831 FLOGI response with cleared Fabric "
1057 "bit fcf_index 0x%x "
1058 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1059 "Fabric Name "
1060 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1061 phba->fcf.current_rec.fcf_indx,
1062 phba->fcf.current_rec.switch_name[0],
1063 phba->fcf.current_rec.switch_name[1],
1064 phba->fcf.current_rec.switch_name[2],
1065 phba->fcf.current_rec.switch_name[3],
1066 phba->fcf.current_rec.switch_name[4],
1067 phba->fcf.current_rec.switch_name[5],
1068 phba->fcf.current_rec.switch_name[6],
1069 phba->fcf.current_rec.switch_name[7],
1070 phba->fcf.current_rec.fabric_name[0],
1071 phba->fcf.current_rec.fabric_name[1],
1072 phba->fcf.current_rec.fabric_name[2],
1073 phba->fcf.current_rec.fabric_name[3],
1074 phba->fcf.current_rec.fabric_name[4],
1075 phba->fcf.current_rec.fabric_name[5],
1076 phba->fcf.current_rec.fabric_name[6],
1077 phba->fcf.current_rec.fabric_name[7]);
1078 lpfc_nlp_put(ndlp);
1079 spin_lock_irq(&phba->hbalock);
1080 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001081 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -04001082 spin_unlock_irq(&phba->hbalock);
1083 goto out;
1084 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001085 if (!rc) {
1086 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -04001087 if (phba->hba_flag & HBA_FIP_SUPPORT)
1088 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1089 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001090 "2769 FLOGI to FCF (x%x) "
1091 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -04001092 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001093 spin_lock_irq(&phba->hbalock);
1094 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001095 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -05001096 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001097 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001098 }
dea31012005-04-17 16:05:31 -05001099 }
1100
1101flogifail:
James Smart329f9bc2007-04-25 09:53:01 -04001102 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001103
James Smart858c9f62007-06-17 19:56:39 -05001104 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001105 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001106 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001107
1108 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001109 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001110 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1111 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
1112 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
1113 (phba->link_state != LPFC_CLEAR_LA)) {
1114 /* If FLOGI failed enable link interrupt. */
1115 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001116 }
dea31012005-04-17 16:05:31 -05001117out:
1118 lpfc_els_free_iocb(phba, cmdiocb);
1119}
1120
James Smarte59058c2008-08-24 21:49:00 -04001121/**
James Smart3621a712009-04-06 18:47:14 -04001122 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001123 * @vport: pointer to a host virtual N_Port data structure.
1124 * @ndlp: pointer to a node-list data structure.
1125 * @retry: number of retries to the command IOCB.
1126 *
1127 * This routine issues a Fabric Login (FLOGI) Request ELS command
1128 * for a @vport. The initiator service parameters are put into the payload
1129 * of the FLOGI Request IOCB and the top-level callback function pointer
1130 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1131 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1132 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1133 *
1134 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1135 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1136 * will be stored into the context1 field of the IOCB for the completion
1137 * callback function to the FLOGI ELS command.
1138 *
1139 * Return code
1140 * 0 - successfully issued flogi iocb for @vport
1141 * 1 - failed to issue flogi iocb for @vport
1142 **/
dea31012005-04-17 16:05:31 -05001143static int
James Smart2e0fef82007-06-17 19:56:36 -05001144lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001145 uint8_t retry)
1146{
James Smart2e0fef82007-06-17 19:56:36 -05001147 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001148 struct serv_parm *sp;
1149 IOCB_t *icmd;
1150 struct lpfc_iocbq *elsiocb;
1151 struct lpfc_sli_ring *pring;
1152 uint8_t *pcmd;
1153 uint16_t cmdsize;
1154 uint32_t tmo;
1155 int rc;
1156
1157 pring = &phba->sli.ring[LPFC_ELS_RING];
1158
James Smart92d7f7b2007-06-17 19:56:38 -05001159 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001160 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1161 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001162
James Smart488d1462006-03-07 15:02:37 -05001163 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001164 return 1;
dea31012005-04-17 16:05:31 -05001165
1166 icmd = &elsiocb->iocb;
1167 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1168
1169 /* For FLOGI request, remainder of payload is service parameters */
1170 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001171 pcmd += sizeof(uint32_t);
1172 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001173 sp = (struct serv_parm *) pcmd;
1174
1175 /* Setup CSPs accordingly for Fabric */
1176 sp->cmn.e_d_tov = 0;
1177 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001178 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001179 sp->cls1.classValid = 0;
1180 sp->cls2.seqDelivery = 1;
1181 sp->cls3.seqDelivery = 1;
1182 if (sp->cmn.fcphLow < FC_PH3)
1183 sp->cmn.fcphLow = FC_PH3;
1184 if (sp->cmn.fcphHigh < FC_PH3)
1185 sp->cmn.fcphHigh = FC_PH3;
1186
James Smartc31098c2011-04-16 11:03:33 -04001187 if (phba->sli_rev == LPFC_SLI_REV4) {
1188 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1189 LPFC_SLI_INTF_IF_TYPE_0) {
1190 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1191 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1192 /* FLOGI needs to be 3 for WQE FCFI */
1193 /* Set the fcfi to the fcfi we registered with */
1194 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1195 }
James Smart5248a742011-07-22 18:37:06 -04001196 } else {
1197 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1198 sp->cmn.request_multiple_Nport = 1;
1199 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1200 icmd->ulpCt_h = 1;
1201 icmd->ulpCt_l = 0;
1202 } else
1203 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001204 }
1205
James Smart76a95d72010-11-20 23:11:48 -05001206 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001207 icmd->un.elsreq64.myID = 0;
1208 icmd->un.elsreq64.fl = 1;
1209 }
1210
dea31012005-04-17 16:05:31 -05001211 tmo = phba->fc_ratov;
1212 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001213 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001214 phba->fc_ratov = tmo;
1215
1216 phba->fc_stat.elsXmitFLOGI++;
1217 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001218
1219 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1220 "Issue FLOGI: opt:x%x",
1221 phba->sli3_options, 0, 0);
1222
James Smart92d7f7b2007-06-17 19:56:38 -05001223 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001224 if (rc == IOCB_ERROR) {
1225 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001226 return 1;
dea31012005-04-17 16:05:31 -05001227 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001228 return 0;
dea31012005-04-17 16:05:31 -05001229}
1230
James Smarte59058c2008-08-24 21:49:00 -04001231/**
James Smart3621a712009-04-06 18:47:14 -04001232 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001233 * @phba: pointer to lpfc hba data structure.
1234 *
1235 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1236 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1237 * list and issues an abort IOCB commond on each outstanding IOCB that
1238 * contains a active Fabric_DID ndlp. Note that this function is to issue
1239 * the abort IOCB command on all the outstanding IOCBs, thus when this
1240 * function returns, it does not guarantee all the IOCBs are actually aborted.
1241 *
1242 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001243 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001244 **/
dea31012005-04-17 16:05:31 -05001245int
James Smart2e0fef82007-06-17 19:56:36 -05001246lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001247{
1248 struct lpfc_sli_ring *pring;
1249 struct lpfc_iocbq *iocb, *next_iocb;
1250 struct lpfc_nodelist *ndlp;
1251 IOCB_t *icmd;
1252
1253 /* Abort outstanding I/O on NPort <nlp_DID> */
1254 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001255 "0201 Abort outstanding I/O on NPort x%x\n",
1256 Fabric_DID);
dea31012005-04-17 16:05:31 -05001257
1258 pring = &phba->sli.ring[LPFC_ELS_RING];
1259
1260 /*
1261 * Check the txcmplq for an iocb that matches the nport the driver is
1262 * searching for.
1263 */
James Smart2e0fef82007-06-17 19:56:36 -05001264 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001265 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1266 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001267 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001268 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001269 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1270 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001271 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001272 }
1273 }
James Smart2e0fef82007-06-17 19:56:36 -05001274 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001275
1276 return 0;
1277}
1278
James Smarte59058c2008-08-24 21:49:00 -04001279/**
James Smart3621a712009-04-06 18:47:14 -04001280 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001281 * @vport: pointer to a host virtual N_Port data structure.
1282 *
1283 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1284 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1285 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1286 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1287 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1288 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1289 * @vport.
1290 *
1291 * Return code
1292 * 0 - failed to issue initial flogi for @vport
1293 * 1 - successfully issued initial flogi for @vport
1294 **/
dea31012005-04-17 16:05:31 -05001295int
James Smart2e0fef82007-06-17 19:56:36 -05001296lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001297{
James Smart2e0fef82007-06-17 19:56:36 -05001298 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001299 struct lpfc_nodelist *ndlp;
1300
James Smart98c9ea52007-10-27 13:37:33 -04001301 vport->port_state = LPFC_FLOGI;
1302 lpfc_set_disctmo(vport);
1303
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001304 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001305 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001306 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001307 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001308 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1309 if (!ndlp)
1310 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001311 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001312 /* Set the node type */
1313 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001314 /* Put ndlp onto node list */
1315 lpfc_enqueue_node(vport, ndlp);
1316 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1317 /* re-setup ndlp without removing from node list */
1318 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1319 if (!ndlp)
1320 return 0;
dea31012005-04-17 16:05:31 -05001321 }
James Smart87af33f2007-10-27 13:37:43 -04001322
James Smart5ac6b302010-10-22 11:05:36 -04001323 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001324 /* This decrement of reference count to node shall kick off
1325 * the release of the node.
1326 */
James Smart329f9bc2007-04-25 09:53:01 -04001327 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001328 return 0;
1329 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001330 return 1;
dea31012005-04-17 16:05:31 -05001331}
1332
James Smarte59058c2008-08-24 21:49:00 -04001333/**
James Smart3621a712009-04-06 18:47:14 -04001334 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001335 * @vport: pointer to a host virtual N_Port data structure.
1336 *
1337 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1338 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1339 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1340 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1341 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1342 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1343 * @vport.
1344 *
1345 * Return code
1346 * 0 - failed to issue initial fdisc for @vport
1347 * 1 - successfully issued initial fdisc for @vport
1348 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001349int
1350lpfc_initial_fdisc(struct lpfc_vport *vport)
1351{
1352 struct lpfc_hba *phba = vport->phba;
1353 struct lpfc_nodelist *ndlp;
1354
1355 /* First look for the Fabric ndlp */
1356 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1357 if (!ndlp) {
1358 /* Cannot find existing Fabric ndlp, so allocate a new one */
1359 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1360 if (!ndlp)
1361 return 0;
1362 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001363 /* Put ndlp onto node list */
1364 lpfc_enqueue_node(vport, ndlp);
1365 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1366 /* re-setup ndlp without removing from node list */
1367 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1368 if (!ndlp)
1369 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001370 }
James Smarte47c9092008-02-08 18:49:26 -05001371
James Smart92d7f7b2007-06-17 19:56:38 -05001372 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001373 /* decrement node reference count to trigger the release of
1374 * the node.
1375 */
James Smart92d7f7b2007-06-17 19:56:38 -05001376 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001377 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001378 }
1379 return 1;
1380}
James Smart87af33f2007-10-27 13:37:43 -04001381
James Smarte59058c2008-08-24 21:49:00 -04001382/**
James Smart3621a712009-04-06 18:47:14 -04001383 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001384 * @vport: pointer to a host virtual N_Port data structure.
1385 *
1386 * This routine checks whether there are more remaining Port Logins
1387 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1388 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1389 * to issue ELS PLOGIs up to the configured discover threads with the
1390 * @vport (@vport->cfg_discovery_threads). The function also decrement
1391 * the @vport's num_disc_node by 1 if it is not already 0.
1392 **/
James Smart87af33f2007-10-27 13:37:43 -04001393void
James Smart2e0fef82007-06-17 19:56:36 -05001394lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001395{
1396 int sentplogi;
1397
James Smart2e0fef82007-06-17 19:56:36 -05001398 if (vport->num_disc_nodes)
1399 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001400
1401 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001402 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1403 "0232 Continue discovery with %d PLOGIs to go "
1404 "Data: x%x x%x x%x\n",
1405 vport->num_disc_nodes, vport->fc_plogi_cnt,
1406 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001407 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001408 if (vport->fc_flag & FC_NLP_MORE)
1409 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1410 sentplogi = lpfc_els_disc_plogi(vport);
1411
dea31012005-04-17 16:05:31 -05001412 return;
1413}
1414
James Smarte59058c2008-08-24 21:49:00 -04001415/**
James Smart3621a712009-04-06 18:47:14 -04001416 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001417 * @phba: pointer to lpfc hba data structure.
1418 * @prsp: pointer to response IOCB payload.
1419 * @ndlp: pointer to a node-list data structure.
1420 *
1421 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1422 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1423 * The following cases are considered N_Port confirmed:
1424 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1425 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1426 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1427 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1428 * 1) if there is a node on vport list other than the @ndlp with the same
1429 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1430 * on that node to release the RPI associated with the node; 2) if there is
1431 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1432 * into, a new node shall be allocated (or activated). In either case, the
1433 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1434 * be released and the new_ndlp shall be put on to the vport node list and
1435 * its pointer returned as the confirmed node.
1436 *
1437 * Note that before the @ndlp got "released", the keepDID from not-matching
1438 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1439 * of the @ndlp. This is because the release of @ndlp is actually to put it
1440 * into an inactive state on the vport node list and the vport node list
1441 * management algorithm does not allow two node with a same DID.
1442 *
1443 * Return code
1444 * pointer to the PLOGI N_Port @ndlp
1445 **/
James Smart488d1462006-03-07 15:02:37 -05001446static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001447lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001448 struct lpfc_nodelist *ndlp)
1449{
James Smart2e0fef82007-06-17 19:56:36 -05001450 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001451 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001452 struct lpfc_rport_data *rdata;
1453 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001454 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001455 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001456 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001457 int put_node;
1458 int put_rport;
James Smart19ca7602010-11-20 23:11:55 -05001459 struct lpfc_node_rrqs rrq;
James Smart488d1462006-03-07 15:02:37 -05001460
James Smart2fb9bd82006-12-02 13:33:57 -05001461 /* Fabric nodes can have the same WWPN so we don't bother searching
1462 * by WWPN. Just return the ndlp that was given to us.
1463 */
1464 if (ndlp->nlp_type & NLP_FABRIC)
1465 return ndlp;
1466
James Smart92d7f7b2007-06-17 19:56:38 -05001467 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001468 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001469
James Smart685f0bf2007-04-25 09:53:08 -04001470 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001471 * we have for that ndlp. If not, we have some work to do.
1472 */
James Smart2e0fef82007-06-17 19:56:36 -05001473 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001474
James Smarte47c9092008-02-08 18:49:26 -05001475 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001476 return ndlp;
James Smart19ca7602010-11-20 23:11:55 -05001477 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
James Smart488d1462006-03-07 15:02:37 -05001478
James Smart34f5ad82012-08-03 12:35:03 -04001479 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1480 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1481 ndlp, ndlp->nlp_DID, new_ndlp);
1482
James Smart488d1462006-03-07 15:02:37 -05001483 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001484 rc = memcmp(&ndlp->nlp_portname, name,
1485 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001486 if (!rc)
1487 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001488 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1489 if (!new_ndlp)
1490 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001491 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001492 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001493 rc = memcmp(&ndlp->nlp_portname, name,
1494 sizeof(struct lpfc_name));
1495 if (!rc)
1496 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001497 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1498 NLP_STE_UNUSED_NODE);
1499 if (!new_ndlp)
1500 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001501 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001502 if (phba->sli_rev == LPFC_SLI_REV4)
1503 memcpy(&rrq.xri_bitmap,
1504 &new_ndlp->active_rrqs.xri_bitmap,
1505 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1506 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001507 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001508 if (phba->sli_rev == LPFC_SLI_REV4)
1509 memcpy(&rrq.xri_bitmap,
1510 &new_ndlp->active_rrqs.xri_bitmap,
1511 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1512 }
James Smart488d1462006-03-07 15:02:37 -05001513
James Smart2e0fef82007-06-17 19:56:36 -05001514 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001515 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001516 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001517 if (phba->sli_rev == LPFC_SLI_REV4)
1518 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1519 &ndlp->active_rrqs.xri_bitmap,
1520 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart0ff10d42008-01-11 01:52:36 -05001521
1522 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1523 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1524 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1525
James Smarte47c9092008-02-08 18:49:26 -05001526 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001527 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001528
James Smart2e0fef82007-06-17 19:56:36 -05001529 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001530 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1531 /* The new_ndlp is replacing ndlp totally, so we need
1532 * to put ndlp on UNUSED list and try to free it.
1533 */
James Smart34f5ad82012-08-03 12:35:03 -04001534 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1535 "3179 PLOGI confirm NEW: %x %x\n",
1536 new_ndlp->nlp_DID, keepDID);
James Smart0ff10d42008-01-11 01:52:36 -05001537
1538 /* Fix up the rport accordingly */
1539 rport = ndlp->rport;
1540 if (rport) {
1541 rdata = rport->dd_data;
1542 if (rdata->pnode == ndlp) {
1543 lpfc_nlp_put(ndlp);
1544 ndlp->rport = NULL;
1545 rdata->pnode = lpfc_nlp_get(new_ndlp);
1546 new_ndlp->rport = rport;
1547 }
1548 new_ndlp->nlp_type = ndlp->nlp_type;
1549 }
James Smart58da1ff2008-04-07 10:15:56 -04001550 /* We shall actually free the ndlp with both nlp_DID and
1551 * nlp_portname fields equals 0 to avoid any ndlp on the
1552 * nodelist never to be used.
1553 */
1554 if (ndlp->nlp_DID == 0) {
1555 spin_lock_irq(&phba->ndlp_lock);
1556 NLP_SET_FREE_REQ(ndlp);
1557 spin_unlock_irq(&phba->ndlp_lock);
1558 }
James Smart0ff10d42008-01-11 01:52:36 -05001559
James Smart58da1ff2008-04-07 10:15:56 -04001560 /* Two ndlps cannot have the same did on the nodelist */
1561 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001562 if (phba->sli_rev == LPFC_SLI_REV4)
1563 memcpy(&ndlp->active_rrqs.xri_bitmap,
1564 &rrq.xri_bitmap,
1565 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001566 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001567 }
James Smart92795652006-07-06 15:50:02 -04001568 else {
James Smart34f5ad82012-08-03 12:35:03 -04001569 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1570 "3180 PLOGI confirm SWAP: %x %x\n",
1571 new_ndlp->nlp_DID, keepDID);
1572
James Smart2e0fef82007-06-17 19:56:36 -05001573 lpfc_unreg_rpi(vport, ndlp);
James Smart34f5ad82012-08-03 12:35:03 -04001574
James Smart58da1ff2008-04-07 10:15:56 -04001575 /* Two ndlps cannot have the same did */
1576 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001577 if (phba->sli_rev == LPFC_SLI_REV4)
1578 memcpy(&ndlp->active_rrqs.xri_bitmap,
1579 &rrq.xri_bitmap,
1580 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart34f5ad82012-08-03 12:35:03 -04001581
James Smart38b92ef2010-08-04 16:11:39 -04001582 /* Since we are swapping the ndlp passed in with the new one
James Smart34f5ad82012-08-03 12:35:03 -04001583 * and the did has already been swapped, copy over state.
1584 * The new WWNs are already in new_ndlp since thats what
1585 * we looked it up by in the begining of this routine.
James Smart38b92ef2010-08-04 16:11:39 -04001586 */
James Smart38b92ef2010-08-04 16:11:39 -04001587 new_ndlp->nlp_state = ndlp->nlp_state;
James Smart34f5ad82012-08-03 12:35:03 -04001588
1589 /* Since we are switching over to the new_ndlp, the old
1590 * ndlp should be put in the NPR state, unless we have
1591 * already started re-discovery on it.
1592 */
1593 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1594 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1595 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1596
James Smart38b92ef2010-08-04 16:11:39 -04001597 /* Fix up the rport accordingly */
1598 rport = ndlp->rport;
1599 if (rport) {
1600 rdata = rport->dd_data;
1601 put_node = rdata->pnode != NULL;
1602 put_rport = ndlp->rport != NULL;
1603 rdata->pnode = NULL;
1604 ndlp->rport = NULL;
1605 if (put_node)
1606 lpfc_nlp_put(ndlp);
1607 if (put_rport)
1608 put_device(&rport->dev);
1609 }
James Smart92795652006-07-06 15:50:02 -04001610 }
James Smart488d1462006-03-07 15:02:37 -05001611 return new_ndlp;
1612}
1613
James Smarte59058c2008-08-24 21:49:00 -04001614/**
James Smart3621a712009-04-06 18:47:14 -04001615 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001616 * @vport: pointer to a host virtual N_Port data structure.
1617 *
1618 * This routine checks whether more Registration State Change
1619 * Notifications (RSCNs) came in while the discovery state machine was in
1620 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1621 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1622 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1623 * handling the RSCNs.
1624 **/
James Smart87af33f2007-10-27 13:37:43 -04001625void
1626lpfc_end_rscn(struct lpfc_vport *vport)
1627{
1628 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1629
1630 if (vport->fc_flag & FC_RSCN_MODE) {
1631 /*
1632 * Check to see if more RSCNs came in while we were
1633 * processing this one.
1634 */
1635 if (vport->fc_rscn_id_cnt ||
1636 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1637 lpfc_els_handle_rscn(vport);
1638 else {
1639 spin_lock_irq(shost->host_lock);
1640 vport->fc_flag &= ~FC_RSCN_MODE;
1641 spin_unlock_irq(shost->host_lock);
1642 }
1643 }
1644}
1645
James Smarte59058c2008-08-24 21:49:00 -04001646/**
James Smart19ca7602010-11-20 23:11:55 -05001647 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1648 * @phba: pointer to lpfc hba data structure.
1649 * @cmdiocb: pointer to lpfc command iocb data structure.
1650 * @rspiocb: pointer to lpfc response iocb data structure.
1651 *
1652 * This routine will call the clear rrq function to free the rrq and
1653 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1654 * exist then the clear_rrq is still called because the rrq needs to
1655 * be freed.
1656 **/
1657
1658static void
1659lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1660 struct lpfc_iocbq *rspiocb)
1661{
1662 struct lpfc_vport *vport = cmdiocb->vport;
1663 IOCB_t *irsp;
1664 struct lpfc_nodelist *ndlp;
1665 struct lpfc_node_rrq *rrq;
1666
1667 /* we pass cmdiocb to state machine which needs rspiocb as well */
1668 rrq = cmdiocb->context_un.rrq;
1669 cmdiocb->context_un.rsp_iocb = rspiocb;
1670
1671 irsp = &rspiocb->iocb;
1672 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1673 "RRQ cmpl: status:x%x/x%x did:x%x",
1674 irsp->ulpStatus, irsp->un.ulpWord[4],
1675 irsp->un.elsreq64.remoteID);
1676
1677 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1678 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1679 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1680 "2882 RRQ completes to NPort x%x "
1681 "with no ndlp. Data: x%x x%x x%x\n",
1682 irsp->un.elsreq64.remoteID,
1683 irsp->ulpStatus, irsp->un.ulpWord[4],
1684 irsp->ulpIoTag);
1685 goto out;
1686 }
1687
1688 /* rrq completes to NPort <nlp_DID> */
1689 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1690 "2880 RRQ completes to NPort x%x "
1691 "Data: x%x x%x x%x x%x x%x\n",
1692 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1693 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1694
1695 if (irsp->ulpStatus) {
1696 /* Check for retry */
1697 /* RRQ failed Don't print the vport to vport rjts */
1698 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1699 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1700 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1701 (phba)->pport->cfg_log_verbose & LOG_ELS)
1702 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1703 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1704 ndlp->nlp_DID, irsp->ulpStatus,
1705 irsp->un.ulpWord[4]);
1706 }
1707out:
1708 if (rrq)
1709 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1710 lpfc_els_free_iocb(phba, cmdiocb);
1711 return;
1712}
1713/**
James Smart3621a712009-04-06 18:47:14 -04001714 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001715 * @phba: pointer to lpfc hba data structure.
1716 * @cmdiocb: pointer to lpfc command iocb data structure.
1717 * @rspiocb: pointer to lpfc response iocb data structure.
1718 *
1719 * This routine is the completion callback function for issuing the Port
1720 * Login (PLOGI) command. For PLOGI completion, there must be an active
1721 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001722 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001723 * ignored and command IOCB released. The PLOGI response IOCB status is
1724 * checked for error conditons. If there is error status reported, PLOGI
1725 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1726 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1727 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1728 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1729 * there are additional N_Port nodes with the vport that need to perform
1730 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1731 * PLOGIs.
1732 **/
dea31012005-04-17 16:05:31 -05001733static void
James Smart2e0fef82007-06-17 19:56:36 -05001734lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1735 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001736{
James Smart2e0fef82007-06-17 19:56:36 -05001737 struct lpfc_vport *vport = cmdiocb->vport;
1738 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001739 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001740 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001741 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001742 int disc, rc, did, type;
1743
dea31012005-04-17 16:05:31 -05001744 /* we pass cmdiocb to state machine which needs rspiocb as well */
1745 cmdiocb->context_un.rsp_iocb = rspiocb;
1746
1747 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001748 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1749 "PLOGI cmpl: status:x%x/x%x did:x%x",
1750 irsp->ulpStatus, irsp->un.ulpWord[4],
1751 irsp->un.elsreq64.remoteID);
1752
James Smart2e0fef82007-06-17 19:56:36 -05001753 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001754 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001755 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1756 "0136 PLOGI completes to NPort x%x "
1757 "with no ndlp. Data: x%x x%x x%x\n",
1758 irsp->un.elsreq64.remoteID,
1759 irsp->ulpStatus, irsp->un.ulpWord[4],
1760 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001761 goto out;
James Smarted957682007-06-17 19:56:37 -05001762 }
dea31012005-04-17 16:05:31 -05001763
1764 /* Since ndlp can be freed in the disc state machine, note if this node
1765 * is being used during discovery.
1766 */
James Smart2e0fef82007-06-17 19:56:36 -05001767 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001768 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001769 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001770 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001771 rc = 0;
1772
1773 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001774 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1775 "0102 PLOGI completes to NPort x%x "
1776 "Data: x%x x%x x%x x%x x%x\n",
1777 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1778 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001779 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001780 if (lpfc_els_chk_latt(vport)) {
1781 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001782 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001783 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001784 goto out;
1785 }
1786
1787 /* ndlp could be freed in DSM, save these values now */
1788 type = ndlp->nlp_type;
1789 did = ndlp->nlp_DID;
1790
1791 if (irsp->ulpStatus) {
1792 /* Check for retry */
1793 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1794 /* ELS command is being retried */
1795 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001796 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001797 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001798 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001799 }
1800 goto out;
1801 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001802 /* PLOGI failed Don't print the vport to vport rjts */
1803 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1804 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1805 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1806 (phba)->pport->cfg_log_verbose & LOG_ELS)
1807 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001808 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1809 ndlp->nlp_DID, irsp->ulpStatus,
1810 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001811 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001812 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001813 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001814 else
James Smart2e0fef82007-06-17 19:56:36 -05001815 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001816 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001817 } else {
1818 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001819 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001820 cmdiocb->context2)->list.next,
1821 struct lpfc_dmabuf, list);
1822 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001823 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001824 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001825 }
1826
James Smart2e0fef82007-06-17 19:56:36 -05001827 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001828 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001829 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001830
James Smart2e0fef82007-06-17 19:56:36 -05001831 if (vport->num_disc_nodes == 0) {
1832 spin_lock_irq(shost->host_lock);
1833 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1834 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001835
James Smart2e0fef82007-06-17 19:56:36 -05001836 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001837 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001838 }
1839 }
1840
1841out:
1842 lpfc_els_free_iocb(phba, cmdiocb);
1843 return;
1844}
1845
James Smarte59058c2008-08-24 21:49:00 -04001846/**
James Smart3621a712009-04-06 18:47:14 -04001847 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001848 * @vport: pointer to a host virtual N_Port data structure.
1849 * @did: destination port identifier.
1850 * @retry: number of retries to the command IOCB.
1851 *
1852 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1853 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1854 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1855 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1856 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1857 *
1858 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1859 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1860 * will be stored into the context1 field of the IOCB for the completion
1861 * callback function to the PLOGI ELS command.
1862 *
1863 * Return code
1864 * 0 - Successfully issued a plogi for @vport
1865 * 1 - failed to issue a plogi for @vport
1866 **/
dea31012005-04-17 16:05:31 -05001867int
James Smart2e0fef82007-06-17 19:56:36 -05001868lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001869{
James Smart2e0fef82007-06-17 19:56:36 -05001870 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001871 struct serv_parm *sp;
1872 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001873 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001874 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001875 struct lpfc_sli *psli;
1876 uint8_t *pcmd;
1877 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001878 int ret;
dea31012005-04-17 16:05:31 -05001879
1880 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001881
James Smart98c9ea52007-10-27 13:37:33 -04001882 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001883 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1884 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001885
James Smarte47c9092008-02-08 18:49:26 -05001886 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001887 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001888 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001889 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001890 if (!elsiocb)
1891 return 1;
dea31012005-04-17 16:05:31 -05001892
1893 icmd = &elsiocb->iocb;
1894 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1895
1896 /* For PLOGI request, remainder of payload is service parameters */
1897 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001898 pcmd += sizeof(uint32_t);
1899 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001900 sp = (struct serv_parm *) pcmd;
1901
James Smart5ac6b302010-10-22 11:05:36 -04001902 /*
1903 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1904 * to device on remote loops work.
1905 */
1906 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1907 sp->cmn.altBbCredit = 1;
1908
dea31012005-04-17 16:05:31 -05001909 if (sp->cmn.fcphLow < FC_PH_4_3)
1910 sp->cmn.fcphLow = FC_PH_4_3;
1911
1912 if (sp->cmn.fcphHigh < FC_PH3)
1913 sp->cmn.fcphHigh = FC_PH3;
1914
James Smart858c9f62007-06-17 19:56:39 -05001915 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1916 "Issue PLOGI: did:x%x",
1917 did, 0, 0);
1918
dea31012005-04-17 16:05:31 -05001919 phba->fc_stat.elsXmitPLOGI++;
1920 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001921 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001922
1923 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001924 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001925 return 1;
dea31012005-04-17 16:05:31 -05001926 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001927 return 0;
dea31012005-04-17 16:05:31 -05001928}
1929
James Smarte59058c2008-08-24 21:49:00 -04001930/**
James Smart3621a712009-04-06 18:47:14 -04001931 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001932 * @phba: pointer to lpfc hba data structure.
1933 * @cmdiocb: pointer to lpfc command iocb data structure.
1934 * @rspiocb: pointer to lpfc response iocb data structure.
1935 *
1936 * This routine is the completion callback function for a Process Login
1937 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1938 * status. If there is error status reported, PRLI retry shall be attempted
1939 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1940 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1941 * ndlp to mark the PRLI completion.
1942 **/
dea31012005-04-17 16:05:31 -05001943static void
James Smart2e0fef82007-06-17 19:56:36 -05001944lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1945 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001946{
James Smart2e0fef82007-06-17 19:56:36 -05001947 struct lpfc_vport *vport = cmdiocb->vport;
1948 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001949 IOCB_t *irsp;
1950 struct lpfc_sli *psli;
1951 struct lpfc_nodelist *ndlp;
1952
1953 psli = &phba->sli;
1954 /* we pass cmdiocb to state machine which needs rspiocb as well */
1955 cmdiocb->context_un.rsp_iocb = rspiocb;
1956
1957 irsp = &(rspiocb->iocb);
1958 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001959 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001960 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001961 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001962
James Smart858c9f62007-06-17 19:56:39 -05001963 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1964 "PRLI cmpl: status:x%x/x%x did:x%x",
1965 irsp->ulpStatus, irsp->un.ulpWord[4],
1966 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001967 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001968 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1969 "0103 PRLI completes to NPort x%x "
1970 "Data: x%x x%x x%x x%x\n",
1971 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1972 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001973
James Smart2e0fef82007-06-17 19:56:36 -05001974 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001975 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001976 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001977 goto out;
1978
1979 if (irsp->ulpStatus) {
1980 /* Check for retry */
1981 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1982 /* ELS command is being retried */
1983 goto out;
1984 }
1985 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001986 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1987 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1988 ndlp->nlp_DID, irsp->ulpStatus,
1989 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001990 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001991 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001992 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001993 else
James Smart2e0fef82007-06-17 19:56:36 -05001994 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001995 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001996 } else
dea31012005-04-17 16:05:31 -05001997 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001998 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001999 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05002000out:
2001 lpfc_els_free_iocb(phba, cmdiocb);
2002 return;
2003}
2004
James Smarte59058c2008-08-24 21:49:00 -04002005/**
James Smart3621a712009-04-06 18:47:14 -04002006 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002007 * @vport: pointer to a host virtual N_Port data structure.
2008 * @ndlp: pointer to a node-list data structure.
2009 * @retry: number of retries to the command IOCB.
2010 *
2011 * This routine issues a Process Login (PRLI) ELS command for the
2012 * @vport. The PRLI service parameters are set up in the payload of the
2013 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2014 * is put to the IOCB completion callback func field before invoking the
2015 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2016 *
2017 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2018 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2019 * will be stored into the context1 field of the IOCB for the completion
2020 * callback function to the PRLI ELS command.
2021 *
2022 * Return code
2023 * 0 - successfully issued prli iocb command for @vport
2024 * 1 - failed to issue prli iocb command for @vport
2025 **/
dea31012005-04-17 16:05:31 -05002026int
James Smart2e0fef82007-06-17 19:56:36 -05002027lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002028 uint8_t retry)
2029{
James Smart2e0fef82007-06-17 19:56:36 -05002030 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2031 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002032 PRLI *npr;
2033 IOCB_t *icmd;
2034 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002035 uint8_t *pcmd;
2036 uint16_t cmdsize;
2037
James Smart92d7f7b2007-06-17 19:56:38 -05002038 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05002039 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2040 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05002041 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002042 return 1;
dea31012005-04-17 16:05:31 -05002043
2044 icmd = &elsiocb->iocb;
2045 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2046
2047 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05002048 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05002049 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05002050 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002051
2052 /* For PRLI, remainder of payload is PRLI parameter page */
2053 npr = (PRLI *) pcmd;
2054 /*
2055 * If our firmware version is 3.20 or later,
2056 * set the following bits for FC-TAPE support.
2057 */
2058 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2059 npr->ConfmComplAllowed = 1;
2060 npr->Retry = 1;
2061 npr->TaskRetryIdReq = 1;
2062 }
2063 npr->estabImagePair = 1;
2064 npr->readXferRdyDis = 1;
2065
2066 /* For FCP support */
2067 npr->prliType = PRLI_FCP_TYPE;
2068 npr->initiatorFunc = 1;
2069
James Smart858c9f62007-06-17 19:56:39 -05002070 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2071 "Issue PRLI: did:x%x",
2072 ndlp->nlp_DID, 0, 0);
2073
dea31012005-04-17 16:05:31 -05002074 phba->fc_stat.elsXmitPRLI++;
2075 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05002076 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002077 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002078 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002079 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2080 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002081 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002082 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002083 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002084 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002085 return 1;
dea31012005-04-17 16:05:31 -05002086 }
James Smart2e0fef82007-06-17 19:56:36 -05002087 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002088 return 0;
dea31012005-04-17 16:05:31 -05002089}
2090
James Smarte59058c2008-08-24 21:49:00 -04002091/**
James Smart3621a712009-04-06 18:47:14 -04002092 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002093 * @vport: pointer to a host virtual N_Port data structure.
2094 *
2095 * This routine performs Registration State Change Notification (RSCN)
2096 * discovery for a @vport. If the @vport's node port recovery count is not
2097 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2098 * the nodes that need recovery. If none of the PLOGI were needed through
2099 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2100 * invoked to check and handle possible more RSCN came in during the period
2101 * of processing the current ones.
2102 **/
2103static void
2104lpfc_rscn_disc(struct lpfc_vport *vport)
2105{
2106 lpfc_can_disctmo(vport);
2107
2108 /* RSCN discovery */
2109 /* go thru NPR nodes and issue ELS PLOGIs */
2110 if (vport->fc_npr_cnt)
2111 if (lpfc_els_disc_plogi(vport))
2112 return;
2113
2114 lpfc_end_rscn(vport);
2115}
2116
2117/**
James Smart3621a712009-04-06 18:47:14 -04002118 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002119 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2120 *
2121 * This function is called when the final ADISC is completed during discovery.
2122 * This function handles clearing link attention or issuing reg_vpi depending
2123 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2124 * discovery.
2125 * This function is called with no locks held.
2126 **/
2127static void
2128lpfc_adisc_done(struct lpfc_vport *vport)
2129{
2130 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2131 struct lpfc_hba *phba = vport->phba;
2132
2133 /*
2134 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2135 * and continue discovery.
2136 */
2137 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002138 !(vport->fc_flag & FC_RSCN_MODE) &&
2139 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04002140 lpfc_issue_reg_vpi(phba, vport);
2141 return;
2142 }
2143 /*
2144 * For SLI2, we need to set port_state to READY
2145 * and continue discovery.
2146 */
2147 if (vport->port_state < LPFC_VPORT_READY) {
2148 /* If we get here, there is nothing to ADISC */
2149 if (vport->port_type == LPFC_PHYSICAL_PORT)
2150 lpfc_issue_clear_la(phba, vport);
2151 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2152 vport->num_disc_nodes = 0;
2153 /* go thru NPR list, issue ELS PLOGIs */
2154 if (vport->fc_npr_cnt)
2155 lpfc_els_disc_plogi(vport);
2156 if (!vport->num_disc_nodes) {
2157 spin_lock_irq(shost->host_lock);
2158 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2159 spin_unlock_irq(shost->host_lock);
2160 lpfc_can_disctmo(vport);
2161 lpfc_end_rscn(vport);
2162 }
2163 }
2164 vport->port_state = LPFC_VPORT_READY;
2165 } else
2166 lpfc_rscn_disc(vport);
2167}
2168
2169/**
James Smart3621a712009-04-06 18:47:14 -04002170 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002171 * @vport: pointer to a host virtual N_Port data structure.
2172 *
2173 * This routine determines whether there are more ndlps on a @vport
2174 * node list need to have Address Discover (ADISC) issued. If so, it will
2175 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2176 * remaining nodes which need to have ADISC sent.
2177 **/
James Smart0ff10d42008-01-11 01:52:36 -05002178void
James Smart2e0fef82007-06-17 19:56:36 -05002179lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002180{
2181 int sentadisc;
2182
James Smart2e0fef82007-06-17 19:56:36 -05002183 if (vport->num_disc_nodes)
2184 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002185 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002186 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2187 "0210 Continue discovery with %d ADISCs to go "
2188 "Data: x%x x%x x%x\n",
2189 vport->num_disc_nodes, vport->fc_adisc_cnt,
2190 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002191 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002192 if (vport->fc_flag & FC_NLP_MORE) {
2193 lpfc_set_disctmo(vport);
2194 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2195 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002196 }
James Smart90160e02008-08-24 21:49:45 -04002197 if (!vport->num_disc_nodes)
2198 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002199 return;
2200}
2201
James Smarte59058c2008-08-24 21:49:00 -04002202/**
James Smart3621a712009-04-06 18:47:14 -04002203 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002204 * @phba: pointer to lpfc hba data structure.
2205 * @cmdiocb: pointer to lpfc command iocb data structure.
2206 * @rspiocb: pointer to lpfc response iocb data structure.
2207 *
2208 * This routine is the completion function for issuing the Address Discover
2209 * (ADISC) command. It first checks to see whether link went down during
2210 * the discovery process. If so, the node will be marked as node port
2211 * recovery for issuing discover IOCB by the link attention handler and
2212 * exit. Otherwise, the response status is checked. If error was reported
2213 * in the response status, the ADISC command shall be retried by invoking
2214 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2215 * the response status, the state machine is invoked to set transition
2216 * with respect to NLP_EVT_CMPL_ADISC event.
2217 **/
dea31012005-04-17 16:05:31 -05002218static void
James Smart2e0fef82007-06-17 19:56:36 -05002219lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2220 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002221{
James Smart2e0fef82007-06-17 19:56:36 -05002222 struct lpfc_vport *vport = cmdiocb->vport;
2223 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002224 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002225 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002226 int disc;
dea31012005-04-17 16:05:31 -05002227
2228 /* we pass cmdiocb to state machine which needs rspiocb as well */
2229 cmdiocb->context_un.rsp_iocb = rspiocb;
2230
2231 irsp = &(rspiocb->iocb);
2232 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002233
James Smart858c9f62007-06-17 19:56:39 -05002234 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2235 "ADISC cmpl: status:x%x/x%x did:x%x",
2236 irsp->ulpStatus, irsp->un.ulpWord[4],
2237 ndlp->nlp_DID);
2238
dea31012005-04-17 16:05:31 -05002239 /* Since ndlp can be freed in the disc state machine, note if this node
2240 * is being used during discovery.
2241 */
James Smart2e0fef82007-06-17 19:56:36 -05002242 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002243 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002244 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002245 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002246 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002247 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2248 "0104 ADISC completes to NPort x%x "
2249 "Data: x%x x%x x%x x%x x%x\n",
2250 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2251 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002252 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002253 if (lpfc_els_chk_latt(vport)) {
2254 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002255 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002256 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002257 goto out;
2258 }
2259
2260 if (irsp->ulpStatus) {
2261 /* Check for retry */
2262 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2263 /* ELS command is being retried */
2264 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002265 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002266 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002267 spin_unlock_irq(shost->host_lock);
2268 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002269 }
2270 goto out;
2271 }
2272 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002273 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2274 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2275 ndlp->nlp_DID, irsp->ulpStatus,
2276 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002277 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002278 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002279 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002280 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002281 } else
dea31012005-04-17 16:05:31 -05002282 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002283 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002284 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002285
James Smart90160e02008-08-24 21:49:45 -04002286 /* Check to see if there are more ADISCs to be sent */
2287 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002288 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002289out:
2290 lpfc_els_free_iocb(phba, cmdiocb);
2291 return;
2292}
2293
James Smarte59058c2008-08-24 21:49:00 -04002294/**
James Smart3621a712009-04-06 18:47:14 -04002295 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002296 * @vport: pointer to a virtual N_Port data structure.
2297 * @ndlp: pointer to a node-list data structure.
2298 * @retry: number of retries to the command IOCB.
2299 *
2300 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2301 * @vport. It prepares the payload of the ADISC ELS command, updates the
2302 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2303 * to issue the ADISC ELS command.
2304 *
2305 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2306 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2307 * will be stored into the context1 field of the IOCB for the completion
2308 * callback function to the ADISC ELS command.
2309 *
2310 * Return code
2311 * 0 - successfully issued adisc
2312 * 1 - failed to issue adisc
2313 **/
dea31012005-04-17 16:05:31 -05002314int
James Smart2e0fef82007-06-17 19:56:36 -05002315lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002316 uint8_t retry)
2317{
James Smart2e0fef82007-06-17 19:56:36 -05002318 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2319 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002320 ADISC *ap;
2321 IOCB_t *icmd;
2322 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002323 uint8_t *pcmd;
2324 uint16_t cmdsize;
2325
James Smart92d7f7b2007-06-17 19:56:38 -05002326 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002327 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2328 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002329 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002330 return 1;
dea31012005-04-17 16:05:31 -05002331
2332 icmd = &elsiocb->iocb;
2333 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2334
2335 /* For ADISC request, remainder of payload is service parameters */
2336 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002337 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002338
2339 /* Fill in ADISC payload */
2340 ap = (ADISC *) pcmd;
2341 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002342 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2343 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002344 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002345
James Smart858c9f62007-06-17 19:56:39 -05002346 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2347 "Issue ADISC: did:x%x",
2348 ndlp->nlp_DID, 0, 0);
2349
dea31012005-04-17 16:05:31 -05002350 phba->fc_stat.elsXmitADISC++;
2351 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002352 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002353 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002354 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002355 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2356 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002357 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002358 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002359 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002360 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002361 return 1;
dea31012005-04-17 16:05:31 -05002362 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002363 return 0;
dea31012005-04-17 16:05:31 -05002364}
2365
James Smarte59058c2008-08-24 21:49:00 -04002366/**
James Smart3621a712009-04-06 18:47:14 -04002367 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002368 * @phba: pointer to lpfc hba data structure.
2369 * @cmdiocb: pointer to lpfc command iocb data structure.
2370 * @rspiocb: pointer to lpfc response iocb data structure.
2371 *
2372 * This routine is the completion function for issuing the ELS Logout (LOGO)
2373 * command. If no error status was reported from the LOGO response, the
2374 * state machine of the associated ndlp shall be invoked for transition with
2375 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2376 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2377 **/
dea31012005-04-17 16:05:31 -05002378static void
James Smart2e0fef82007-06-17 19:56:36 -05002379lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2380 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002381{
James Smart2e0fef82007-06-17 19:56:36 -05002382 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2383 struct lpfc_vport *vport = ndlp->vport;
2384 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002385 IOCB_t *irsp;
2386 struct lpfc_sli *psli;
James Smart92494142011-02-16 12:39:44 -05002387 struct lpfcMboxq *mbox;
dea31012005-04-17 16:05:31 -05002388
2389 psli = &phba->sli;
2390 /* we pass cmdiocb to state machine which needs rspiocb as well */
2391 cmdiocb->context_un.rsp_iocb = rspiocb;
2392
2393 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002394 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002395 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002396 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002397
James Smart858c9f62007-06-17 19:56:39 -05002398 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2399 "LOGO cmpl: status:x%x/x%x did:x%x",
2400 irsp->ulpStatus, irsp->un.ulpWord[4],
2401 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002402 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002403 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2404 "0105 LOGO completes to NPort x%x "
2405 "Data: x%x x%x x%x x%x\n",
2406 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2407 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002408 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002409 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002410 goto out;
2411
James Smart92d7f7b2007-06-17 19:56:38 -05002412 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2413 /* NLP_EVT_DEVICE_RM should unregister the RPI
2414 * which should abort all outstanding IOs.
2415 */
2416 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2417 NLP_EVT_DEVICE_RM);
2418 goto out;
2419 }
2420
dea31012005-04-17 16:05:31 -05002421 if (irsp->ulpStatus) {
2422 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002423 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002424 /* ELS command is being retried */
2425 goto out;
dea31012005-04-17 16:05:31 -05002426 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002427 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2428 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2429 ndlp->nlp_DID, irsp->ulpStatus,
2430 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002431 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002432 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002433 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002434 else
James Smart2e0fef82007-06-17 19:56:36 -05002435 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002436 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002437 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002438 /* Good status, call state machine.
2439 * This will unregister the rpi if needed.
2440 */
James Smart2e0fef82007-06-17 19:56:36 -05002441 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002442 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002443out:
2444 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002445 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2446 if ((vport->fc_flag & FC_PT2PT) &&
2447 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2448 phba->pport->fc_myDID = 0;
2449 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2450 if (mbox) {
2451 lpfc_config_link(phba, mbox);
2452 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2453 mbox->vport = vport;
2454 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2455 MBX_NOT_FINISHED) {
2456 mempool_free(mbox, phba->mbox_mem_pool);
2457 }
2458 }
2459 }
dea31012005-04-17 16:05:31 -05002460 return;
2461}
2462
James Smarte59058c2008-08-24 21:49:00 -04002463/**
James Smart3621a712009-04-06 18:47:14 -04002464 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002465 * @vport: pointer to a virtual N_Port data structure.
2466 * @ndlp: pointer to a node-list data structure.
2467 * @retry: number of retries to the command IOCB.
2468 *
2469 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2470 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2471 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2472 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2473 *
2474 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2475 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2476 * will be stored into the context1 field of the IOCB for the completion
2477 * callback function to the LOGO ELS command.
2478 *
2479 * Return code
2480 * 0 - successfully issued logo
2481 * 1 - failed to issue logo
2482 **/
dea31012005-04-17 16:05:31 -05002483int
James Smart2e0fef82007-06-17 19:56:36 -05002484lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002485 uint8_t retry)
2486{
James Smart2e0fef82007-06-17 19:56:36 -05002487 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2488 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002489 IOCB_t *icmd;
2490 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002491 uint8_t *pcmd;
2492 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002493 int rc;
dea31012005-04-17 16:05:31 -05002494
James Smart98c9ea52007-10-27 13:37:33 -04002495 spin_lock_irq(shost->host_lock);
2496 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2497 spin_unlock_irq(shost->host_lock);
2498 return 0;
2499 }
2500 spin_unlock_irq(shost->host_lock);
2501
James Smart92d7f7b2007-06-17 19:56:38 -05002502 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002503 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2504 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002505 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002506 return 1;
dea31012005-04-17 16:05:31 -05002507
2508 icmd = &elsiocb->iocb;
2509 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2510 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002511 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002512
2513 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002514 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002515 pcmd += sizeof(uint32_t);
2516 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002517
James Smart858c9f62007-06-17 19:56:39 -05002518 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2519 "Issue LOGO: did:x%x",
2520 ndlp->nlp_DID, 0, 0);
2521
dea31012005-04-17 16:05:31 -05002522 phba->fc_stat.elsXmitLOGO++;
2523 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002524 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002525 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002526 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002527 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002528
2529 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002530 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002531 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002532 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002533 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002534 return 1;
dea31012005-04-17 16:05:31 -05002535 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002536 return 0;
dea31012005-04-17 16:05:31 -05002537}
2538
James Smarte59058c2008-08-24 21:49:00 -04002539/**
James Smart3621a712009-04-06 18:47:14 -04002540 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002541 * @phba: pointer to lpfc hba data structure.
2542 * @cmdiocb: pointer to lpfc command iocb data structure.
2543 * @rspiocb: pointer to lpfc response iocb data structure.
2544 *
2545 * This routine is a generic completion callback function for ELS commands.
2546 * Specifically, it is the callback function which does not need to perform
2547 * any command specific operations. It is currently used by the ELS command
2548 * issuing routines for the ELS State Change Request (SCR),
2549 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2550 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2551 * certain debug loggings, this callback function simply invokes the
2552 * lpfc_els_chk_latt() routine to check whether link went down during the
2553 * discovery process.
2554 **/
dea31012005-04-17 16:05:31 -05002555static void
James Smart2e0fef82007-06-17 19:56:36 -05002556lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2557 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002558{
James Smart2e0fef82007-06-17 19:56:36 -05002559 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002560 IOCB_t *irsp;
2561
2562 irsp = &rspiocb->iocb;
2563
James Smart858c9f62007-06-17 19:56:39 -05002564 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2565 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2566 irsp->ulpStatus, irsp->un.ulpWord[4],
2567 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002568 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002569 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2570 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2571 irsp->ulpIoTag, irsp->ulpStatus,
2572 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002573 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002574 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002575 lpfc_els_free_iocb(phba, cmdiocb);
2576 return;
2577}
2578
James Smarte59058c2008-08-24 21:49:00 -04002579/**
James Smart3621a712009-04-06 18:47:14 -04002580 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002581 * @vport: pointer to a host virtual N_Port data structure.
2582 * @nportid: N_Port identifier to the remote node.
2583 * @retry: number of retries to the command IOCB.
2584 *
2585 * This routine issues a State Change Request (SCR) to a fabric node
2586 * on a @vport. The remote node @nportid is passed into the function. It
2587 * first search the @vport node list to find the matching ndlp. If no such
2588 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2589 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2590 * routine is invoked to send the SCR IOCB.
2591 *
2592 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2593 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2594 * will be stored into the context1 field of the IOCB for the completion
2595 * callback function to the SCR ELS command.
2596 *
2597 * Return code
2598 * 0 - Successfully issued scr command
2599 * 1 - Failed to issue scr command
2600 **/
dea31012005-04-17 16:05:31 -05002601int
James Smart2e0fef82007-06-17 19:56:36 -05002602lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002603{
James Smart2e0fef82007-06-17 19:56:36 -05002604 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002605 IOCB_t *icmd;
2606 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002607 struct lpfc_sli *psli;
2608 uint8_t *pcmd;
2609 uint16_t cmdsize;
2610 struct lpfc_nodelist *ndlp;
2611
2612 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002613 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002614
James Smarte47c9092008-02-08 18:49:26 -05002615 ndlp = lpfc_findnode_did(vport, nportid);
2616 if (!ndlp) {
2617 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2618 if (!ndlp)
2619 return 1;
2620 lpfc_nlp_init(vport, ndlp, nportid);
2621 lpfc_enqueue_node(vport, ndlp);
2622 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2623 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2624 if (!ndlp)
2625 return 1;
2626 }
dea31012005-04-17 16:05:31 -05002627
James Smart2e0fef82007-06-17 19:56:36 -05002628 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2629 ndlp->nlp_DID, ELS_CMD_SCR);
2630
James Smart488d1462006-03-07 15:02:37 -05002631 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002632 /* This will trigger the release of the node just
2633 * allocated
2634 */
James Smart329f9bc2007-04-25 09:53:01 -04002635 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002636 return 1;
dea31012005-04-17 16:05:31 -05002637 }
2638
2639 icmd = &elsiocb->iocb;
2640 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2641
2642 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002643 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002644
2645 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002646 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002647 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2648
James Smart858c9f62007-06-17 19:56:39 -05002649 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2650 "Issue SCR: did:x%x",
2651 ndlp->nlp_DID, 0, 0);
2652
dea31012005-04-17 16:05:31 -05002653 phba->fc_stat.elsXmitSCR++;
2654 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002655 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2656 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002657 /* The additional lpfc_nlp_put will cause the following
2658 * lpfc_els_free_iocb routine to trigger the rlease of
2659 * the node.
2660 */
James Smart329f9bc2007-04-25 09:53:01 -04002661 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002662 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002663 return 1;
dea31012005-04-17 16:05:31 -05002664 }
James Smartfa4066b2008-01-11 01:53:27 -05002665 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2666 * trigger the release of node.
2667 */
James Smart329f9bc2007-04-25 09:53:01 -04002668 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002669 return 0;
dea31012005-04-17 16:05:31 -05002670}
2671
James Smarte59058c2008-08-24 21:49:00 -04002672/**
James Smart3621a712009-04-06 18:47:14 -04002673 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002674 * @vport: pointer to a host virtual N_Port data structure.
2675 * @nportid: N_Port identifier to the remote node.
2676 * @retry: number of retries to the command IOCB.
2677 *
2678 * This routine issues a Fibre Channel Address Resolution Response
2679 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2680 * is passed into the function. It first search the @vport node list to find
2681 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2682 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2683 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2684 *
2685 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2686 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2687 * will be stored into the context1 field of the IOCB for the completion
2688 * callback function to the PARPR ELS command.
2689 *
2690 * Return code
2691 * 0 - Successfully issued farpr command
2692 * 1 - Failed to issue farpr command
2693 **/
dea31012005-04-17 16:05:31 -05002694static int
James Smart2e0fef82007-06-17 19:56:36 -05002695lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002696{
James Smart2e0fef82007-06-17 19:56:36 -05002697 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002698 IOCB_t *icmd;
2699 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002700 struct lpfc_sli *psli;
2701 FARP *fp;
2702 uint8_t *pcmd;
2703 uint32_t *lp;
2704 uint16_t cmdsize;
2705 struct lpfc_nodelist *ondlp;
2706 struct lpfc_nodelist *ndlp;
2707
2708 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002709 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002710
James Smarte47c9092008-02-08 18:49:26 -05002711 ndlp = lpfc_findnode_did(vport, nportid);
2712 if (!ndlp) {
2713 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2714 if (!ndlp)
2715 return 1;
2716 lpfc_nlp_init(vport, ndlp, nportid);
2717 lpfc_enqueue_node(vport, ndlp);
2718 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2719 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2720 if (!ndlp)
2721 return 1;
2722 }
James Smart2e0fef82007-06-17 19:56:36 -05002723
2724 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2725 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002726 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002727 /* This will trigger the release of the node just
2728 * allocated
2729 */
James Smart329f9bc2007-04-25 09:53:01 -04002730 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002731 return 1;
dea31012005-04-17 16:05:31 -05002732 }
2733
2734 icmd = &elsiocb->iocb;
2735 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2736
2737 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002738 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002739
2740 /* Fill in FARPR payload */
2741 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002742 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002743 lp = (uint32_t *) pcmd;
2744 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002745 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002746 fp->Rflags = 0;
2747 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2748
James Smart92d7f7b2007-06-17 19:56:38 -05002749 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2750 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002751 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002752 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002753 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002754 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002755 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002756 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002757 }
2758
James Smart858c9f62007-06-17 19:56:39 -05002759 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2760 "Issue FARPR: did:x%x",
2761 ndlp->nlp_DID, 0, 0);
2762
dea31012005-04-17 16:05:31 -05002763 phba->fc_stat.elsXmitFARPR++;
2764 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002765 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2766 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002767 /* The additional lpfc_nlp_put will cause the following
2768 * lpfc_els_free_iocb routine to trigger the release of
2769 * the node.
2770 */
James Smart329f9bc2007-04-25 09:53:01 -04002771 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002772 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002773 return 1;
dea31012005-04-17 16:05:31 -05002774 }
James Smartfa4066b2008-01-11 01:53:27 -05002775 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2776 * trigger the release of the node.
2777 */
James Smart329f9bc2007-04-25 09:53:01 -04002778 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002779 return 0;
dea31012005-04-17 16:05:31 -05002780}
2781
James Smarte59058c2008-08-24 21:49:00 -04002782/**
James Smart3621a712009-04-06 18:47:14 -04002783 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002784 * @vport: pointer to a host virtual N_Port data structure.
2785 * @nlp: pointer to a node-list data structure.
2786 *
2787 * This routine cancels the timer with a delayed IOCB-command retry for
2788 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2789 * removes the ELS retry event if it presents. In addition, if the
2790 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2791 * commands are sent for the @vport's nodes that require issuing discovery
2792 * ADISC.
2793 **/
dea31012005-04-17 16:05:31 -05002794void
James Smart2e0fef82007-06-17 19:56:36 -05002795lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002796{
James Smart2e0fef82007-06-17 19:56:36 -05002797 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002798 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002799
James Smart0d2b6b82008-06-14 22:52:47 -04002800 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2801 return;
James Smart2e0fef82007-06-17 19:56:36 -05002802 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002803 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002804 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002805 del_timer_sync(&nlp->nlp_delayfunc);
2806 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002807 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002808 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002809 /* Decrement nlp reference count held for the delayed retry */
2810 evtp = &nlp->els_retry_evt;
2811 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2812 }
James Smartfdcebe22006-03-07 15:04:01 -05002813 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002814 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002815 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002816 spin_unlock_irq(shost->host_lock);
2817 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002818 if (vport->port_state < LPFC_VPORT_READY) {
2819 /* Check if there are more ADISCs to be sent */
2820 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002821 } else {
2822 /* Check if there are more PLOGIs to be sent */
2823 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002824 if (vport->num_disc_nodes == 0) {
2825 spin_lock_irq(shost->host_lock);
2826 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2827 spin_unlock_irq(shost->host_lock);
2828 lpfc_can_disctmo(vport);
2829 lpfc_end_rscn(vport);
2830 }
James Smartfdcebe22006-03-07 15:04:01 -05002831 }
2832 }
2833 }
2834 return;
2835}
2836
James Smarte59058c2008-08-24 21:49:00 -04002837/**
James Smart3621a712009-04-06 18:47:14 -04002838 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002839 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2840 *
2841 * This routine is invoked by the ndlp delayed-function timer to check
2842 * whether there is any pending ELS retry event(s) with the node. If not, it
2843 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2844 * adds the delayed events to the HBA work list and invokes the
2845 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2846 * event. Note that lpfc_nlp_get() is called before posting the event to
2847 * the work list to hold reference count of ndlp so that it guarantees the
2848 * reference to ndlp will still be available when the worker thread gets
2849 * to the event associated with the ndlp.
2850 **/
James Smartfdcebe22006-03-07 15:04:01 -05002851void
dea31012005-04-17 16:05:31 -05002852lpfc_els_retry_delay(unsigned long ptr)
2853{
James Smart2e0fef82007-06-17 19:56:36 -05002854 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2855 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002856 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002857 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002858 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002859
James Smart92d7f7b2007-06-17 19:56:38 -05002860 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002861 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002862 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002863 return;
2864 }
2865
James Smartfa4066b2008-01-11 01:53:27 -05002866 /* We need to hold the node by incrementing the reference
2867 * count until the queued work is done
2868 */
2869 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002870 if (evtp->evt_arg1) {
2871 evtp->evt = LPFC_EVT_ELS_RETRY;
2872 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002873 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002874 }
James Smart92d7f7b2007-06-17 19:56:38 -05002875 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002876 return;
2877}
2878
James Smarte59058c2008-08-24 21:49:00 -04002879/**
James Smart3621a712009-04-06 18:47:14 -04002880 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002881 * @ndlp: pointer to a node-list data structure.
2882 *
2883 * This routine is the worker-thread handler for processing the @ndlp delayed
2884 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2885 * the last ELS command from the associated ndlp and invokes the proper ELS
2886 * function according to the delayed ELS command to retry the command.
2887 **/
dea31012005-04-17 16:05:31 -05002888void
2889lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2890{
James Smart2e0fef82007-06-17 19:56:36 -05002891 struct lpfc_vport *vport = ndlp->vport;
2892 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2893 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002894
James Smart2e0fef82007-06-17 19:56:36 -05002895 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002896 did = ndlp->nlp_DID;
2897 cmd = ndlp->nlp_last_elscmd;
2898 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002899
2900 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002901 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002902 return;
2903 }
2904
2905 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002906 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002907 /*
2908 * If a discovery event readded nlp_delayfunc after timer
2909 * firing and before processing the timer, cancel the
2910 * nlp_delayfunc.
2911 */
2912 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002913 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002914 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002915
2916 switch (cmd) {
2917 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002918 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002919 break;
2920 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002921 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002922 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002923 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002924 }
dea31012005-04-17 16:05:31 -05002925 break;
2926 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002927 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002928 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002929 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002930 }
dea31012005-04-17 16:05:31 -05002931 break;
2932 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002933 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002934 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002935 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002936 }
dea31012005-04-17 16:05:31 -05002937 break;
2938 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002939 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002940 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002941 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002942 }
dea31012005-04-17 16:05:31 -05002943 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002944 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05002945 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
2946 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05002947 break;
dea31012005-04-17 16:05:31 -05002948 }
2949 return;
2950}
2951
James Smarte59058c2008-08-24 21:49:00 -04002952/**
James Smart3621a712009-04-06 18:47:14 -04002953 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002954 * @phba: pointer to lpfc hba data structure.
2955 * @cmdiocb: pointer to lpfc command iocb data structure.
2956 * @rspiocb: pointer to lpfc response iocb data structure.
2957 *
2958 * This routine makes a retry decision on an ELS command IOCB, which has
2959 * failed. The following ELS IOCBs use this function for retrying the command
2960 * when previously issued command responsed with error status: FLOGI, PLOGI,
2961 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2962 * returned error status, it makes the decision whether a retry shall be
2963 * issued for the command, and whether a retry shall be made immediately or
2964 * delayed. In the former case, the corresponding ELS command issuing-function
2965 * is called to retry the command. In the later case, the ELS command shall
2966 * be posted to the ndlp delayed event and delayed function timer set to the
2967 * ndlp for the delayed command issusing.
2968 *
2969 * Return code
2970 * 0 - No retry of els command is made
2971 * 1 - Immediate or delayed retry of els command is made
2972 **/
dea31012005-04-17 16:05:31 -05002973static int
James Smart2e0fef82007-06-17 19:56:36 -05002974lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2975 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002976{
James Smart2e0fef82007-06-17 19:56:36 -05002977 struct lpfc_vport *vport = cmdiocb->vport;
2978 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2979 IOCB_t *irsp = &rspiocb->iocb;
2980 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2981 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002982 uint32_t *elscmd;
2983 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002984 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002985 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002986 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002987 uint32_t did;
dea31012005-04-17 16:05:31 -05002988
James Smart488d1462006-03-07 15:02:37 -05002989
dea31012005-04-17 16:05:31 -05002990 /* Note: context2 may be 0 for internal driver abort
2991 * of delays ELS command.
2992 */
2993
2994 if (pcmd && pcmd->virt) {
2995 elscmd = (uint32_t *) (pcmd->virt);
2996 cmd = *elscmd++;
2997 }
2998
James Smarte47c9092008-02-08 18:49:26 -05002999 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05003000 did = ndlp->nlp_DID;
3001 else {
3002 /* We should only hit this case for retrying PLOGI */
3003 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003004 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05003005 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3006 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05003007 return 1;
3008 }
3009
James Smart858c9f62007-06-17 19:56:39 -05003010 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3011 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3012 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3013
dea31012005-04-17 16:05:31 -05003014 switch (irsp->ulpStatus) {
3015 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05003016 break;
James Smart1151e3e2011-02-16 12:39:35 -05003017 case IOSTAT_REMOTE_STOP:
3018 if (phba->sli_rev == LPFC_SLI_REV4) {
3019 /* This IO was aborted by the target, we don't
3020 * know the rxid and because we did not send the
3021 * ABTS we cannot generate and RRQ.
3022 */
3023 lpfc_set_rrq_active(phba, ndlp,
James Smartee0f4fe2012-05-09 21:19:14 -04003024 cmdiocb->sli4_lxritag, 0, 0);
James Smart1151e3e2011-02-16 12:39:35 -05003025 }
3026 break;
dea31012005-04-17 16:05:31 -05003027 case IOSTAT_LOCAL_REJECT:
3028 switch ((irsp->un.ulpWord[4] & 0xff)) {
3029 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05003030 if (cmd == ELS_CMD_FLOGI) {
3031 if (PCI_DEVICE_ID_HORNET ==
3032 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05003033 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05003034 phba->pport->fc_myDID = 0;
3035 phba->alpa_map[0] = 0;
3036 phba->alpa_map[1] = 0;
3037 }
3038 }
James Smart2e0fef82007-06-17 19:56:36 -05003039 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003040 delay = 1000;
dea31012005-04-17 16:05:31 -05003041 retry = 1;
3042 break;
3043
James Smart92d7f7b2007-06-17 19:56:38 -05003044 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05003045 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3046 "0124 Retry illegal cmd x%x "
3047 "retry:x%x delay:x%x\n",
3048 cmd, cmdiocb->retry, delay);
3049 retry = 1;
3050 /* All command's retry policy */
3051 maxretry = 8;
3052 if (cmdiocb->retry > 2)
3053 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05003054 break;
3055
dea31012005-04-17 16:05:31 -05003056 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04003057 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05003058 retry = 1;
3059 if (cmdiocb->retry > 100)
3060 delay = 100;
3061 maxretry = 250;
3062 break;
3063
3064 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05003065 delay = 100;
dea31012005-04-17 16:05:31 -05003066 retry = 1;
3067 break;
3068
James Smart858c9f62007-06-17 19:56:39 -05003069 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05003070 case IOERR_INVALID_RPI:
3071 retry = 1;
3072 break;
3073 }
3074 break;
3075
3076 case IOSTAT_NPORT_RJT:
3077 case IOSTAT_FABRIC_RJT:
3078 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3079 retry = 1;
3080 break;
3081 }
3082 break;
3083
3084 case IOSTAT_NPORT_BSY:
3085 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04003086 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05003087 retry = 1;
3088 break;
3089
3090 case IOSTAT_LS_RJT:
3091 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3092 /* Added for Vendor specifc support
3093 * Just keep retrying for these Rsn / Exp codes
3094 */
3095 switch (stat.un.b.lsRjtRsnCode) {
3096 case LSRJT_UNABLE_TPC:
3097 if (stat.un.b.lsRjtRsnCodeExp ==
3098 LSEXP_CMD_IN_PROGRESS) {
3099 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003100 delay = 1000;
dea31012005-04-17 16:05:31 -05003101 maxretry = 48;
3102 }
3103 retry = 1;
3104 break;
3105 }
James Smartffc95492010-06-07 15:23:17 -04003106 if (stat.un.b.lsRjtRsnCodeExp ==
3107 LSEXP_CANT_GIVE_DATA) {
3108 if (cmd == ELS_CMD_PLOGI) {
3109 delay = 1000;
3110 maxretry = 48;
3111 }
3112 retry = 1;
3113 break;
3114 }
dea31012005-04-17 16:05:31 -05003115 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003116 delay = 1000;
dea31012005-04-17 16:05:31 -05003117 maxretry = lpfc_max_els_tries + 1;
3118 retry = 1;
3119 break;
3120 }
James Smart92d7f7b2007-06-17 19:56:38 -05003121 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3122 (cmd == ELS_CMD_FDISC) &&
3123 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003124 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3125 "0125 FDISC Failed (x%x). "
3126 "Fabric out of resources\n",
3127 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003128 lpfc_vport_set_state(vport,
3129 FC_VPORT_NO_FABRIC_RSCS);
3130 }
dea31012005-04-17 16:05:31 -05003131 break;
3132
3133 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003134 if ((cmd == ELS_CMD_PLOGI) ||
3135 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003136 delay = 1000;
dea31012005-04-17 16:05:31 -05003137 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003138 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003139 /* FDISC retry policy */
3140 maxretry = 48;
3141 if (cmdiocb->retry >= 32)
3142 delay = 1000;
dea31012005-04-17 16:05:31 -05003143 }
3144 retry = 1;
3145 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003146
3147 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003148 /* There are some cases where switches return this
3149 * error when they are not ready and should be returning
3150 * Logical Busy. We should delay every time.
3151 */
3152 if (cmd == ELS_CMD_FDISC &&
3153 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3154 maxretry = 3;
3155 delay = 1000;
3156 retry = 1;
3157 break;
3158 }
James Smart92d7f7b2007-06-17 19:56:38 -05003159 case LSRJT_PROTOCOL_ERR:
3160 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3161 (cmd == ELS_CMD_FDISC) &&
3162 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3163 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3164 ) {
James Smarte8b62012007-08-02 11:10:09 -04003165 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003166 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003167 "Fabric Detected Bad WWN\n",
3168 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003169 lpfc_vport_set_state(vport,
3170 FC_VPORT_FABRIC_REJ_WWN);
3171 }
3172 break;
dea31012005-04-17 16:05:31 -05003173 }
3174 break;
3175
3176 case IOSTAT_INTERMED_RSP:
3177 case IOSTAT_BA_RJT:
3178 break;
3179
3180 default:
3181 break;
3182 }
3183
James Smart488d1462006-03-07 15:02:37 -05003184 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003185 retry = 1;
dea31012005-04-17 16:05:31 -05003186
James Smartdf9e1b52011-12-13 13:22:17 -05003187 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05003188 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003189 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003190 /* FLOGI retry policy */
3191 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05003192 /* retry FLOGI forever */
James Smart6669f9b2009-10-02 15:16:45 -04003193 maxretry = 0;
3194 if (cmdiocb->retry >= 100)
3195 delay = 5000;
3196 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003197 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05003198 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3199 /* retry FDISCs every second up to devloss */
3200 retry = 1;
3201 maxretry = vport->cfg_devloss_tmo;
3202 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04003203 }
3204
James Smart6669f9b2009-10-02 15:16:45 -04003205 cmdiocb->retry++;
3206 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003207 phba->fc_stat.elsRetryExceeded++;
3208 retry = 0;
3209 }
3210
James Smarted957682007-06-17 19:56:37 -05003211 if ((vport->load_flag & FC_UNLOADING) != 0)
3212 retry = 0;
3213
dea31012005-04-17 16:05:31 -05003214 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003215 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3216 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3217 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3218 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3219 "2849 Stop retry ELS command "
3220 "x%x to remote NPORT x%x, "
3221 "Data: x%x x%x\n", cmd, did,
3222 cmdiocb->retry, delay);
3223 return 0;
3224 }
3225 }
dea31012005-04-17 16:05:31 -05003226
3227 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003228 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3229 "0107 Retry ELS command x%x to remote "
3230 "NPORT x%x Data: x%x x%x\n",
3231 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003232
James Smart858c9f62007-06-17 19:56:39 -05003233 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3234 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3235 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
3236 /* Don't reset timer for no resources */
3237
dea31012005-04-17 16:05:31 -05003238 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003239 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003240 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003241 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003242 }
3243
3244 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003245 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003246 phba->fc_stat.elsDelayRetry++;
3247 ndlp->nlp_retry = cmdiocb->retry;
3248
James Smart92d7f7b2007-06-17 19:56:38 -05003249 /* delay is specified in milliseconds */
3250 mod_timer(&ndlp->nlp_delayfunc,
3251 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003252 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003253 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003254 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003255
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003256 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003257 if (cmd == ELS_CMD_PRLI)
3258 lpfc_nlp_set_state(vport, ndlp,
3259 NLP_STE_REG_LOGIN_ISSUE);
3260 else
3261 lpfc_nlp_set_state(vport, ndlp,
3262 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003263 ndlp->nlp_last_elscmd = cmd;
3264
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003265 return 1;
dea31012005-04-17 16:05:31 -05003266 }
3267 switch (cmd) {
3268 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003269 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003270 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003271 case ELS_CMD_FDISC:
3272 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3273 return 1;
dea31012005-04-17 16:05:31 -05003274 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003275 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003276 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003277 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003278 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003279 }
James Smart2e0fef82007-06-17 19:56:36 -05003280 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003281 return 1;
dea31012005-04-17 16:05:31 -05003282 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003283 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003284 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3285 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003286 return 1;
dea31012005-04-17 16:05:31 -05003287 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003288 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003289 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3290 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003291 return 1;
dea31012005-04-17 16:05:31 -05003292 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003293 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003294 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3295 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003296 return 1;
dea31012005-04-17 16:05:31 -05003297 }
3298 }
dea31012005-04-17 16:05:31 -05003299 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003300 if (logerr) {
3301 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3302 "0137 No retry ELS command x%x to remote "
3303 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3304 cmd, did, irsp->ulpStatus,
3305 irsp->un.ulpWord[4]);
3306 }
3307 else {
3308 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003309 "0108 No retry ELS command x%x to remote "
3310 "NPORT x%x Retried:%d Error:x%x/%x\n",
3311 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3312 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003313 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003314 return 0;
dea31012005-04-17 16:05:31 -05003315}
3316
James Smarte59058c2008-08-24 21:49:00 -04003317/**
James Smart3621a712009-04-06 18:47:14 -04003318 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003319 * @phba: pointer to lpfc hba data structure.
3320 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3321 *
3322 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3323 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3324 * checks to see whether there is a lpfc DMA buffer associated with the
3325 * response of the command IOCB. If so, it will be released before releasing
3326 * the lpfc DMA buffer associated with the IOCB itself.
3327 *
3328 * Return code
3329 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3330 **/
James Smart09372822008-01-11 01:52:54 -05003331static int
James Smart87af33f2007-10-27 13:37:43 -04003332lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3333{
3334 struct lpfc_dmabuf *buf_ptr;
3335
James Smarte59058c2008-08-24 21:49:00 -04003336 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003337 if (!list_empty(&buf_ptr1->list)) {
3338 list_remove_head(&buf_ptr1->list, buf_ptr,
3339 struct lpfc_dmabuf,
3340 list);
3341 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3342 kfree(buf_ptr);
3343 }
3344 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3345 kfree(buf_ptr1);
3346 return 0;
3347}
3348
James Smarte59058c2008-08-24 21:49:00 -04003349/**
James Smart3621a712009-04-06 18:47:14 -04003350 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003351 * @phba: pointer to lpfc hba data structure.
3352 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3353 *
3354 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3355 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3356 * pool.
3357 *
3358 * Return code
3359 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3360 **/
James Smart09372822008-01-11 01:52:54 -05003361static int
James Smart87af33f2007-10-27 13:37:43 -04003362lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3363{
3364 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3365 kfree(buf_ptr);
3366 return 0;
3367}
3368
James Smarte59058c2008-08-24 21:49:00 -04003369/**
James Smart3621a712009-04-06 18:47:14 -04003370 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003371 * @phba: pointer to lpfc hba data structure.
3372 * @elsiocb: pointer to lpfc els command iocb data structure.
3373 *
3374 * This routine frees a command IOCB and its associated resources. The
3375 * command IOCB data structure contains the reference to various associated
3376 * resources, these fields must be set to NULL if the associated reference
3377 * not present:
3378 * context1 - reference to ndlp
3379 * context2 - reference to cmd
3380 * context2->next - reference to rsp
3381 * context3 - reference to bpl
3382 *
3383 * It first properly decrements the reference count held on ndlp for the
3384 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3385 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3386 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3387 * adds the DMA buffer the @phba data structure for the delayed release.
3388 * If reference to the Buffer Pointer List (BPL) is present, the
3389 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3390 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3391 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3392 *
3393 * Return code
3394 * 0 - Success (currently, always return 0)
3395 **/
James Smart87af33f2007-10-27 13:37:43 -04003396int
James Smart329f9bc2007-04-25 09:53:01 -04003397lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003398{
3399 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003400 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003401
James Smarta8adb832007-10-27 13:37:53 -04003402 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3403 if (ndlp) {
3404 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3405 lpfc_nlp_put(ndlp);
3406
3407 /* If the ndlp is not being used by another discovery
3408 * thread, free it.
3409 */
3410 if (!lpfc_nlp_not_used(ndlp)) {
3411 /* If ndlp is being used by another discovery
3412 * thread, just clear NLP_DEFER_RM
3413 */
3414 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3415 }
3416 }
3417 else
3418 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003419 elsiocb->context1 = NULL;
3420 }
dea31012005-04-17 16:05:31 -05003421 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3422 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003423 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3424 /* Firmware could still be in progress of DMAing
3425 * payload, so don't free data buffer till after
3426 * a hbeat.
3427 */
3428 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3429 buf_ptr = elsiocb->context2;
3430 elsiocb->context2 = NULL;
3431 if (buf_ptr) {
3432 buf_ptr1 = NULL;
3433 spin_lock_irq(&phba->hbalock);
3434 if (!list_empty(&buf_ptr->list)) {
3435 list_remove_head(&buf_ptr->list,
3436 buf_ptr1, struct lpfc_dmabuf,
3437 list);
3438 INIT_LIST_HEAD(&buf_ptr1->list);
3439 list_add_tail(&buf_ptr1->list,
3440 &phba->elsbuf);
3441 phba->elsbuf_cnt++;
3442 }
3443 INIT_LIST_HEAD(&buf_ptr->list);
3444 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3445 phba->elsbuf_cnt++;
3446 spin_unlock_irq(&phba->hbalock);
3447 }
3448 } else {
3449 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3450 lpfc_els_free_data(phba, buf_ptr1);
3451 }
dea31012005-04-17 16:05:31 -05003452 }
3453
3454 if (elsiocb->context3) {
3455 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003456 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003457 }
James Bottomley604a3e32005-10-29 10:28:33 -05003458 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003459 return 0;
3460}
3461
James Smarte59058c2008-08-24 21:49:00 -04003462/**
James Smart3621a712009-04-06 18:47:14 -04003463 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003464 * @phba: pointer to lpfc hba data structure.
3465 * @cmdiocb: pointer to lpfc command iocb data structure.
3466 * @rspiocb: pointer to lpfc response iocb data structure.
3467 *
3468 * This routine is the completion callback function to the Logout (LOGO)
3469 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3470 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3471 * release the ndlp if it has the last reference remaining (reference count
3472 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3473 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3474 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3475 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3476 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3477 * IOCB data structure.
3478 **/
dea31012005-04-17 16:05:31 -05003479static void
James Smart2e0fef82007-06-17 19:56:36 -05003480lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3481 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003482{
James Smart2e0fef82007-06-17 19:56:36 -05003483 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3484 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003485 IOCB_t *irsp;
3486
3487 irsp = &rspiocb->iocb;
3488 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3489 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3490 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003491 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003492 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3493 "0109 ACC to LOGO completes to NPort x%x "
3494 "Data: x%x x%x x%x\n",
3495 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3496 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003497
3498 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3499 /* NPort Recovery mode or node is just allocated */
3500 if (!lpfc_nlp_not_used(ndlp)) {
3501 /* If the ndlp is being used by another discovery
3502 * thread, just unregister the RPI.
3503 */
3504 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003505 } else {
3506 /* Indicate the node has already released, should
3507 * not reference to it from within lpfc_els_free_iocb.
3508 */
3509 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003510 }
dea31012005-04-17 16:05:31 -05003511 }
James Smart73d91e52011-10-10 21:32:10 -04003512
3513 /*
3514 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05003515 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04003516 */
dea31012005-04-17 16:05:31 -05003517 lpfc_els_free_iocb(phba, cmdiocb);
James Smartdf9e1b52011-12-13 13:22:17 -05003518
3519 /*
3520 * Remove the ndlp reference if it's a fabric node that has
3521 * sent us an unsolicted LOGO.
3522 */
3523 if (ndlp->nlp_type & NLP_FABRIC)
3524 lpfc_nlp_put(ndlp);
3525
dea31012005-04-17 16:05:31 -05003526 return;
3527}
3528
James Smarte59058c2008-08-24 21:49:00 -04003529/**
James Smart3621a712009-04-06 18:47:14 -04003530 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003531 * @phba: pointer to lpfc hba data structure.
3532 * @pmb: pointer to the driver internal queue element for mailbox command.
3533 *
3534 * This routine is the completion callback function for unregister default
3535 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3536 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3537 * decrements the ndlp reference count held for this completion callback
3538 * function. After that, it invokes the lpfc_nlp_not_used() to check
3539 * whether there is only one reference left on the ndlp. If so, it will
3540 * perform one more decrement and trigger the release of the ndlp.
3541 **/
James Smart858c9f62007-06-17 19:56:39 -05003542void
3543lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3544{
3545 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3546 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3547
3548 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003549 pmb->context2 = NULL;
3550
James Smart858c9f62007-06-17 19:56:39 -05003551 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3552 kfree(mp);
3553 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003554 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003555 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003556 /* This is the end of the default RPI cleanup logic for this
3557 * ndlp. If no other discovery threads are using this ndlp.
3558 * we should free all resources associated with it.
3559 */
3560 lpfc_nlp_not_used(ndlp);
3561 }
James Smart3772a992009-05-22 14:50:54 -04003562
James Smart858c9f62007-06-17 19:56:39 -05003563 return;
3564}
3565
James Smarte59058c2008-08-24 21:49:00 -04003566/**
James Smart3621a712009-04-06 18:47:14 -04003567 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003568 * @phba: pointer to lpfc hba data structure.
3569 * @cmdiocb: pointer to lpfc command iocb data structure.
3570 * @rspiocb: pointer to lpfc response iocb data structure.
3571 *
3572 * This routine is the completion callback function for ELS Response IOCB
3573 * command. In normal case, this callback function just properly sets the
3574 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3575 * field in the command IOCB is not NULL, the referred mailbox command will
3576 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3577 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3578 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3579 * routine shall be invoked trying to release the ndlp if no other threads
3580 * are currently referring it.
3581 **/
dea31012005-04-17 16:05:31 -05003582static void
James Smart858c9f62007-06-17 19:56:39 -05003583lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003584 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003585{
James Smart2e0fef82007-06-17 19:56:36 -05003586 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3587 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3588 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003589 IOCB_t *irsp;
3590 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003591 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003592 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003593 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003594
James Smart33ccf8d2006-08-17 11:57:58 -04003595 irsp = &rspiocb->iocb;
3596
dea31012005-04-17 16:05:31 -05003597 if (cmdiocb->context_un.mbox)
3598 mbox = cmdiocb->context_un.mbox;
3599
James Smartfa4066b2008-01-11 01:53:27 -05003600 /* First determine if this is a LS_RJT cmpl. Note, this callback
3601 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3602 */
James Smart87af33f2007-10-27 13:37:43 -04003603 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003604 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3605 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003606 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003607 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003608 */
3609 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3610 ls_rjt = 1;
3611 }
3612
dea31012005-04-17 16:05:31 -05003613 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003614 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003615 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003616 mp = (struct lpfc_dmabuf *) mbox->context1;
3617 if (mp) {
3618 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3619 kfree(mp);
3620 }
James Smart329f9bc2007-04-25 09:53:01 -04003621 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003622 }
James Smart58da1ff2008-04-07 10:15:56 -04003623 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3624 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003625 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003626 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003627 /* Indicate the node has already released,
3628 * should not reference to it from within
3629 * the routine lpfc_els_free_iocb.
3630 */
3631 cmdiocb->context1 = NULL;
3632 }
dea31012005-04-17 16:05:31 -05003633 goto out;
3634 }
3635
James Smart858c9f62007-06-17 19:56:39 -05003636 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003637 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003638 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003639 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003640 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003641 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3642 "0110 ELS response tag x%x completes "
3643 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3644 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3645 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3646 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3647 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003648 if (mbox) {
3649 if ((rspiocb->iocb.ulpStatus == 0)
3650 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003651 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003652 /* Increment reference count to ndlp to hold the
3653 * reference to ndlp for the callback function.
3654 */
James Smart329f9bc2007-04-25 09:53:01 -04003655 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003656 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003657 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3658 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3659 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3660 }
3661 else {
3662 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3663 ndlp->nlp_prev_state = ndlp->nlp_state;
3664 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003665 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003666 }
James Smart0b727fe2007-10-27 13:37:25 -04003667 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003668 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003669 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003670 else
3671 /* Decrement the ndlp reference count we
3672 * set for this failed mailbox command.
3673 */
3674 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003675
3676 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3677 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3678 "0138 ELS rsp: Cannot issue reg_login for x%x "
3679 "Data: x%x x%x x%x\n",
3680 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3681 ndlp->nlp_rpi);
3682
James Smartfa4066b2008-01-11 01:53:27 -05003683 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003684 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003685 /* Indicate node has already been released,
3686 * should not reference to it from within
3687 * the routine lpfc_els_free_iocb.
3688 */
3689 cmdiocb->context1 = NULL;
3690 }
dea31012005-04-17 16:05:31 -05003691 } else {
James Smart858c9f62007-06-17 19:56:39 -05003692 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3693 if (!lpfc_error_lost_link(irsp) &&
3694 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003695 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003696 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003697 /* Indicate node has already been
3698 * released, should not reference
3699 * to it from within the routine
3700 * lpfc_els_free_iocb.
3701 */
3702 cmdiocb->context1 = NULL;
3703 }
dea31012005-04-17 16:05:31 -05003704 }
3705 }
James Smart14691152006-12-02 13:34:28 -05003706 mp = (struct lpfc_dmabuf *) mbox->context1;
3707 if (mp) {
3708 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3709 kfree(mp);
3710 }
3711 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003712 }
3713out:
James Smart58da1ff2008-04-07 10:15:56 -04003714 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003715 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003716 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003717 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003718
3719 /* If the node is not being used by another discovery thread,
3720 * and we are sending a reject, we are done with it.
3721 * Release driver reference count here and free associated
3722 * resources.
3723 */
3724 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003725 if (lpfc_nlp_not_used(ndlp))
3726 /* Indicate node has already been released,
3727 * should not reference to it from within
3728 * the routine lpfc_els_free_iocb.
3729 */
3730 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003731 }
James Smart87af33f2007-10-27 13:37:43 -04003732
dea31012005-04-17 16:05:31 -05003733 lpfc_els_free_iocb(phba, cmdiocb);
3734 return;
3735}
3736
James Smarte59058c2008-08-24 21:49:00 -04003737/**
James Smart3621a712009-04-06 18:47:14 -04003738 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003739 * @vport: pointer to a host virtual N_Port data structure.
3740 * @flag: the els command code to be accepted.
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 issues an Accept (ACC) response IOCB
3746 * command. It uses the @flag to properly set up the IOCB field for the
3747 * specific ACC response command to be issued and invokes the
3748 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3749 * @mbox pointer is passed in, it will be put into the context_un.mbox
3750 * field of the IOCB for the completion callback function to issue the
3751 * mailbox command to the HBA later when callback is invoked.
3752 *
3753 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3754 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3755 * will be stored into the context1 field of the IOCB for the completion
3756 * callback function to the corresponding response ELS IOCB command.
3757 *
3758 * Return code
3759 * 0 - Successfully issued acc response
3760 * 1 - Failed to issue acc response
3761 **/
dea31012005-04-17 16:05:31 -05003762int
James Smart2e0fef82007-06-17 19:56:36 -05003763lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3764 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003765 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003766{
James Smart2e0fef82007-06-17 19:56:36 -05003767 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3768 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003769 IOCB_t *icmd;
3770 IOCB_t *oldcmd;
3771 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003772 struct lpfc_sli *psli;
3773 uint8_t *pcmd;
3774 uint16_t cmdsize;
3775 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003776 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003777
3778 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003779 oldcmd = &oldiocb->iocb;
3780
3781 switch (flag) {
3782 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003783 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003784 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3785 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003786 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003787 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003788 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003789 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003790 return 1;
dea31012005-04-17 16:05:31 -05003791 }
James Smart2e0fef82007-06-17 19:56:36 -05003792
dea31012005-04-17 16:05:31 -05003793 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003794 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3795 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003796 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3797 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003798 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003799
3800 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3801 "Issue ACC: did:x%x flg:x%x",
3802 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003803 break;
3804 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003805 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003806 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3807 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003808 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003809 return 1;
James Smart488d1462006-03-07 15:02:37 -05003810
dea31012005-04-17 16:05:31 -05003811 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003812 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3813 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003814 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3815
3816 if (mbox)
3817 elsiocb->context_un.mbox = mbox;
3818
3819 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003820 pcmd += sizeof(uint32_t);
3821 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003822
3823 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3824 "Issue ACC PLOGI: did:x%x flg:x%x",
3825 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003826 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003827 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003828 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003829 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003830 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3831 if (!elsiocb)
3832 return 1;
3833
3834 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003835 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3836 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04003837 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3838
3839 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003840 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003841 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3842 els_pkt_ptr = (ELS_PKT *) pcmd;
3843 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003844
3845 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3846 "Issue ACC PRLO: did:x%x flg:x%x",
3847 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003848 break;
dea31012005-04-17 16:05:31 -05003849 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003850 return 1;
dea31012005-04-17 16:05:31 -05003851 }
dea31012005-04-17 16:05:31 -05003852 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003853 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3854 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
James Smarte6446432012-05-09 21:16:42 -04003855 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
3856 "fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003857 elsiocb->iotag, elsiocb->iocb.ulpContext,
3858 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
James Smarte6446432012-05-09 21:16:42 -04003859 ndlp->nlp_rpi, vport->fc_flag);
dea31012005-04-17 16:05:31 -05003860 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003861 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003862 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003863 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003864 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3865 } else {
James Smart858c9f62007-06-17 19:56:39 -05003866 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003867 }
3868
3869 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003870 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003871 if (rc == IOCB_ERROR) {
3872 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003873 return 1;
dea31012005-04-17 16:05:31 -05003874 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003875 return 0;
dea31012005-04-17 16:05:31 -05003876}
3877
James Smarte59058c2008-08-24 21:49:00 -04003878/**
James Smart3621a712009-04-06 18:47:14 -04003879 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003880 * @vport: pointer to a virtual N_Port data structure.
3881 * @rejectError:
3882 * @oldiocb: pointer to the original lpfc command iocb data structure.
3883 * @ndlp: pointer to a node-list data structure.
3884 * @mbox: pointer to the driver internal queue element for mailbox command.
3885 *
3886 * This routine prepares and issue an Reject (RJT) response IOCB
3887 * command. If a @mbox pointer is passed in, it will be put into the
3888 * context_un.mbox field of the IOCB for the completion callback function
3889 * to issue to the HBA later.
3890 *
3891 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3892 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3893 * will be stored into the context1 field of the IOCB for the completion
3894 * callback function to the reject response ELS IOCB command.
3895 *
3896 * Return code
3897 * 0 - Successfully issued reject response
3898 * 1 - Failed to issue reject response
3899 **/
dea31012005-04-17 16:05:31 -05003900int
James Smart2e0fef82007-06-17 19:56:36 -05003901lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003902 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3903 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003904{
James Smart2e0fef82007-06-17 19:56:36 -05003905 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003906 IOCB_t *icmd;
3907 IOCB_t *oldcmd;
3908 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003909 struct lpfc_sli *psli;
3910 uint8_t *pcmd;
3911 uint16_t cmdsize;
3912 int rc;
3913
3914 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003915 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003916 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3917 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003918 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003919 return 1;
dea31012005-04-17 16:05:31 -05003920
3921 icmd = &elsiocb->iocb;
3922 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003923 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3924 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003925 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3926
3927 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003928 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003929 *((uint32_t *) (pcmd)) = rejectError;
3930
James Smart51ef4c22007-08-02 11:10:31 -04003931 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003932 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003933
dea31012005-04-17 16:05:31 -05003934 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003935 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3936 "0129 Xmit ELS RJT x%x response tag x%x "
3937 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3938 "rpi x%x\n",
3939 rejectError, elsiocb->iotag,
3940 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3941 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003942 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3943 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3944 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3945
dea31012005-04-17 16:05:31 -05003946 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003947 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003948 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003949
dea31012005-04-17 16:05:31 -05003950 if (rc == IOCB_ERROR) {
3951 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003952 return 1;
dea31012005-04-17 16:05:31 -05003953 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003954 return 0;
dea31012005-04-17 16:05:31 -05003955}
3956
James Smarte59058c2008-08-24 21:49:00 -04003957/**
James Smart3621a712009-04-06 18:47:14 -04003958 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003959 * @vport: pointer to a virtual N_Port data structure.
3960 * @oldiocb: pointer to the original lpfc command iocb data structure.
3961 * @ndlp: pointer to a node-list data structure.
3962 *
3963 * This routine prepares and issues an Accept (ACC) response to Address
3964 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3965 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3966 *
3967 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3968 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3969 * will be stored into the context1 field of the IOCB for the completion
3970 * callback function to the ADISC Accept response ELS IOCB command.
3971 *
3972 * Return code
3973 * 0 - Successfully issued acc adisc response
3974 * 1 - Failed to issue adisc acc response
3975 **/
dea31012005-04-17 16:05:31 -05003976int
James Smart2e0fef82007-06-17 19:56:36 -05003977lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3978 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003979{
James Smart2e0fef82007-06-17 19:56:36 -05003980 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003981 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003982 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003983 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003984 uint8_t *pcmd;
3985 uint16_t cmdsize;
3986 int rc;
3987
James Smart92d7f7b2007-06-17 19:56:38 -05003988 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003989 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3990 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003991 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003992 return 1;
dea31012005-04-17 16:05:31 -05003993
dea31012005-04-17 16:05:31 -05003994 icmd = &elsiocb->iocb;
3995 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003996 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3997 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04003998
3999 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004000 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4001 "0130 Xmit ADISC ACC response iotag x%x xri: "
4002 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4003 elsiocb->iotag, elsiocb->iocb.ulpContext,
4004 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4005 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004006 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4007
4008 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004009 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004010
4011 ap = (ADISC *) (pcmd);
4012 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05004013 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4014 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05004015 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05004016
James Smart858c9f62007-06-17 19:56:39 -05004017 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4018 "Issue ACC ADISC: did:x%x flg:x%x",
4019 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4020
dea31012005-04-17 16:05:31 -05004021 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004022 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004023 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004024 if (rc == IOCB_ERROR) {
4025 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004026 return 1;
dea31012005-04-17 16:05:31 -05004027 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004028 return 0;
dea31012005-04-17 16:05:31 -05004029}
4030
James Smarte59058c2008-08-24 21:49:00 -04004031/**
James Smart3621a712009-04-06 18:47:14 -04004032 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004033 * @vport: pointer to a virtual N_Port data structure.
4034 * @oldiocb: pointer to the original lpfc command iocb data structure.
4035 * @ndlp: pointer to a node-list data structure.
4036 *
4037 * This routine prepares and issues an Accept (ACC) response to Process
4038 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4039 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4040 *
4041 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4042 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4043 * will be stored into the context1 field of the IOCB for the completion
4044 * callback function to the PRLI Accept response ELS IOCB command.
4045 *
4046 * Return code
4047 * 0 - Successfully issued acc prli response
4048 * 1 - Failed to issue acc prli response
4049 **/
dea31012005-04-17 16:05:31 -05004050int
James Smart2e0fef82007-06-17 19:56:36 -05004051lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04004052 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004053{
James Smart2e0fef82007-06-17 19:56:36 -05004054 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004055 PRLI *npr;
4056 lpfc_vpd_t *vpd;
4057 IOCB_t *icmd;
4058 IOCB_t *oldcmd;
4059 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004060 struct lpfc_sli *psli;
4061 uint8_t *pcmd;
4062 uint16_t cmdsize;
4063 int rc;
4064
4065 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05004066
James Smart92d7f7b2007-06-17 19:56:38 -05004067 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05004068 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05004069 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004070 if (!elsiocb)
4071 return 1;
dea31012005-04-17 16:05:31 -05004072
dea31012005-04-17 16:05:31 -05004073 icmd = &elsiocb->iocb;
4074 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004075 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4076 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4077
James Smart5b8bd0c2007-04-25 09:52:49 -04004078 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004079 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4080 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4081 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4082 elsiocb->iotag, elsiocb->iocb.ulpContext,
4083 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4084 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004085 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4086
4087 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05004088 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004089
4090 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05004091 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05004092
4093 npr = (PRLI *) pcmd;
4094 vpd = &phba->vpd;
4095 /*
James Smart0d2b6b82008-06-14 22:52:47 -04004096 * If the remote port is a target and our firmware version is 3.20 or
4097 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05004098 */
James Smart0d2b6b82008-06-14 22:52:47 -04004099 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4100 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05004101 npr->ConfmComplAllowed = 1;
4102 npr->Retry = 1;
4103 npr->TaskRetryIdReq = 1;
4104 }
4105
4106 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4107 npr->estabImagePair = 1;
4108 npr->readXferRdyDis = 1;
4109 npr->ConfmComplAllowed = 1;
4110
4111 npr->prliType = PRLI_FCP_TYPE;
4112 npr->initiatorFunc = 1;
4113
James Smart858c9f62007-06-17 19:56:39 -05004114 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4115 "Issue ACC PRLI: did:x%x flg:x%x",
4116 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4117
dea31012005-04-17 16:05:31 -05004118 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004119 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004120
James Smart3772a992009-05-22 14:50:54 -04004121 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004122 if (rc == IOCB_ERROR) {
4123 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004124 return 1;
dea31012005-04-17 16:05:31 -05004125 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004126 return 0;
dea31012005-04-17 16:05:31 -05004127}
4128
James Smarte59058c2008-08-24 21:49:00 -04004129/**
James Smart3621a712009-04-06 18:47:14 -04004130 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004131 * @vport: pointer to a virtual N_Port data structure.
4132 * @format: rnid command format.
4133 * @oldiocb: pointer to the original lpfc command iocb data structure.
4134 * @ndlp: pointer to a node-list data structure.
4135 *
4136 * This routine issues a Request Node Identification Data (RNID) Accept
4137 * (ACC) response. It constructs the RNID ACC response command according to
4138 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4139 * issue the response. Note that this command does not need to hold the ndlp
4140 * reference count for the callback. So, the ndlp reference count taken by
4141 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4142 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4143 * there is no ndlp reference available.
4144 *
4145 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4146 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4147 * will be stored into the context1 field of the IOCB for the completion
4148 * callback function. However, for the RNID Accept Response ELS command,
4149 * this is undone later by this routine after the IOCB is allocated.
4150 *
4151 * Return code
4152 * 0 - Successfully issued acc rnid response
4153 * 1 - Failed to issue acc rnid response
4154 **/
dea31012005-04-17 16:05:31 -05004155static int
James Smart2e0fef82007-06-17 19:56:36 -05004156lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004157 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004158{
James Smart2e0fef82007-06-17 19:56:36 -05004159 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004160 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004161 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004162 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004163 struct lpfc_sli *psli;
4164 uint8_t *pcmd;
4165 uint16_t cmdsize;
4166 int rc;
4167
4168 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004169 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4170 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004171 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004172 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004173
James Smart2e0fef82007-06-17 19:56:36 -05004174 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4175 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004176 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004177 return 1;
dea31012005-04-17 16:05:31 -05004178
dea31012005-04-17 16:05:31 -05004179 icmd = &elsiocb->iocb;
4180 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004181 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4182 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4183
James Smart5b8bd0c2007-04-25 09:52:49 -04004184 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004185 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4186 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4187 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004188 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004189 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004190 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004191
James Smart92d7f7b2007-06-17 19:56:38 -05004192 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004193 rn = (RNID *) (pcmd);
4194 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004195 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4196 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4197 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004198 switch (format) {
4199 case 0:
4200 rn->SpecificLen = 0;
4201 break;
4202 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004203 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004204 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004205 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004206 rn->un.topologyDisc.unitType = RNID_HBA;
4207 rn->un.topologyDisc.physPort = 0;
4208 rn->un.topologyDisc.attachedNodes = 0;
4209 break;
4210 default:
4211 rn->CommonLen = 0;
4212 rn->SpecificLen = 0;
4213 break;
4214 }
4215
James Smart858c9f62007-06-17 19:56:39 -05004216 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4217 "Issue ACC RNID: did:x%x flg:x%x",
4218 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4219
dea31012005-04-17 16:05:31 -05004220 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004221 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004222
James Smart3772a992009-05-22 14:50:54 -04004223 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004224 if (rc == IOCB_ERROR) {
4225 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004226 return 1;
dea31012005-04-17 16:05:31 -05004227 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004228 return 0;
dea31012005-04-17 16:05:31 -05004229}
4230
James Smarte59058c2008-08-24 21:49:00 -04004231/**
James Smart19ca7602010-11-20 23:11:55 -05004232 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4233 * @vport: pointer to a virtual N_Port data structure.
4234 * @iocb: pointer to the lpfc command iocb data structure.
4235 * @ndlp: pointer to a node-list data structure.
4236 *
4237 * Return
4238 **/
4239static void
4240lpfc_els_clear_rrq(struct lpfc_vport *vport,
4241 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4242{
4243 struct lpfc_hba *phba = vport->phba;
4244 uint8_t *pcmd;
4245 struct RRQ *rrq;
4246 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004247 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004248 struct lpfc_node_rrq *prrq;
4249
4250
4251 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4252 pcmd += sizeof(uint32_t);
4253 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004254 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b062011-04-16 11:03:17 -04004255 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004256
4257 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4258 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4259 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004260 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b062011-04-16 11:03:17 -04004261 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004262 rxid,
4263 iocb->iotag, iocb->iocb.ulpContext);
4264
4265 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4266 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4267 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004268 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b062011-04-16 11:03:17 -04004269 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004270 else
4271 xri = rxid;
4272 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004273 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004274 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004275 return;
4276}
4277
4278/**
James Smart12265f62010-10-22 11:05:53 -04004279 * lpfc_els_rsp_echo_acc - Issue echo acc response
4280 * @vport: pointer to a virtual N_Port data structure.
4281 * @data: pointer to echo data to return in the accept.
4282 * @oldiocb: pointer to the original lpfc command iocb data structure.
4283 * @ndlp: pointer to a node-list data structure.
4284 *
4285 * Return code
4286 * 0 - Successfully issued acc echo response
4287 * 1 - Failed to issue acc echo response
4288 **/
4289static int
4290lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4291 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4292{
4293 struct lpfc_hba *phba = vport->phba;
4294 struct lpfc_iocbq *elsiocb;
4295 struct lpfc_sli *psli;
4296 uint8_t *pcmd;
4297 uint16_t cmdsize;
4298 int rc;
4299
4300 psli = &phba->sli;
4301 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4302
James Smartbf086112011-08-21 21:48:13 -04004303 /* The accumulated length can exceed the BPL_SIZE. For
4304 * now, use this as the limit
4305 */
4306 if (cmdsize > LPFC_BPL_SIZE)
4307 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04004308 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4309 ndlp->nlp_DID, ELS_CMD_ACC);
4310 if (!elsiocb)
4311 return 1;
4312
James Smart7851fe22011-07-22 18:36:52 -04004313 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4314 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4315
James Smart12265f62010-10-22 11:05:53 -04004316 /* Xmit ECHO ACC response tag <ulpIoTag> */
4317 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4318 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4319 elsiocb->iotag, elsiocb->iocb.ulpContext);
4320 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4321 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4322 pcmd += sizeof(uint32_t);
4323 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4324
4325 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4326 "Issue ACC ECHO: did:x%x flg:x%x",
4327 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4328
4329 phba->fc_stat.elsXmitACC++;
4330 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04004331
4332 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4333 if (rc == IOCB_ERROR) {
4334 lpfc_els_free_iocb(phba, elsiocb);
4335 return 1;
4336 }
4337 return 0;
4338}
4339
4340/**
James Smart3621a712009-04-06 18:47:14 -04004341 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004342 * @vport: pointer to a host virtual N_Port data structure.
4343 *
4344 * This routine issues Address Discover (ADISC) ELS commands to those
4345 * N_Ports which are in node port recovery state and ADISC has not been issued
4346 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4347 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4348 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4349 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4350 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4351 * IOCBs quit for later pick up. On the other hand, after walking through
4352 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4353 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4354 * no more ADISC need to be sent.
4355 *
4356 * Return code
4357 * The number of N_Ports with adisc issued.
4358 **/
dea31012005-04-17 16:05:31 -05004359int
James Smart2e0fef82007-06-17 19:56:36 -05004360lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004361{
James Smart2e0fef82007-06-17 19:56:36 -05004362 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004363 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004364 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004365
James Smart685f0bf2007-04-25 09:53:08 -04004366 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004367 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004368 if (!NLP_CHK_NODE_ACT(ndlp))
4369 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004370 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4371 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4372 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004373 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004374 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004375 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004376 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004377 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4378 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004379 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004380 vport->num_disc_nodes++;
4381 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004382 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004383 spin_lock_irq(shost->host_lock);
4384 vport->fc_flag |= FC_NLP_MORE;
4385 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004386 break;
dea31012005-04-17 16:05:31 -05004387 }
4388 }
4389 }
4390 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004391 spin_lock_irq(shost->host_lock);
4392 vport->fc_flag &= ~FC_NLP_MORE;
4393 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004394 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004395 return sentadisc;
dea31012005-04-17 16:05:31 -05004396}
4397
James Smarte59058c2008-08-24 21:49:00 -04004398/**
James Smart3621a712009-04-06 18:47:14 -04004399 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004400 * @vport: pointer to a host virtual N_Port data structure.
4401 *
4402 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4403 * which are in node port recovery state, with a @vport. Each time an ELS
4404 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4405 * the per @vport number of discover count (num_disc_nodes) shall be
4406 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4407 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4408 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4409 * later pick up. On the other hand, after walking through all the ndlps with
4410 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4411 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4412 * PLOGI need to be sent.
4413 *
4414 * Return code
4415 * The number of N_Ports with plogi issued.
4416 **/
dea31012005-04-17 16:05:31 -05004417int
James Smart2e0fef82007-06-17 19:56:36 -05004418lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004419{
James Smart2e0fef82007-06-17 19:56:36 -05004420 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004421 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004422 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004423
James Smart2e0fef82007-06-17 19:56:36 -05004424 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4425 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004426 if (!NLP_CHK_NODE_ACT(ndlp))
4427 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004428 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4429 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4430 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4431 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4432 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004433 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4434 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004435 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004436 vport->num_disc_nodes++;
4437 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004438 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004439 spin_lock_irq(shost->host_lock);
4440 vport->fc_flag |= FC_NLP_MORE;
4441 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004442 break;
dea31012005-04-17 16:05:31 -05004443 }
4444 }
4445 }
James Smart87af33f2007-10-27 13:37:43 -04004446 if (sentplogi) {
4447 lpfc_set_disctmo(vport);
4448 }
4449 else {
James Smart2e0fef82007-06-17 19:56:36 -05004450 spin_lock_irq(shost->host_lock);
4451 vport->fc_flag &= ~FC_NLP_MORE;
4452 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004453 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004454 return sentplogi;
dea31012005-04-17 16:05:31 -05004455}
4456
James Smarte59058c2008-08-24 21:49:00 -04004457/**
James Smart3621a712009-04-06 18:47:14 -04004458 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004459 * @vport: pointer to a host virtual N_Port data structure.
4460 *
4461 * This routine cleans up any Registration State Change Notification
4462 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4463 * @vport together with the host_lock is used to prevent multiple thread
4464 * trying to access the RSCN array on a same @vport at the same time.
4465 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004466void
James Smart2e0fef82007-06-17 19:56:36 -05004467lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004468{
James Smart2e0fef82007-06-17 19:56:36 -05004469 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4470 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004471 int i;
4472
James Smart7f5f3d02008-02-08 18:50:14 -05004473 spin_lock_irq(shost->host_lock);
4474 if (vport->fc_rscn_flush) {
4475 /* Another thread is walking fc_rscn_id_list on this vport */
4476 spin_unlock_irq(shost->host_lock);
4477 return;
4478 }
4479 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4480 vport->fc_rscn_flush = 1;
4481 spin_unlock_irq(shost->host_lock);
4482
James Smart2e0fef82007-06-17 19:56:36 -05004483 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004484 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004485 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004486 }
James Smart2e0fef82007-06-17 19:56:36 -05004487 spin_lock_irq(shost->host_lock);
4488 vport->fc_rscn_id_cnt = 0;
4489 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4490 spin_unlock_irq(shost->host_lock);
4491 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004492 /* Indicate we are done walking this fc_rscn_id_list */
4493 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004494}
4495
James Smarte59058c2008-08-24 21:49:00 -04004496/**
James Smart3621a712009-04-06 18:47:14 -04004497 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004498 * @vport: pointer to a host virtual N_Port data structure.
4499 * @did: remote destination port identifier.
4500 *
4501 * This routine checks whether there is any pending Registration State
4502 * Configuration Notification (RSCN) to a @did on @vport.
4503 *
4504 * Return code
4505 * None zero - The @did matched with a pending rscn
4506 * 0 - not able to match @did with a pending rscn
4507 **/
dea31012005-04-17 16:05:31 -05004508int
James Smart2e0fef82007-06-17 19:56:36 -05004509lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004510{
4511 D_ID ns_did;
4512 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004513 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004514 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004515 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004516
4517 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004518
4519 /* Never match fabric nodes for RSCNs */
4520 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004521 return 0;
dea31012005-04-17 16:05:31 -05004522
4523 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004524 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004525 return did;
dea31012005-04-17 16:05:31 -05004526
James Smart7f5f3d02008-02-08 18:50:14 -05004527 spin_lock_irq(shost->host_lock);
4528 if (vport->fc_rscn_flush) {
4529 /* Another thread is walking fc_rscn_id_list on this vport */
4530 spin_unlock_irq(shost->host_lock);
4531 return 0;
4532 }
4533 /* Indicate we are walking fc_rscn_id_list on this vport */
4534 vport->fc_rscn_flush = 1;
4535 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004536 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004537 lp = vport->fc_rscn_id_list[i]->virt;
4538 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4539 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004540 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004541 rscn_did.un.word = be32_to_cpu(*lp++);
4542 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004543 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4544 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004545 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4546 && (ns_did.un.b.area == rscn_did.un.b.area)
4547 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004548 goto return_did_out;
dea31012005-04-17 16:05:31 -05004549 break;
James Smarteaf15d52008-12-04 22:39:29 -05004550 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004551 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4552 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004553 goto return_did_out;
dea31012005-04-17 16:05:31 -05004554 break;
James Smarteaf15d52008-12-04 22:39:29 -05004555 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004556 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004557 goto return_did_out;
dea31012005-04-17 16:05:31 -05004558 break;
James Smarteaf15d52008-12-04 22:39:29 -05004559 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004560 goto return_did_out;
dea31012005-04-17 16:05:31 -05004561 }
4562 }
James Smart92d7f7b2007-06-17 19:56:38 -05004563 }
James Smart7f5f3d02008-02-08 18:50:14 -05004564 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4565 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004566 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004567return_did_out:
4568 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4569 vport->fc_rscn_flush = 0;
4570 return did;
dea31012005-04-17 16:05:31 -05004571}
4572
James Smarte59058c2008-08-24 21:49:00 -04004573/**
James Smart3621a712009-04-06 18:47:14 -04004574 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004575 * @vport: pointer to a host virtual N_Port data structure.
4576 *
4577 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4578 * state machine for a @vport's nodes that are with pending RSCN (Registration
4579 * State Change Notification).
4580 *
4581 * Return code
4582 * 0 - Successful (currently alway return 0)
4583 **/
dea31012005-04-17 16:05:31 -05004584static int
James Smart2e0fef82007-06-17 19:56:36 -05004585lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004586{
James Smart685f0bf2007-04-25 09:53:08 -04004587 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004588
James Smart0d2b6b82008-06-14 22:52:47 -04004589 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004590 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004591 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004592 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4593 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004594 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004595 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004596 NLP_EVT_DEVICE_RECOVERY);
4597 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004598 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004599 return 0;
dea31012005-04-17 16:05:31 -05004600}
4601
James Smarte59058c2008-08-24 21:49:00 -04004602/**
James Smart3621a712009-04-06 18:47:14 -04004603 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004604 * @vport: pointer to a host virtual N_Port data structure.
4605 * @cmdiocb: pointer to lpfc command iocb data structure.
4606 *
4607 * lpfc_send_rscn_event sends an RSCN netlink event to management
4608 * applications.
4609 */
4610static void
4611lpfc_send_rscn_event(struct lpfc_vport *vport,
4612 struct lpfc_iocbq *cmdiocb)
4613{
4614 struct lpfc_dmabuf *pcmd;
4615 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4616 uint32_t *payload_ptr;
4617 uint32_t payload_len;
4618 struct lpfc_rscn_event_header *rscn_event_data;
4619
4620 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4621 payload_ptr = (uint32_t *) pcmd->virt;
4622 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4623
4624 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4625 payload_len, GFP_KERNEL);
4626 if (!rscn_event_data) {
4627 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4628 "0147 Failed to allocate memory for RSCN event\n");
4629 return;
4630 }
4631 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4632 rscn_event_data->payload_length = payload_len;
4633 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4634 payload_len);
4635
4636 fc_host_post_vendor_event(shost,
4637 fc_get_event_number(),
4638 sizeof(struct lpfc_els_event_header) + payload_len,
4639 (char *)rscn_event_data,
4640 LPFC_NL_VENDOR_ID);
4641
4642 kfree(rscn_event_data);
4643}
4644
4645/**
James Smart3621a712009-04-06 18:47:14 -04004646 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004647 * @vport: pointer to a host virtual N_Port data structure.
4648 * @cmdiocb: pointer to lpfc command iocb data structure.
4649 * @ndlp: pointer to a node-list data structure.
4650 *
4651 * This routine processes an unsolicited RSCN (Registration State Change
4652 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4653 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4654 * discover state machine is about to begin discovery, it just accepts the
4655 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4656 * contains N_Port IDs for other vports on this HBA, it just accepts the
4657 * RSCN and ignore processing it. If the state machine is in the recovery
4658 * state, the fc_rscn_id_list of this @vport is walked and the
4659 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4660 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4661 * routine is invoked to handle the RSCN event.
4662 *
4663 * Return code
4664 * 0 - Just sent the acc response
4665 * 1 - Sent the acc response and waited for name server completion
4666 **/
dea31012005-04-17 16:05:31 -05004667static int
James Smart2e0fef82007-06-17 19:56:36 -05004668lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004669 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004670{
James Smart2e0fef82007-06-17 19:56:36 -05004671 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4672 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004673 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004674 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004675 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004676 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004677 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004678 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004679 int i;
dea31012005-04-17 16:05:31 -05004680
4681 icmd = &cmdiocb->iocb;
4682 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4683 lp = (uint32_t *) pcmd->virt;
4684
James Smart92d7f7b2007-06-17 19:56:38 -05004685 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4686 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004687 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004688 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4689 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004690 vport->fc_flag, payload_len, *lp,
4691 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004692
4693 /* Send an RSCN event to the management application */
4694 lpfc_send_rscn_event(vport, cmdiocb);
4695
James Smartd2873e42006-08-18 17:46:43 -04004696 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004697 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004698 FCH_EVT_RSCN, lp[i]);
4699
dea31012005-04-17 16:05:31 -05004700 /* If we are about to begin discovery, just ACC the RSCN.
4701 * Discovery processing will satisfy it.
4702 */
James Smart2e0fef82007-06-17 19:56:36 -05004703 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004704 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4705 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4706 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4707
James Smart51ef4c22007-08-02 11:10:31 -04004708 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004709 return 0;
dea31012005-04-17 16:05:31 -05004710 }
4711
James Smart92d7f7b2007-06-17 19:56:38 -05004712 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4713 * just ACC and ignore it.
4714 */
4715 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004716 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004717 i = payload_len;
4718 datap = lp;
4719 while (i > 0) {
4720 nportid = *datap++;
4721 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4722 i -= sizeof(uint32_t);
4723 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004724 if (lpfc_find_vport_by_did(phba, nportid))
4725 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004726 }
4727 if (rscn_id == hba_id) {
4728 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004729 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004730 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004731 "Data: x%x x%x x%x x%x\n",
4732 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004733 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004734 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4735 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4736 ndlp->nlp_DID, vport->port_state,
4737 ndlp->nlp_flag);
4738
James Smart92d7f7b2007-06-17 19:56:38 -05004739 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004740 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004741 return 0;
4742 }
4743 }
4744
James Smart7f5f3d02008-02-08 18:50:14 -05004745 spin_lock_irq(shost->host_lock);
4746 if (vport->fc_rscn_flush) {
4747 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004748 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004749 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004750 /* Send back ACC */
4751 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004752 return 0;
4753 }
4754 /* Indicate we are walking fc_rscn_id_list on this vport */
4755 vport->fc_rscn_flush = 1;
4756 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004757 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004758 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004759 /* If we are already processing an RSCN, save the received
4760 * RSCN payload buffer, cmdiocb->context2 to process later.
4761 */
James Smart2e0fef82007-06-17 19:56:36 -05004762 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004763 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4764 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4765 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4766
James Smart09372822008-01-11 01:52:54 -05004767 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004768 vport->fc_flag |= FC_RSCN_DEFERRED;
4769 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004770 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004771 vport->fc_flag |= FC_RSCN_MODE;
4772 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004773 if (rscn_cnt) {
4774 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4775 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4776 }
4777 if ((rscn_cnt) &&
4778 (payload_len + length <= LPFC_BPL_SIZE)) {
4779 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004780 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004781 memcpy(((uint8_t *)cmd) + length, lp,
4782 payload_len);
4783 } else {
4784 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4785 vport->fc_rscn_id_cnt++;
4786 /* If we zero, cmdiocb->context2, the calling
4787 * routine will not try to free it.
4788 */
4789 cmdiocb->context2 = NULL;
4790 }
dea31012005-04-17 16:05:31 -05004791 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004792 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4793 "0235 Deferred RSCN "
4794 "Data: x%x x%x x%x\n",
4795 vport->fc_rscn_id_cnt, vport->fc_flag,
4796 vport->port_state);
dea31012005-04-17 16:05:31 -05004797 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004798 vport->fc_flag |= FC_RSCN_DISCOVERY;
4799 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004800 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004801 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4802 "0234 ReDiscovery RSCN "
4803 "Data: x%x x%x x%x\n",
4804 vport->fc_rscn_id_cnt, vport->fc_flag,
4805 vport->port_state);
dea31012005-04-17 16:05:31 -05004806 }
James Smart7f5f3d02008-02-08 18:50:14 -05004807 /* Indicate we are done walking fc_rscn_id_list on this vport */
4808 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004809 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004810 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004811 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004812 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004813 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004814 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004815 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004816 return 0;
dea31012005-04-17 16:05:31 -05004817 }
James Smart858c9f62007-06-17 19:56:39 -05004818 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4819 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4820 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4821
James Smart2e0fef82007-06-17 19:56:36 -05004822 spin_lock_irq(shost->host_lock);
4823 vport->fc_flag |= FC_RSCN_MODE;
4824 spin_unlock_irq(shost->host_lock);
4825 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004826 /* Indicate we are done walking fc_rscn_id_list on this vport */
4827 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004828 /*
4829 * If we zero, cmdiocb->context2, the calling routine will
4830 * not try to free it.
4831 */
4832 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004833 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004834 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004835 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004836 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004837 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004838 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004839}
4840
James Smarte59058c2008-08-24 21:49:00 -04004841/**
James Smart3621a712009-04-06 18:47:14 -04004842 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004843 * @vport: pointer to a host virtual N_Port data structure.
4844 *
4845 * This routine handles the Registration State Configuration Notification
4846 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4847 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4848 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4849 * NameServer shall be issued. If CT command to the NameServer fails to be
4850 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4851 * RSCN activities with the @vport.
4852 *
4853 * Return code
4854 * 0 - Cleaned up rscn on the @vport
4855 * 1 - Wait for plogi to name server before proceed
4856 **/
dea31012005-04-17 16:05:31 -05004857int
James Smart2e0fef82007-06-17 19:56:36 -05004858lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004859{
4860 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004861 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004862
James Smart92d7f7b2007-06-17 19:56:38 -05004863 /* Ignore RSCN if the port is being torn down. */
4864 if (vport->load_flag & FC_UNLOADING) {
4865 lpfc_els_flush_rscn(vport);
4866 return 0;
4867 }
4868
dea31012005-04-17 16:05:31 -05004869 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004870 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004871
4872 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004873 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4874 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4875 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4876 vport->port_state);
dea31012005-04-17 16:05:31 -05004877
4878 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004879 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004880 vport->num_disc_nodes = 0;
4881
James Smart2e0fef82007-06-17 19:56:36 -05004882 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004883 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4884 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004885 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004886 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004887 /* Wait for NameServer query cmpl before we can
4888 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004889 return 1;
dea31012005-04-17 16:05:31 -05004890 } else {
4891 /* If login to NameServer does not exist, issue one */
4892 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004893 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004894 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004895 /* Wait for NameServer login cmpl before we can
4896 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004897 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004898
James Smarte47c9092008-02-08 18:49:26 -05004899 if (ndlp) {
4900 ndlp = lpfc_enable_node(vport, ndlp,
4901 NLP_STE_PLOGI_ISSUE);
4902 if (!ndlp) {
4903 lpfc_els_flush_rscn(vport);
4904 return 0;
4905 }
4906 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004907 } else {
James Smarte47c9092008-02-08 18:49:26 -05004908 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4909 if (!ndlp) {
4910 lpfc_els_flush_rscn(vport);
4911 return 0;
4912 }
James Smart2e0fef82007-06-17 19:56:36 -05004913 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004914 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004915 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004916 }
James Smarte47c9092008-02-08 18:49:26 -05004917 ndlp->nlp_type |= NLP_FABRIC;
4918 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4919 /* Wait for NameServer login cmpl before we can
4920 * continue
4921 */
4922 return 1;
dea31012005-04-17 16:05:31 -05004923 }
4924
James Smart2e0fef82007-06-17 19:56:36 -05004925 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004926 return 0;
dea31012005-04-17 16:05:31 -05004927}
4928
James Smarte59058c2008-08-24 21:49:00 -04004929/**
James Smart3621a712009-04-06 18:47:14 -04004930 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004931 * @vport: pointer to a host virtual N_Port data structure.
4932 * @cmdiocb: pointer to lpfc command iocb data structure.
4933 * @ndlp: pointer to a node-list data structure.
4934 *
4935 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4936 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4937 * point topology. As an unsolicited FLOGI should not be received in a loop
4938 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4939 * lpfc_check_sparm() routine is invoked to check the parameters in the
4940 * unsolicited FLOGI. If parameters validation failed, the routine
4941 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4942 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4943 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4944 * will initiate PLOGI. The higher lexicographical value party shall has
4945 * higher priority (as the winning port) and will initiate PLOGI and
4946 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4947 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4948 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4949 *
4950 * Return code
4951 * 0 - Successfully processed the unsolicited flogi
4952 * 1 - Failed to process the unsolicited flogi
4953 **/
dea31012005-04-17 16:05:31 -05004954static int
James Smart2e0fef82007-06-17 19:56:36 -05004955lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004956 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004957{
James Smart2e0fef82007-06-17 19:56:36 -05004958 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4959 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004960 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4961 uint32_t *lp = (uint32_t *) pcmd->virt;
4962 IOCB_t *icmd = &cmdiocb->iocb;
4963 struct serv_parm *sp;
4964 LPFC_MBOXQ_t *mbox;
4965 struct ls_rjt stat;
4966 uint32_t cmd, did;
4967 int rc;
4968
4969 cmd = *lp++;
4970 sp = (struct serv_parm *) lp;
4971
4972 /* FLOGI received */
4973
James Smart2e0fef82007-06-17 19:56:36 -05004974 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004975
James Smart76a95d72010-11-20 23:11:48 -05004976 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004977 /* We should never receive a FLOGI in loop mode, ignore it */
4978 did = icmd->un.elsreq64.remoteID;
4979
4980 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4981 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004982 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4983 "0113 An FLOGI ELS command x%x was "
4984 "received from DID x%x in Loop Mode\n",
4985 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004986 return 1;
dea31012005-04-17 16:05:31 -05004987 }
4988
James Smart341af102010-01-26 23:07:37 -05004989 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004990 /* For a FLOGI we accept, then if our portname is greater
4991 * then the remote portname we initiate Nport login.
4992 */
4993
James Smart2e0fef82007-06-17 19:56:36 -05004994 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004995 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004996
4997 if (!rc) {
James Smart1b511972011-12-13 13:23:09 -05004998 if (phba->sli_rev < LPFC_SLI_REV4) {
4999 mbox = mempool_alloc(phba->mbox_mem_pool,
5000 GFP_KERNEL);
5001 if (!mbox)
5002 return 1;
5003 lpfc_linkdown(phba);
5004 lpfc_init_link(phba, mbox,
5005 phba->cfg_topology,
5006 phba->cfg_link_speed);
5007 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5008 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5009 mbox->vport = vport;
5010 rc = lpfc_sli_issue_mbox(phba, mbox,
5011 MBX_NOWAIT);
5012 lpfc_set_loopback_flag(phba);
5013 if (rc == MBX_NOT_FINISHED)
5014 mempool_free(mbox, phba->mbox_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005015 return 1;
James Smart1b511972011-12-13 13:23:09 -05005016 } else {
5017 /* abort the flogi coming back to ourselves
5018 * due to external loopback on the port.
5019 */
5020 lpfc_els_abort_flogi(phba);
5021 return 0;
dea31012005-04-17 16:05:31 -05005022 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005023 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05005024 spin_lock_irq(shost->host_lock);
5025 vport->fc_flag |= FC_PT2PT_PLOGI;
5026 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04005027
5028 /* If we have the high WWPN we can assign our own
5029 * myDID; otherwise, we have to WAIT for a PLOGI
5030 * from the remote NPort to find out what it
5031 * will be.
5032 */
James Smarte6446432012-05-09 21:16:42 -04005033 vport->fc_myDID = PT2PT_LocalID;
James Smart939723a2012-05-09 21:19:03 -04005034 }
5035
5036 /*
5037 * The vport state should go to LPFC_FLOGI only
5038 * AFTER we issue a FLOGI, not receive one.
5039 */
James Smart2e0fef82007-06-17 19:56:36 -05005040 spin_lock_irq(shost->host_lock);
5041 vport->fc_flag |= FC_PT2PT;
5042 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5043 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04005044
5045 /*
5046 * We temporarily set fc_myDID to make it look like we are
5047 * a Fabric. This is done just so we end up with the right
5048 * did / sid on the FLOGI ACC rsp.
5049 */
5050 did = vport->fc_myDID;
5051 vport->fc_myDID = Fabric_DID;
5052
dea31012005-04-17 16:05:31 -05005053 } else {
5054 /* Reject this request because invalid parameters */
5055 stat.un.b.lsRjtRsvd0 = 0;
5056 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5057 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
5058 stat.un.b.vendorUnique = 0;
James Smart939723a2012-05-09 21:19:03 -04005059
5060 /*
5061 * We temporarily set fc_myDID to make it look like we are
5062 * a Fabric. This is done just so we end up with the right
5063 * did / sid on the FLOGI LS_RJT rsp.
5064 */
5065 did = vport->fc_myDID;
5066 vport->fc_myDID = Fabric_DID;
5067
James Smart858c9f62007-06-17 19:56:39 -05005068 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5069 NULL);
James Smart939723a2012-05-09 21:19:03 -04005070
5071 /* Now lets put fc_myDID back to what its supposed to be */
5072 vport->fc_myDID = did;
5073
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005074 return 1;
dea31012005-04-17 16:05:31 -05005075 }
5076
5077 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04005078 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005079
James Smart939723a2012-05-09 21:19:03 -04005080 /* Now lets put fc_myDID back to what its supposed to be */
5081 vport->fc_myDID = did;
5082
James Smarte6446432012-05-09 21:16:42 -04005083 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
James Smart939723a2012-05-09 21:19:03 -04005084
James Smarte6446432012-05-09 21:16:42 -04005085 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5086 if (!mbox)
5087 goto fail;
5088
5089 lpfc_config_link(phba, mbox);
5090
5091 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5092 mbox->vport = vport;
5093 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5094 if (rc == MBX_NOT_FINISHED) {
5095 mempool_free(mbox, phba->mbox_mem_pool);
5096 goto fail;
5097 }
5098 }
5099
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005100 return 0;
James Smarte6446432012-05-09 21:16:42 -04005101fail:
5102 return 1;
dea31012005-04-17 16:05:31 -05005103}
5104
James Smarte59058c2008-08-24 21:49:00 -04005105/**
James Smart3621a712009-04-06 18:47:14 -04005106 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04005107 * @vport: pointer to a host virtual N_Port data structure.
5108 * @cmdiocb: pointer to lpfc command iocb data structure.
5109 * @ndlp: pointer to a node-list data structure.
5110 *
5111 * This routine processes Request Node Identification Data (RNID) IOCB
5112 * received as an ELS unsolicited event. Only when the RNID specified format
5113 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
5114 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
5115 * Accept (ACC) the RNID ELS command. All the other RNID formats are
5116 * rejected by invoking the lpfc_els_rsp_reject() routine.
5117 *
5118 * Return code
5119 * 0 - Successfully processed rnid iocb (currently always return 0)
5120 **/
dea31012005-04-17 16:05:31 -05005121static int
James Smart2e0fef82007-06-17 19:56:36 -05005122lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5123 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005124{
5125 struct lpfc_dmabuf *pcmd;
5126 uint32_t *lp;
5127 IOCB_t *icmd;
5128 RNID *rn;
5129 struct ls_rjt stat;
5130 uint32_t cmd, did;
5131
5132 icmd = &cmdiocb->iocb;
5133 did = icmd->un.elsreq64.remoteID;
5134 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5135 lp = (uint32_t *) pcmd->virt;
5136
5137 cmd = *lp++;
5138 rn = (RNID *) lp;
5139
5140 /* RNID received */
5141
5142 switch (rn->Format) {
5143 case 0:
5144 case RNID_TOPOLOGY_DISC:
5145 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05005146 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005147 break;
5148 default:
5149 /* Reject this request because format not supported */
5150 stat.un.b.lsRjtRsvd0 = 0;
5151 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5152 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5153 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005154 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5155 NULL);
dea31012005-04-17 16:05:31 -05005156 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005157 return 0;
dea31012005-04-17 16:05:31 -05005158}
5159
James Smarte59058c2008-08-24 21:49:00 -04005160/**
James Smart12265f62010-10-22 11:05:53 -04005161 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
5162 * @vport: pointer to a host virtual N_Port data structure.
5163 * @cmdiocb: pointer to lpfc command iocb data structure.
5164 * @ndlp: pointer to a node-list data structure.
5165 *
5166 * Return code
5167 * 0 - Successfully processed echo iocb (currently always return 0)
5168 **/
5169static int
5170lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5171 struct lpfc_nodelist *ndlp)
5172{
5173 uint8_t *pcmd;
5174
5175 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
5176
5177 /* skip over first word of echo command to find echo data */
5178 pcmd += sizeof(uint32_t);
5179
5180 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
5181 return 0;
5182}
5183
5184/**
James Smart3621a712009-04-06 18:47:14 -04005185 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04005186 * @vport: pointer to a host virtual N_Port data structure.
5187 * @cmdiocb: pointer to lpfc command iocb data structure.
5188 * @ndlp: pointer to a node-list data structure.
5189 *
5190 * This routine processes a Link Incident Report Registration(LIRR) IOCB
5191 * received as an ELS unsolicited event. Currently, this function just invokes
5192 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
5193 *
5194 * Return code
5195 * 0 - Successfully processed lirr iocb (currently always return 0)
5196 **/
dea31012005-04-17 16:05:31 -05005197static int
James Smart2e0fef82007-06-17 19:56:36 -05005198lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5199 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005200{
5201 struct ls_rjt stat;
5202
5203 /* For now, unconditionally reject this command */
5204 stat.un.b.lsRjtRsvd0 = 0;
5205 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5206 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5207 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005208 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005209 return 0;
5210}
5211
James Smarte59058c2008-08-24 21:49:00 -04005212/**
James Smart5ffc2662009-11-18 15:39:44 -05005213 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5214 * @vport: pointer to a host virtual N_Port data structure.
5215 * @cmdiocb: pointer to lpfc command iocb data structure.
5216 * @ndlp: pointer to a node-list data structure.
5217 *
5218 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5219 * received as an ELS unsolicited event. A request to RRQ shall only
5220 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5221 * Nx_Port N_Port_ID of the target Exchange is the same as the
5222 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5223 * not accepted, an LS_RJT with reason code "Unable to perform
5224 * command request" and reason code explanation "Invalid Originator
5225 * S_ID" shall be returned. For now, we just unconditionally accept
5226 * RRQ from the target.
5227 **/
5228static void
5229lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5230 struct lpfc_nodelist *ndlp)
5231{
5232 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05005233 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5234 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05005235}
5236
5237/**
James Smart12265f62010-10-22 11:05:53 -04005238 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5239 * @phba: pointer to lpfc hba data structure.
5240 * @pmb: pointer to the driver internal queue element for mailbox command.
5241 *
5242 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5243 * mailbox command. This callback function is to actually send the Accept
5244 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5245 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5246 * mailbox command, constructs the RPS response with the link statistics
5247 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5248 * response to the RPS.
5249 *
5250 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5251 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5252 * will be stored into the context1 field of the IOCB for the completion
5253 * callback function to the RPS Accept Response ELS IOCB command.
5254 *
5255 **/
5256static void
5257lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5258{
5259 MAILBOX_t *mb;
5260 IOCB_t *icmd;
5261 struct RLS_RSP *rls_rsp;
5262 uint8_t *pcmd;
5263 struct lpfc_iocbq *elsiocb;
5264 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005265 uint16_t oxid;
5266 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04005267 uint32_t cmdsize;
5268
5269 mb = &pmb->u.mb;
5270
5271 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005272 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5273 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04005274 pmb->context1 = NULL;
5275 pmb->context2 = NULL;
5276
5277 if (mb->mbxStatus) {
5278 mempool_free(pmb, phba->mbox_mem_pool);
5279 return;
5280 }
5281
5282 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04005283 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5284 lpfc_max_els_tries, ndlp,
5285 ndlp->nlp_DID, ELS_CMD_ACC);
5286
5287 /* Decrement the ndlp reference count from previous mbox command */
5288 lpfc_nlp_put(ndlp);
5289
James Smart37db57e2012-05-09 21:17:16 -04005290 if (!elsiocb) {
5291 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04005292 return;
James Smart37db57e2012-05-09 21:17:16 -04005293 }
James Smart12265f62010-10-22 11:05:53 -04005294
5295 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005296 icmd->ulpContext = rxid;
5297 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04005298
5299 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5300 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5301 pcmd += sizeof(uint32_t); /* Skip past command */
5302 rls_rsp = (struct RLS_RSP *)pcmd;
5303
5304 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5305 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5306 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5307 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5308 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5309 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04005310 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04005311 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5312 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5313 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5314 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5315 elsiocb->iotag, elsiocb->iocb.ulpContext,
5316 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5317 ndlp->nlp_rpi);
5318 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5319 phba->fc_stat.elsXmitACC++;
5320 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5321 lpfc_els_free_iocb(phba, elsiocb);
5322}
5323
5324/**
James Smart3621a712009-04-06 18:47:14 -04005325 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005326 * @phba: pointer to lpfc hba data structure.
5327 * @pmb: pointer to the driver internal queue element for mailbox command.
5328 *
5329 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5330 * mailbox command. This callback function is to actually send the Accept
5331 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5332 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5333 * mailbox command, constructs the RPS response with the link statistics
5334 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5335 * response to the RPS.
5336 *
5337 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5338 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5339 * will be stored into the context1 field of the IOCB for the completion
5340 * callback function to the RPS Accept Response ELS IOCB command.
5341 *
5342 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005343static void
James Smart329f9bc2007-04-25 09:53:01 -04005344lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005345{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005346 MAILBOX_t *mb;
5347 IOCB_t *icmd;
5348 RPS_RSP *rps_rsp;
5349 uint8_t *pcmd;
5350 struct lpfc_iocbq *elsiocb;
5351 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005352 uint16_t status;
5353 uint16_t oxid;
5354 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005355 uint32_t cmdsize;
5356
James Smart04c68492009-05-22 14:52:52 -04005357 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005358
5359 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005360 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5361 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07005362 pmb->context1 = NULL;
5363 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005364
5365 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005366 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005367 return;
5368 }
5369
5370 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005371 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005372 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5373 lpfc_max_els_tries, ndlp,
5374 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005375
5376 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005377 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005378
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005379 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005380 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005381
5382 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005383 icmd->ulpContext = rxid;
5384 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005385
5386 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5387 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005388 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005389 rps_rsp = (RPS_RSP *)pcmd;
5390
James Smart76a95d72010-11-20 23:11:48 -05005391 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005392 status = 0x10;
5393 else
5394 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005395 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005396 status |= 0x4;
5397
5398 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005399 rps_rsp->portStatus = cpu_to_be16(status);
5400 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5401 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5402 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5403 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5404 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5405 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005406 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005407 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5408 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5409 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5410 elsiocb->iotag, elsiocb->iocb.ulpContext,
5411 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5412 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005413 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005414 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005415 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005416 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005417 return;
5418}
5419
James Smarte59058c2008-08-24 21:49:00 -04005420/**
James Smart12265f62010-10-22 11:05:53 -04005421 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5422 * @vport: pointer to a host virtual N_Port data structure.
5423 * @cmdiocb: pointer to lpfc command iocb data structure.
5424 * @ndlp: pointer to a node-list data structure.
5425 *
5426 * This routine processes Read Port Status (RPL) IOCB received as an
5427 * ELS unsolicited event. It first checks the remote port state. If the
5428 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5429 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5430 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5431 * for reading the HBA link statistics. It is for the callback function,
5432 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5433 * to actually sending out RPL Accept (ACC) response.
5434 *
5435 * Return codes
5436 * 0 - Successfully processed rls iocb (currently always return 0)
5437 **/
5438static int
5439lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5440 struct lpfc_nodelist *ndlp)
5441{
5442 struct lpfc_hba *phba = vport->phba;
5443 LPFC_MBOXQ_t *mbox;
5444 struct lpfc_dmabuf *pcmd;
5445 struct ls_rjt stat;
5446
5447 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5448 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5449 /* reject the unsolicited RPS request and done with it */
5450 goto reject_out;
5451
5452 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5453
5454 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5455 if (mbox) {
5456 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005457 mbox->context1 = (void *)((unsigned long)
5458 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5459 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04005460 mbox->context2 = lpfc_nlp_get(ndlp);
5461 mbox->vport = vport;
5462 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5463 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5464 != MBX_NOT_FINISHED)
5465 /* Mbox completion will send ELS Response */
5466 return 0;
5467 /* Decrement reference count used for the failed mbox
5468 * command.
5469 */
5470 lpfc_nlp_put(ndlp);
5471 mempool_free(mbox, phba->mbox_mem_pool);
5472 }
5473reject_out:
5474 /* issue rejection response */
5475 stat.un.b.lsRjtRsvd0 = 0;
5476 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5477 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5478 stat.un.b.vendorUnique = 0;
5479 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5480 return 0;
5481}
5482
5483/**
5484 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5485 * @vport: pointer to a host virtual N_Port data structure.
5486 * @cmdiocb: pointer to lpfc command iocb data structure.
5487 * @ndlp: pointer to a node-list data structure.
5488 *
5489 * This routine processes Read Timout Value (RTV) IOCB received as an
5490 * ELS unsolicited event. It first checks the remote port state. If the
5491 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5492 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5493 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5494 * Value (RTV) unsolicited IOCB event.
5495 *
5496 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5497 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5498 * will be stored into the context1 field of the IOCB for the completion
5499 * callback function to the RPS Accept Response ELS IOCB command.
5500 *
5501 * Return codes
5502 * 0 - Successfully processed rtv iocb (currently always return 0)
5503 **/
5504static int
5505lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5506 struct lpfc_nodelist *ndlp)
5507{
5508 struct lpfc_hba *phba = vport->phba;
5509 struct ls_rjt stat;
5510 struct RTV_RSP *rtv_rsp;
5511 uint8_t *pcmd;
5512 struct lpfc_iocbq *elsiocb;
5513 uint32_t cmdsize;
5514
5515
5516 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5517 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5518 /* reject the unsolicited RPS request and done with it */
5519 goto reject_out;
5520
5521 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5522 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5523 lpfc_max_els_tries, ndlp,
5524 ndlp->nlp_DID, ELS_CMD_ACC);
5525
5526 if (!elsiocb)
5527 return 1;
5528
5529 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5530 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5531 pcmd += sizeof(uint32_t); /* Skip past command */
5532
5533 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04005534 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
5535 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04005536
5537 rtv_rsp = (struct RTV_RSP *)pcmd;
5538
5539 /* populate RTV payload */
5540 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5541 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5542 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5543 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5544 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5545
5546 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5547 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5548 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5549 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5550 "Data: x%x x%x x%x\n",
5551 elsiocb->iotag, elsiocb->iocb.ulpContext,
5552 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5553 ndlp->nlp_rpi,
5554 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5555 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5556 phba->fc_stat.elsXmitACC++;
5557 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5558 lpfc_els_free_iocb(phba, elsiocb);
5559 return 0;
5560
5561reject_out:
5562 /* issue rejection response */
5563 stat.un.b.lsRjtRsvd0 = 0;
5564 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5565 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5566 stat.un.b.vendorUnique = 0;
5567 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5568 return 0;
5569}
5570
5571/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005572 * @vport: pointer to a host virtual N_Port data structure.
5573 * @cmdiocb: pointer to lpfc command iocb data structure.
5574 * @ndlp: pointer to a node-list data structure.
5575 *
5576 * This routine processes Read Port Status (RPS) IOCB received as an
5577 * ELS unsolicited event. It first checks the remote port state. If the
5578 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5579 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5580 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5581 * for reading the HBA link statistics. It is for the callback function,
5582 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5583 * to actually sending out RPS Accept (ACC) response.
5584 *
5585 * Return codes
5586 * 0 - Successfully processed rps iocb (currently always return 0)
5587 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005588static int
James Smart2e0fef82007-06-17 19:56:36 -05005589lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5590 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005591{
James Smart2e0fef82007-06-17 19:56:36 -05005592 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005593 uint32_t *lp;
5594 uint8_t flag;
5595 LPFC_MBOXQ_t *mbox;
5596 struct lpfc_dmabuf *pcmd;
5597 RPS *rps;
5598 struct ls_rjt stat;
5599
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005600 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005601 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5602 /* reject the unsolicited RPS request and done with it */
5603 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005604
5605 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5606 lp = (uint32_t *) pcmd->virt;
5607 flag = (be32_to_cpu(*lp++) & 0xf);
5608 rps = (RPS *) lp;
5609
5610 if ((flag == 0) ||
5611 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005612 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005613 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005614
James Smart92d7f7b2007-06-17 19:56:38 -05005615 printk("Fix me....\n");
5616 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005617 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5618 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005619 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005620 mbox->context1 = (void *)((unsigned long)
5621 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5622 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04005623 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005624 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005625 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005626 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005627 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005628 /* Mbox completion will send ELS Response */
5629 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005630 /* Decrement reference count used for the failed mbox
5631 * command.
5632 */
James Smart329f9bc2007-04-25 09:53:01 -04005633 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005634 mempool_free(mbox, phba->mbox_mem_pool);
5635 }
5636 }
James Smart90160e02008-08-24 21:49:45 -04005637
5638reject_out:
5639 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005640 stat.un.b.lsRjtRsvd0 = 0;
5641 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5642 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5643 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005644 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005645 return 0;
5646}
5647
James Smart19ca7602010-11-20 23:11:55 -05005648/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5649 * @vport: pointer to a host virtual N_Port data structure.
5650 * @ndlp: pointer to a node-list data structure.
5651 * @did: DID of the target.
5652 * @rrq: Pointer to the rrq struct.
5653 *
5654 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5655 * Successful the the completion handler will clear the RRQ.
5656 *
5657 * Return codes
5658 * 0 - Successfully sent rrq els iocb.
5659 * 1 - Failed to send rrq els iocb.
5660 **/
5661static int
5662lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5663 uint32_t did, struct lpfc_node_rrq *rrq)
5664{
5665 struct lpfc_hba *phba = vport->phba;
5666 struct RRQ *els_rrq;
5667 IOCB_t *icmd;
5668 struct lpfc_iocbq *elsiocb;
5669 uint8_t *pcmd;
5670 uint16_t cmdsize;
5671 int ret;
5672
5673
5674 if (ndlp != rrq->ndlp)
5675 ndlp = rrq->ndlp;
5676 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5677 return 1;
5678
5679 /* If ndlp is not NULL, we will bump the reference count on it */
5680 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5681 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5682 ELS_CMD_RRQ);
5683 if (!elsiocb)
5684 return 1;
5685
5686 icmd = &elsiocb->iocb;
5687 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5688
5689 /* For RRQ request, remainder of payload is Exchange IDs */
5690 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5691 pcmd += sizeof(uint32_t);
5692 els_rrq = (struct RRQ *) pcmd;
5693
James Smartee0f4fe2012-05-09 21:19:14 -04005694 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
James Smart19ca7602010-11-20 23:11:55 -05005695 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5696 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5697 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5698 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5699
5700
5701 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5702 "Issue RRQ: did:x%x",
5703 did, rrq->xritag, rrq->rxid);
5704 elsiocb->context_un.rrq = rrq;
5705 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5706 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5707
5708 if (ret == IOCB_ERROR) {
5709 lpfc_els_free_iocb(phba, elsiocb);
5710 return 1;
5711 }
5712 return 0;
5713}
5714
5715/**
5716 * lpfc_send_rrq - Sends ELS RRQ if needed.
5717 * @phba: pointer to lpfc hba data structure.
5718 * @rrq: pointer to the active rrq.
5719 *
5720 * This routine will call the lpfc_issue_els_rrq if the rrq is
5721 * still active for the xri. If this function returns a failure then
5722 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5723 *
5724 * Returns 0 Success.
5725 * 1 Failure.
5726 **/
5727int
5728lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5729{
5730 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5731 rrq->nlp_DID);
5732 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5733 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5734 rrq->nlp_DID, rrq);
5735 else
5736 return 1;
5737}
5738
James Smarte59058c2008-08-24 21:49:00 -04005739/**
James Smart3621a712009-04-06 18:47:14 -04005740 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005741 * @vport: pointer to a host virtual N_Port data structure.
5742 * @cmdsize: size of the ELS command.
5743 * @oldiocb: pointer to the original lpfc command iocb data structure.
5744 * @ndlp: pointer to a node-list data structure.
5745 *
5746 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5747 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5748 *
5749 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5750 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5751 * will be stored into the context1 field of the IOCB for the completion
5752 * callback function to the RPL Accept Response ELS command.
5753 *
5754 * Return code
5755 * 0 - Successfully issued ACC RPL ELS command
5756 * 1 - Failed to issue ACC RPL ELS command
5757 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005758static int
James Smart2e0fef82007-06-17 19:56:36 -05005759lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5760 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005761{
James Smart2e0fef82007-06-17 19:56:36 -05005762 struct lpfc_hba *phba = vport->phba;
5763 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005764 RPL_RSP rpl_rsp;
5765 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005766 uint8_t *pcmd;
5767
James Smart2e0fef82007-06-17 19:56:36 -05005768 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5769 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005770
James Smart488d1462006-03-07 15:02:37 -05005771 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005772 return 1;
James Smart488d1462006-03-07 15:02:37 -05005773
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005774 icmd = &elsiocb->iocb;
5775 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005776 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5777 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005778
5779 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5780 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005781 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005782 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5783 pcmd += sizeof(uint16_t);
5784
5785 /* Setup the RPL ACC payload */
5786 rpl_rsp.listLen = be32_to_cpu(1);
5787 rpl_rsp.index = 0;
5788 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005789 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5790 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005791 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005792 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005793 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005794 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5795 "0120 Xmit ELS RPL ACC response tag x%x "
5796 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5797 "rpi x%x\n",
5798 elsiocb->iotag, elsiocb->iocb.ulpContext,
5799 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5800 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005801 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005802 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005803 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5804 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005805 lpfc_els_free_iocb(phba, elsiocb);
5806 return 1;
5807 }
5808 return 0;
5809}
5810
James Smarte59058c2008-08-24 21:49:00 -04005811/**
James Smart3621a712009-04-06 18:47:14 -04005812 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005813 * @vport: pointer to a host virtual N_Port data structure.
5814 * @cmdiocb: pointer to lpfc command iocb data structure.
5815 * @ndlp: pointer to a node-list data structure.
5816 *
5817 * This routine processes Read Port List (RPL) IOCB received as an ELS
5818 * unsolicited event. It first checks the remote port state. If the remote
5819 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5820 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5821 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5822 * to accept the RPL.
5823 *
5824 * Return code
5825 * 0 - Successfully processed rpl iocb (currently always return 0)
5826 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005827static int
James Smart2e0fef82007-06-17 19:56:36 -05005828lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5829 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005830{
5831 struct lpfc_dmabuf *pcmd;
5832 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005833 uint32_t maxsize;
5834 uint16_t cmdsize;
5835 RPL *rpl;
5836 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005837
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005838 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5839 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005840 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005841 stat.un.b.lsRjtRsvd0 = 0;
5842 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5843 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5844 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005845 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5846 NULL);
James Smart90160e02008-08-24 21:49:45 -04005847 /* rejected the unsolicited RPL request and done with it */
5848 return 0;
dea31012005-04-17 16:05:31 -05005849 }
5850
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005851 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5852 lp = (uint32_t *) pcmd->virt;
5853 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005854 maxsize = be32_to_cpu(rpl->maxsize);
5855
5856 /* We support only one port */
5857 if ((rpl->index == 0) &&
5858 ((maxsize == 0) ||
5859 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5860 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005861 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005862 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5863 }
James Smart2e0fef82007-06-17 19:56:36 -05005864 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005865
5866 return 0;
5867}
5868
James Smarte59058c2008-08-24 21:49:00 -04005869/**
James Smart3621a712009-04-06 18:47:14 -04005870 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005871 * @vport: pointer to a virtual N_Port data structure.
5872 * @cmdiocb: pointer to lpfc command iocb data structure.
5873 * @ndlp: pointer to a node-list data structure.
5874 *
5875 * This routine processes Fibre Channel Address Resolution Protocol
5876 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5877 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5878 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5879 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5880 * remote PortName is compared against the FC PortName stored in the @vport
5881 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5882 * compared against the FC NodeName stored in the @vport data structure.
5883 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5884 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5885 * invoked to send out FARP Response to the remote node. Before sending the
5886 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5887 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5888 * routine is invoked to log into the remote port first.
5889 *
5890 * Return code
5891 * 0 - Either the FARP Match Mode not supported or successfully processed
5892 **/
dea31012005-04-17 16:05:31 -05005893static int
James Smart2e0fef82007-06-17 19:56:36 -05005894lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5895 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005896{
5897 struct lpfc_dmabuf *pcmd;
5898 uint32_t *lp;
5899 IOCB_t *icmd;
5900 FARP *fp;
5901 uint32_t cmd, cnt, did;
5902
5903 icmd = &cmdiocb->iocb;
5904 did = icmd->un.elsreq64.remoteID;
5905 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5906 lp = (uint32_t *) pcmd->virt;
5907
5908 cmd = *lp++;
5909 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005910 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005911 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5912 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005913 /* We will only support match on WWPN or WWNN */
5914 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005915 return 0;
dea31012005-04-17 16:05:31 -05005916 }
5917
5918 cnt = 0;
5919 /* If this FARP command is searching for my portname */
5920 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005921 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005922 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005923 cnt = 1;
5924 }
5925
5926 /* If this FARP command is searching for my nodename */
5927 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005928 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005929 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005930 cnt = 1;
5931 }
5932
5933 if (cnt) {
5934 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5935 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5936 /* Log back into the node before sending the FARP. */
5937 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005938 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005939 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005940 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005941 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005942 }
5943
5944 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005945 if (fp->Rflags & FARP_REQUEST_FARPR)
5946 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005947 }
5948 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005949 return 0;
dea31012005-04-17 16:05:31 -05005950}
5951
James Smarte59058c2008-08-24 21:49:00 -04005952/**
James Smart3621a712009-04-06 18:47:14 -04005953 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005954 * @vport: pointer to a host virtual N_Port data structure.
5955 * @cmdiocb: pointer to lpfc command iocb data structure.
5956 * @ndlp: pointer to a node-list data structure.
5957 *
5958 * This routine processes Fibre Channel Address Resolution Protocol
5959 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5960 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5961 * the FARP response request.
5962 *
5963 * Return code
5964 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5965 **/
dea31012005-04-17 16:05:31 -05005966static int
James Smart2e0fef82007-06-17 19:56:36 -05005967lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5968 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005969{
5970 struct lpfc_dmabuf *pcmd;
5971 uint32_t *lp;
5972 IOCB_t *icmd;
5973 uint32_t cmd, did;
5974
5975 icmd = &cmdiocb->iocb;
5976 did = icmd->un.elsreq64.remoteID;
5977 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5978 lp = (uint32_t *) pcmd->virt;
5979
5980 cmd = *lp++;
5981 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005982 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5983 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005984 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005985 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005986
5987 return 0;
5988}
5989
James Smarte59058c2008-08-24 21:49:00 -04005990/**
James Smart3621a712009-04-06 18:47:14 -04005991 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005992 * @vport: pointer to a host virtual N_Port data structure.
5993 * @cmdiocb: pointer to lpfc command iocb data structure.
5994 * @fan_ndlp: pointer to a node-list data structure.
5995 *
5996 * This routine processes a Fabric Address Notification (FAN) IOCB
5997 * command received as an ELS unsolicited event. The FAN ELS command will
5998 * only be processed on a physical port (i.e., the @vport represents the
5999 * physical port). The fabric NodeName and PortName from the FAN IOCB are
6000 * compared against those in the phba data structure. If any of those is
6001 * different, the lpfc_initial_flogi() routine is invoked to initialize
6002 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
6003 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
6004 * is invoked to register login to the fabric.
6005 *
6006 * Return code
6007 * 0 - Successfully processed fan iocb (currently always return 0).
6008 **/
dea31012005-04-17 16:05:31 -05006009static int
James Smart2e0fef82007-06-17 19:56:36 -05006010lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6011 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05006012{
James Smart2e0fef82007-06-17 19:56:36 -05006013 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04006014 uint32_t *lp;
6015 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006016
James Smart0d2b6b82008-06-14 22:52:47 -04006017 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
6018 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
6019 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006020 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04006021 if ((vport == phba->pport) &&
6022 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006023 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04006024 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006025 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04006026 sizeof(struct lpfc_name)))) {
6027 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05006028 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04006029 } else {
6030 /* FAN verified - skip FLOGI */
6031 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04006032 if (phba->sli_rev < LPFC_SLI_REV4)
6033 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05006034 else {
6035 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6036 "3138 Need register VFI: (x%x/%x)\n",
6037 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04006038 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05006039 }
dea31012005-04-17 16:05:31 -05006040 }
dea31012005-04-17 16:05:31 -05006041 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006042 return 0;
dea31012005-04-17 16:05:31 -05006043}
6044
James Smarte59058c2008-08-24 21:49:00 -04006045/**
James Smart3621a712009-04-06 18:47:14 -04006046 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04006047 * @ptr: holder for the timer function associated data.
6048 *
6049 * This routine is invoked by the ELS timer after timeout. It posts the ELS
6050 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
6051 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
6052 * up the worker thread. It is for the worker thread to invoke the routine
6053 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
6054 **/
dea31012005-04-17 16:05:31 -05006055void
6056lpfc_els_timeout(unsigned long ptr)
6057{
James Smart2e0fef82007-06-17 19:56:36 -05006058 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
6059 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04006060 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05006061 unsigned long iflag;
6062
James Smart2e0fef82007-06-17 19:56:36 -05006063 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04006064 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
6065 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05006066 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04006067 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05006068
James Smart5e9d9b82008-06-14 22:52:53 -04006069 if (!tmo_posted)
6070 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05006071 return;
6072}
6073
James Smart2a9bf3d2010-06-07 15:24:45 -04006074
James Smarte59058c2008-08-24 21:49:00 -04006075/**
James Smart3621a712009-04-06 18:47:14 -04006076 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04006077 * @vport: pointer to a virtual N_Port data structure.
6078 *
6079 * This routine is the actual handler function that processes an ELS timeout
6080 * event. It walks the ELS ring to get and abort all the IOCBs (except the
6081 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
6082 * invoking the lpfc_sli_issue_abort_iotag() routine.
6083 **/
dea31012005-04-17 16:05:31 -05006084void
James Smart2e0fef82007-06-17 19:56:36 -05006085lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006086{
James Smart2e0fef82007-06-17 19:56:36 -05006087 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006088 struct lpfc_sli_ring *pring;
6089 struct lpfc_iocbq *tmp_iocb, *piocb;
6090 IOCB_t *cmd = NULL;
6091 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05006092 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05006093 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05006094 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04006095 LIST_HEAD(txcmplq_completions);
6096 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05006097
James Smart2a9bf3d2010-06-07 15:24:45 -04006098
dea31012005-04-17 16:05:31 -05006099 timeout = (uint32_t)(phba->fc_ratov << 1);
6100
6101 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006102
James Smart2a9bf3d2010-06-07 15:24:45 -04006103 spin_lock_irq(&phba->hbalock);
6104 list_splice_init(&pring->txcmplq, &txcmplq_completions);
6105 spin_unlock_irq(&phba->hbalock);
6106
6107 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05006108 cmd = &piocb->iocb;
6109
James Smart2e0fef82007-06-17 19:56:36 -05006110 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
6111 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
6112 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05006113 continue;
James Smart2e0fef82007-06-17 19:56:36 -05006114
6115 if (piocb->vport != vport)
6116 continue;
6117
dea31012005-04-17 16:05:31 -05006118 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05006119 if (pcmd)
6120 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05006121
James Smart92d7f7b2007-06-17 19:56:38 -05006122 if (els_command == ELS_CMD_FARP ||
6123 els_command == ELS_CMD_FARPR ||
6124 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05006125 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05006126
dea31012005-04-17 16:05:31 -05006127 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05006128 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05006129 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05006130 else
dea31012005-04-17 16:05:31 -05006131 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05006132 continue;
6133 }
6134
James Smart2e0fef82007-06-17 19:56:36 -05006135 remote_ID = 0xffffffff;
6136 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05006137 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05006138 else {
6139 struct lpfc_nodelist *ndlp;
6140 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04006141 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05006142 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05006143 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006144 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05006145 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006146 spin_lock_irq(&phba->hbalock);
6147 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05006148 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04006149
James Smart2a9bf3d2010-06-07 15:24:45 -04006150 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
6151 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6152 "0127 ELS timeout Data: x%x x%x x%x "
6153 "x%x\n", els_command,
6154 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
6155 spin_lock_irq(&phba->hbalock);
6156 list_del_init(&piocb->dlist);
6157 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6158 spin_unlock_irq(&phba->hbalock);
6159 }
6160
James Smart2e0fef82007-06-17 19:56:36 -05006161 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
6162 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05006163}
6164
James Smarte59058c2008-08-24 21:49:00 -04006165/**
James Smart3621a712009-04-06 18:47:14 -04006166 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04006167 * @vport: pointer to a host virtual N_Port data structure.
6168 *
6169 * This routine is used to clean up all the outstanding ELS commands on a
6170 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
6171 * routine. After that, it walks the ELS transmit queue to remove all the
6172 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
6173 * the IOCBs with a non-NULL completion callback function, the callback
6174 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6175 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
6176 * callback function, the IOCB will simply be released. Finally, it walks
6177 * the ELS transmit completion queue to issue an abort IOCB to any transmit
6178 * completion queue IOCB that is associated with the @vport and is not
6179 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
6180 * part of the discovery state machine) out to HBA by invoking the
6181 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
6182 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
6183 * the IOCBs are aborted when this function returns.
6184 **/
dea31012005-04-17 16:05:31 -05006185void
James Smart2e0fef82007-06-17 19:56:36 -05006186lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006187{
James Smart2534ba72007-04-25 09:52:20 -04006188 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05006189 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04006190 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006191 struct lpfc_iocbq *tmp_iocb, *piocb;
6192 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006193
6194 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05006195
James Smart2e0fef82007-06-17 19:56:36 -05006196 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006197 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6198 cmd = &piocb->iocb;
6199
6200 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6201 continue;
6202 }
6203
6204 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04006205 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6206 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6207 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6208 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05006209 continue;
dea31012005-04-17 16:05:31 -05006210
James Smart2e0fef82007-06-17 19:56:36 -05006211 if (piocb->vport != vport)
6212 continue;
6213
James Smart2534ba72007-04-25 09:52:20 -04006214 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04006215 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05006216 }
6217
6218 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05006219 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6220 continue;
6221 }
dea31012005-04-17 16:05:31 -05006222
James Smart2e0fef82007-06-17 19:56:36 -05006223 if (piocb->vport != vport)
6224 continue;
6225
James Smart07951072007-04-25 09:51:38 -04006226 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05006227 }
James Smart2e0fef82007-06-17 19:56:36 -05006228 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04006229
James Smarta257bf92009-04-06 18:48:10 -04006230 /* Cancell all the IOCBs from the completions list */
6231 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6232 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04006233
dea31012005-04-17 16:05:31 -05006234 return;
6235}
6236
James Smarte59058c2008-08-24 21:49:00 -04006237/**
James Smart3621a712009-04-06 18:47:14 -04006238 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04006239 * @phba: pointer to lpfc hba data structure.
6240 *
6241 * This routine is used to clean up all the outstanding ELS commands on a
6242 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6243 * routine. After that, it walks the ELS transmit queue to remove all the
6244 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6245 * the IOCBs with the completion callback function associated, the callback
6246 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6247 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6248 * callback function associated, the IOCB will simply be released. Finally,
6249 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6250 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6251 * management plane IOCBs that are not part of the discovery state machine)
6252 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6253 **/
James Smart549e55c2007-08-02 11:09:51 -04006254void
6255lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6256{
6257 LIST_HEAD(completions);
6258 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6259 struct lpfc_iocbq *tmp_iocb, *piocb;
6260 IOCB_t *cmd = NULL;
6261
6262 lpfc_fabric_abort_hba(phba);
6263 spin_lock_irq(&phba->hbalock);
6264 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6265 cmd = &piocb->iocb;
6266 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6267 continue;
6268 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6269 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6270 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6271 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6272 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6273 continue;
6274 list_move_tail(&piocb->list, &completions);
6275 pring->txq_cnt--;
6276 }
6277 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6278 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6279 continue;
6280 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6281 }
6282 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04006283
6284 /* Cancel all the IOCBs from the completions list */
6285 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6286 IOERR_SLI_ABORTED);
6287
James Smart549e55c2007-08-02 11:09:51 -04006288 return;
6289}
6290
James Smarte59058c2008-08-24 21:49:00 -04006291/**
James Smart3621a712009-04-06 18:47:14 -04006292 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04006293 * @phba: Pointer to hba context object.
6294 * @cmdiocbp: Pointer to command iocb which reported error.
6295 * @rspiocbp: Pointer to response iocb which reported error.
6296 *
6297 * This function sends an event when there is an ELS command
6298 * failure.
6299 **/
6300void
6301lpfc_send_els_failure_event(struct lpfc_hba *phba,
6302 struct lpfc_iocbq *cmdiocbp,
6303 struct lpfc_iocbq *rspiocbp)
6304{
6305 struct lpfc_vport *vport = cmdiocbp->vport;
6306 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6307 struct lpfc_lsrjt_event lsrjt_event;
6308 struct lpfc_fabric_event_header fabric_event;
6309 struct ls_rjt stat;
6310 struct lpfc_nodelist *ndlp;
6311 uint32_t *pcmd;
6312
6313 ndlp = cmdiocbp->context1;
6314 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6315 return;
6316
6317 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6318 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6319 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6320 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6321 sizeof(struct lpfc_name));
6322 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6323 sizeof(struct lpfc_name));
6324 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6325 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006326 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006327 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6328 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6329 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6330 fc_host_post_vendor_event(shost,
6331 fc_get_event_number(),
6332 sizeof(lsrjt_event),
6333 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006334 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006335 return;
6336 }
6337 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6338 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6339 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6340 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6341 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6342 else
6343 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6344 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6345 sizeof(struct lpfc_name));
6346 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6347 sizeof(struct lpfc_name));
6348 fc_host_post_vendor_event(shost,
6349 fc_get_event_number(),
6350 sizeof(fabric_event),
6351 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006352 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006353 return;
6354 }
6355
6356}
6357
6358/**
James Smart3621a712009-04-06 18:47:14 -04006359 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006360 * @vport: Pointer to vport object.
6361 * @ndlp: Pointer FC node object.
6362 * @cmd: ELS command code.
6363 *
6364 * This function posts an event when there is an incoming
6365 * unsolicited ELS command.
6366 **/
6367static void
6368lpfc_send_els_event(struct lpfc_vport *vport,
6369 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006370 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006371{
James Smartddcc50f2008-12-04 22:38:46 -05006372 struct lpfc_els_event_header *els_data = NULL;
6373 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006374 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6375
James Smartddcc50f2008-12-04 22:38:46 -05006376 if (*payload == ELS_CMD_LOGO) {
6377 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6378 if (!logo_data) {
6379 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6380 "0148 Failed to allocate memory "
6381 "for LOGO event\n");
6382 return;
6383 }
6384 els_data = &logo_data->header;
6385 } else {
6386 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6387 GFP_KERNEL);
6388 if (!els_data) {
6389 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6390 "0149 Failed to allocate memory "
6391 "for ELS event\n");
6392 return;
6393 }
6394 }
6395 els_data->event_type = FC_REG_ELS_EVENT;
6396 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006397 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006398 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006399 break;
6400 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006401 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006402 break;
6403 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006404 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6405 break;
6406 case ELS_CMD_LOGO:
6407 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6408 /* Copy the WWPN in the LOGO payload */
6409 memcpy(logo_data->logo_wwpn, &payload[2],
6410 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006411 break;
6412 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006413 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006414 return;
6415 }
James Smartddcc50f2008-12-04 22:38:46 -05006416 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6417 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6418 if (*payload == ELS_CMD_LOGO) {
6419 fc_host_post_vendor_event(shost,
6420 fc_get_event_number(),
6421 sizeof(struct lpfc_logo_event),
6422 (char *)logo_data,
6423 LPFC_NL_VENDOR_ID);
6424 kfree(logo_data);
6425 } else {
6426 fc_host_post_vendor_event(shost,
6427 fc_get_event_number(),
6428 sizeof(struct lpfc_els_event_header),
6429 (char *)els_data,
6430 LPFC_NL_VENDOR_ID);
6431 kfree(els_data);
6432 }
James Smartea2151b2008-09-07 11:52:10 -04006433
6434 return;
6435}
6436
6437
6438/**
James Smart3621a712009-04-06 18:47:14 -04006439 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006440 * @phba: pointer to lpfc hba data structure.
6441 * @pring: pointer to a SLI ring.
6442 * @vport: pointer to a host virtual N_Port data structure.
6443 * @elsiocb: pointer to lpfc els command iocb data structure.
6444 *
6445 * This routine is used for processing the IOCB associated with a unsolicited
6446 * event. It first determines whether there is an existing ndlp that matches
6447 * the DID from the unsolicited IOCB. If not, it will create a new one with
6448 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6449 * IOCB is then used to invoke the proper routine and to set up proper state
6450 * of the discovery state machine.
6451 **/
James Smarted957682007-06-17 19:56:37 -05006452static void
6453lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006454 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006455{
James Smart87af33f2007-10-27 13:37:43 -04006456 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006457 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006458 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006459 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05006460 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006461 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006462
James Smarte47c9092008-02-08 18:49:26 -05006463 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006464 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006465
dea31012005-04-17 16:05:31 -05006466 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006467 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6468 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006469 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006470 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006471
James Smart858c9f62007-06-17 19:56:39 -05006472 did = icmd->un.rcvels.remoteID;
6473 if (icmd->ulpStatus) {
6474 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6475 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6476 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006477 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006478 }
dea31012005-04-17 16:05:31 -05006479
6480 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006481 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006482 goto dropit;
dea31012005-04-17 16:05:31 -05006483
James Smartc8685952009-11-18 15:39:16 -05006484 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006485 if (vport->load_flag & FC_UNLOADING)
6486 goto dropit;
6487
James Smart92494142011-02-16 12:39:44 -05006488 /* If NPort discovery is delayed drop incoming ELS */
6489 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6490 (cmd != ELS_CMD_PLOGI))
6491 goto dropit;
6492
James Smart2e0fef82007-06-17 19:56:36 -05006493 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006494 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006495 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006496 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006497 if (!ndlp)
dea31012005-04-17 16:05:31 -05006498 goto dropit;
dea31012005-04-17 16:05:31 -05006499
James Smart2e0fef82007-06-17 19:56:36 -05006500 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006501 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006502 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006503 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006504 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006505 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6506 ndlp = lpfc_enable_node(vport, ndlp,
6507 NLP_STE_UNUSED_NODE);
6508 if (!ndlp)
6509 goto dropit;
6510 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6511 newnode = 1;
6512 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6513 ndlp->nlp_type |= NLP_FABRIC;
6514 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6515 /* This is similar to the new node path */
6516 ndlp = lpfc_nlp_get(ndlp);
6517 if (!ndlp)
6518 goto dropit;
6519 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6520 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006521 }
dea31012005-04-17 16:05:31 -05006522
6523 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006524
James Smart329f9bc2007-04-25 09:53:01 -04006525 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006526 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006527
6528 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6529 cmd &= ELS_CMD_MASK;
6530 }
6531 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006532 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6533 "0112 ELS command x%x received from NPORT x%x "
6534 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006535 switch (cmd) {
6536 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006537 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6538 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6539 did, vport->port_state, ndlp->nlp_flag);
6540
dea31012005-04-17 16:05:31 -05006541 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006542 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6543
James Smartddcc50f2008-12-04 22:38:46 -05006544 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05006545
6546 /* If Nport discovery is delayed, reject PLOGIs */
6547 if (vport->fc_flag & FC_DISC_DELAYED) {
6548 rjt_err = LSRJT_UNABLE_TPC;
6549 break;
6550 }
James Smart858c9f62007-06-17 19:56:39 -05006551 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006552 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6553 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6554 rjt_err = LSRJT_UNABLE_TPC;
6555 break;
6556 }
6557 /* We get here, and drop thru, if we are PT2PT with
6558 * another NPort and the other side has initiated
6559 * the PLOGI before responding to our FLOGI.
6560 */
dea31012005-04-17 16:05:31 -05006561 }
James Smart87af33f2007-10-27 13:37:43 -04006562
6563 shost = lpfc_shost_from_vport(vport);
6564 spin_lock_irq(shost->host_lock);
6565 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6566 spin_unlock_irq(shost->host_lock);
6567
James Smart2e0fef82007-06-17 19:56:36 -05006568 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6569 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006570
dea31012005-04-17 16:05:31 -05006571 break;
6572 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006573 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6574 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6575 did, vport->port_state, ndlp->nlp_flag);
6576
dea31012005-04-17 16:05:31 -05006577 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006578 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006579 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006580 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006581 break;
6582 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006583 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6584 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6585 did, vport->port_state, ndlp->nlp_flag);
6586
dea31012005-04-17 16:05:31 -05006587 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006588 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006589 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006590 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006591 break;
6592 }
James Smart2e0fef82007-06-17 19:56:36 -05006593 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006594 break;
6595 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006596 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6597 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6598 did, vport->port_state, ndlp->nlp_flag);
6599
dea31012005-04-17 16:05:31 -05006600 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006601 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006602 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006603 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006604 break;
6605 }
James Smart2e0fef82007-06-17 19:56:36 -05006606 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006607 break;
6608 case ELS_CMD_RSCN:
6609 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006610 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006611 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006612 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006613 break;
6614 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006615 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6616 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6617 did, vport->port_state, ndlp->nlp_flag);
6618
James Smartddcc50f2008-12-04 22:38:46 -05006619 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006620 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006621 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006622 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006623 break;
6624 }
James Smart2e0fef82007-06-17 19:56:36 -05006625 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6626 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006627 break;
6628 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006629 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6630 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6631 did, vport->port_state, ndlp->nlp_flag);
6632
dea31012005-04-17 16:05:31 -05006633 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006634 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006635 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006636 break;
6637 }
James Smart2e0fef82007-06-17 19:56:36 -05006638 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6639 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006640 break;
6641 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006642 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6643 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6644 did, vport->port_state, ndlp->nlp_flag);
6645
dea31012005-04-17 16:05:31 -05006646 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006647 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006648 break;
6649 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006650 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6651 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6652 did, vport->port_state, ndlp->nlp_flag);
6653
dea31012005-04-17 16:05:31 -05006654 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006655 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006656 break;
6657 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006658 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6659 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6660 did, vport->port_state, ndlp->nlp_flag);
6661
dea31012005-04-17 16:05:31 -05006662 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006663 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006664 break;
dea31012005-04-17 16:05:31 -05006665 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006666 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6667 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6668 did, vport->port_state, ndlp->nlp_flag);
6669
dea31012005-04-17 16:05:31 -05006670 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006671 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006672 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006673 break;
6674 }
James Smart2e0fef82007-06-17 19:56:36 -05006675 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006676 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006677 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006678 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6679 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6680 did, vport->port_state, ndlp->nlp_flag);
6681
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006682 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006683 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006684 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006685 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006686 break;
James Smart12265f62010-10-22 11:05:53 -04006687 case ELS_CMD_RLS:
6688 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6689 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6690 did, vport->port_state, ndlp->nlp_flag);
6691
6692 phba->fc_stat.elsRcvRLS++;
6693 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6694 if (newnode)
6695 lpfc_nlp_put(ndlp);
6696 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006697 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006698 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6699 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6700 did, vport->port_state, ndlp->nlp_flag);
6701
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006702 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006703 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006704 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006705 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006706 break;
6707 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006708 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6709 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6710 did, vport->port_state, ndlp->nlp_flag);
6711
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006712 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006713 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006714 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006715 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006716 break;
dea31012005-04-17 16:05:31 -05006717 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006718 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6719 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6720 did, vport->port_state, ndlp->nlp_flag);
6721
dea31012005-04-17 16:05:31 -05006722 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006723 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006724 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006725 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006726 break;
James Smart12265f62010-10-22 11:05:53 -04006727 case ELS_CMD_RTV:
6728 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6729 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6730 did, vport->port_state, ndlp->nlp_flag);
6731 phba->fc_stat.elsRcvRTV++;
6732 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6733 if (newnode)
6734 lpfc_nlp_put(ndlp);
6735 break;
James Smart5ffc2662009-11-18 15:39:44 -05006736 case ELS_CMD_RRQ:
6737 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6738 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6739 did, vport->port_state, ndlp->nlp_flag);
6740
6741 phba->fc_stat.elsRcvRRQ++;
6742 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6743 if (newnode)
6744 lpfc_nlp_put(ndlp);
6745 break;
James Smart12265f62010-10-22 11:05:53 -04006746 case ELS_CMD_ECHO:
6747 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6748 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6749 did, vport->port_state, ndlp->nlp_flag);
6750
6751 phba->fc_stat.elsRcvECHO++;
6752 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6753 if (newnode)
6754 lpfc_nlp_put(ndlp);
6755 break;
dea31012005-04-17 16:05:31 -05006756 default:
James Smart858c9f62007-06-17 19:56:39 -05006757 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6758 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6759 cmd, did, vport->port_state);
6760
dea31012005-04-17 16:05:31 -05006761 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006762 rjt_err = LSRJT_CMD_UNSUPPORTED;
dea31012005-04-17 16:05:31 -05006763
6764 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006765 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6766 "0115 Unknown ELS command x%x "
6767 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006768 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006769 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006770 break;
6771 }
6772
6773 /* check if need to LS_RJT received ELS cmd */
6774 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006775 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006776 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006777 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006778 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6779 NULL);
dea31012005-04-17 16:05:31 -05006780 }
6781
James Smartd7c255b2008-08-24 21:50:00 -04006782 lpfc_nlp_put(elsiocb->context1);
6783 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006784 return;
6785
6786dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006787 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006788 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6789 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006790 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006791 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006792 phba->fc_stat.elsRcvDrop++;
6793}
6794
James Smarte59058c2008-08-24 21:49:00 -04006795/**
James Smart3621a712009-04-06 18:47:14 -04006796 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006797 * @phba: pointer to lpfc hba data structure.
6798 * @pring: pointer to a SLI ring.
6799 * @elsiocb: pointer to lpfc els iocb data structure.
6800 *
6801 * This routine is used to process an unsolicited event received from a SLI
6802 * (Service Level Interface) ring. The actual processing of the data buffer
6803 * associated with the unsolicited event is done by invoking the routine
6804 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6805 * SLI ring on which the unsolicited event was received.
6806 **/
James Smarted957682007-06-17 19:56:37 -05006807void
6808lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6809 struct lpfc_iocbq *elsiocb)
6810{
6811 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006812 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006813 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006814 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6815 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006816
James Smartd7c255b2008-08-24 21:50:00 -04006817 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006818 elsiocb->context2 = NULL;
6819 elsiocb->context3 = NULL;
6820
6821 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6822 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6823 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6824 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006825 phba->fc_stat.NoRcvBuf++;
6826 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006827 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006828 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006829 return;
6830 }
6831
James Smart92d7f7b2007-06-17 19:56:38 -05006832 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6833 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6834 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6835 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6836 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006837 else
6838 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04006839 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05006840 }
James Smart6d368e52011-05-24 11:44:12 -04006841
James Smart7f5f3d02008-02-08 18:50:14 -05006842 /* If there are no BDEs associated
6843 * with this IOCB, there is nothing to do.
6844 */
James Smarted957682007-06-17 19:56:37 -05006845 if (icmd->ulpBdeCount == 0)
6846 return;
6847
James Smart7f5f3d02008-02-08 18:50:14 -05006848 /* type of ELS cmd is first 32bit word
6849 * in packet
6850 */
James Smarted957682007-06-17 19:56:37 -05006851 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006852 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006853 } else {
6854 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6855 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006856 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6857 paddr);
James Smarted957682007-06-17 19:56:37 -05006858 }
6859
James Smart92d7f7b2007-06-17 19:56:38 -05006860 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6861 /*
6862 * The different unsolicited event handlers would tell us
6863 * if they are done with "mp" by setting context2 to NULL.
6864 */
dea31012005-04-17 16:05:31 -05006865 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006866 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6867 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006868 }
James Smarted957682007-06-17 19:56:37 -05006869
6870 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006871 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006872 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006873 elsiocb->context2 = bdeBuf2;
6874 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006875 /* free mp if we are done with it */
6876 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006877 lpfc_in_buf_free(phba, elsiocb->context2);
6878 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006879 }
dea31012005-04-17 16:05:31 -05006880 }
dea31012005-04-17 16:05:31 -05006881}
James Smart92d7f7b2007-06-17 19:56:38 -05006882
James Smarte59058c2008-08-24 21:49:00 -04006883/**
James Smart3621a712009-04-06 18:47:14 -04006884 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006885 * @phba: pointer to lpfc hba data structure.
6886 * @vport: pointer to a virtual N_Port data structure.
6887 *
6888 * This routine issues a Port Login (PLOGI) to the Name Server with
6889 * State Change Request (SCR) for a @vport. This routine will create an
6890 * ndlp for the Name Server associated to the @vport if such node does
6891 * not already exist. The PLOGI to Name Server is issued by invoking the
6892 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6893 * (FDMI) is configured to the @vport, a FDMI node will be created and
6894 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6895 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006896void
6897lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6898{
6899 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05006900 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6901
6902 /*
6903 * If lpfc_delay_discovery parameter is set and the clean address
6904 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6905 * discovery.
6906 */
6907 spin_lock_irq(shost->host_lock);
6908 if (vport->fc_flag & FC_DISC_DELAYED) {
6909 spin_unlock_irq(shost->host_lock);
6910 mod_timer(&vport->delayed_disc_tmo,
6911 jiffies + HZ * phba->fc_ratov);
6912 return;
6913 }
6914 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006915
6916 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6917 if (!ndlp) {
6918 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6919 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006920 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05006921 lpfc_disc_start(vport);
6922 return;
6923 }
6924 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006925 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6926 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006927 return;
6928 }
6929 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006930 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6931 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6932 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006933 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05006934 lpfc_disc_start(vport);
6935 return;
6936 }
6937 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6938 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6939 "0348 NameServer login: node freed\n");
6940 return;
6941 }
James Smart92d7f7b2007-06-17 19:56:38 -05006942 }
James Smart58da1ff2008-04-07 10:15:56 -04006943 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006944
6945 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6946
6947 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6948 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006949 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6950 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006951 return;
6952 }
6953
James Smart3de2a652007-08-02 11:09:59 -04006954 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05006955 /* If this is the first time, allocate an ndlp and initialize
6956 * it. Otherwise, make sure the node is enabled and then do the
6957 * login.
6958 */
6959 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
6960 if (!ndlp_fdmi) {
6961 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6962 GFP_KERNEL);
6963 if (ndlp_fdmi) {
6964 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6965 ndlp_fdmi->nlp_type |= NLP_FABRIC;
6966 } else
6967 return;
6968 }
6969 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
6970 ndlp_fdmi = lpfc_enable_node(vport,
6971 ndlp_fdmi,
6972 NLP_STE_NPR_NODE);
6973
James Smart92d7f7b2007-06-17 19:56:38 -05006974 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04006975 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05006976 NLP_STE_PLOGI_ISSUE);
6977 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006978 }
6979 }
James Smart92d7f7b2007-06-17 19:56:38 -05006980}
6981
James Smarte59058c2008-08-24 21:49:00 -04006982/**
James Smart3621a712009-04-06 18:47:14 -04006983 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006984 * @phba: pointer to lpfc hba data structure.
6985 * @pmb: pointer to the driver internal queue element for mailbox command.
6986 *
6987 * This routine is the completion callback function to register new vport
6988 * mailbox command. If the new vport mailbox command completes successfully,
6989 * the fabric registration login shall be performed on physical port (the
6990 * new vport created is actually a physical port, with VPI 0) or the port
6991 * login to Name Server for State Change Request (SCR) will be performed
6992 * on virtual port (real virtual port, with VPI greater than 0).
6993 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006994static void
6995lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6996{
6997 struct lpfc_vport *vport = pmb->vport;
6998 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6999 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04007000 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05007001 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007002
James Smart09372822008-01-11 01:52:54 -05007003 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007004 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05007005 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007006
7007 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04007008 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04007009 "0915 Register VPI failed : Status: x%x"
7010 " upd bit: x%x \n", mb->mbxStatus,
7011 mb->un.varRegVpi.upd);
7012 if (phba->sli_rev == LPFC_SLI_REV4 &&
7013 mb->un.varRegVpi.upd)
7014 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05007015
7016 switch (mb->mbxStatus) {
7017 case 0x11: /* unsupported feature */
7018 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05007019 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05007020 /* giving up on vport registration */
7021 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7022 spin_lock_irq(shost->host_lock);
7023 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7024 spin_unlock_irq(shost->host_lock);
7025 lpfc_can_disctmo(vport);
7026 break;
James Smart695a8142010-01-26 23:08:03 -05007027 /* If reg_vpi fail with invalid VPI status, re-init VPI */
7028 case 0x20:
7029 spin_lock_irq(shost->host_lock);
7030 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7031 spin_unlock_irq(shost->host_lock);
7032 lpfc_init_vpi(phba, pmb, vport->vpi);
7033 pmb->vport = vport;
7034 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
7035 rc = lpfc_sli_issue_mbox(phba, pmb,
7036 MBX_NOWAIT);
7037 if (rc == MBX_NOT_FINISHED) {
7038 lpfc_printf_vlog(vport,
7039 KERN_ERR, LOG_MBOX,
7040 "2732 Failed to issue INIT_VPI"
7041 " mailbox command\n");
7042 } else {
7043 lpfc_nlp_put(ndlp);
7044 return;
7045 }
7046
James Smart92d7f7b2007-06-17 19:56:38 -05007047 default:
7048 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04007049 if (phba->sli_rev == LPFC_SLI_REV4)
7050 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007051 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05007052 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007053 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05007054 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04007055 if (vport->port_type == LPFC_PHYSICAL_PORT
7056 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05007057 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05007058 else
7059 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007060 break;
7061 }
James Smart92d7f7b2007-06-17 19:56:38 -05007062 } else {
James Smart695a8142010-01-26 23:08:03 -05007063 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05007064 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05007065 spin_unlock_irq(shost->host_lock);
7066 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04007067 if (phba->sli_rev < LPFC_SLI_REV4)
7068 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05007069 else {
James Smartfc2b9892010-02-26 14:15:29 -05007070 /*
7071 * If the physical port is instantiated using
7072 * FDISC, do not start vport discovery.
7073 */
7074 if (vport->port_state != LPFC_FDISC)
7075 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05007076 lpfc_do_scr_ns_plogi(phba, vport);
7077 }
7078 } else
James Smart92d7f7b2007-06-17 19:56:38 -05007079 lpfc_do_scr_ns_plogi(phba, vport);
7080 }
James Smart38b92ef2010-08-04 16:11:39 -04007081mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05007082 /* Now, we decrement the ndlp reference count held for this
7083 * callback function
7084 */
7085 lpfc_nlp_put(ndlp);
7086
James Smart92d7f7b2007-06-17 19:56:38 -05007087 mempool_free(pmb, phba->mbox_mem_pool);
7088 return;
7089}
7090
James Smarte59058c2008-08-24 21:49:00 -04007091/**
James Smart3621a712009-04-06 18:47:14 -04007092 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04007093 * @phba: pointer to lpfc hba data structure.
7094 * @vport: pointer to a host virtual N_Port data structure.
7095 * @ndlp: pointer to a node-list data structure.
7096 *
7097 * This routine registers the @vport as a new virtual port with a HBA.
7098 * It is done through a registering vpi mailbox command.
7099 **/
James Smart695a8142010-01-26 23:08:03 -05007100void
James Smart92d7f7b2007-06-17 19:56:38 -05007101lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
7102 struct lpfc_nodelist *ndlp)
7103{
James Smart09372822008-01-11 01:52:54 -05007104 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007105 LPFC_MBOXQ_t *mbox;
7106
7107 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7108 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04007109 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05007110 mbox->vport = vport;
7111 mbox->context2 = lpfc_nlp_get(ndlp);
7112 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04007113 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05007114 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05007115 /* mailbox command not success, decrement ndlp
7116 * reference count for this command
7117 */
7118 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007119 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05007120
James Smarte8b62012007-08-02 11:10:09 -04007121 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7122 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05007123 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007124 }
7125 } else {
James Smarte8b62012007-08-02 11:10:09 -04007126 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7127 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05007128 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007129 }
James Smartfa4066b2008-01-11 01:53:27 -05007130 return;
7131
7132mbox_err_exit:
7133 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7134 spin_lock_irq(shost->host_lock);
7135 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
7136 spin_unlock_irq(shost->host_lock);
7137 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007138}
7139
James Smarte59058c2008-08-24 21:49:00 -04007140/**
James Smart0c9ab6f2010-02-26 14:15:57 -05007141 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05007142 * @phba: pointer to lpfc hba data structure.
7143 *
James Smart0c9ab6f2010-02-26 14:15:57 -05007144 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05007145 **/
7146void
James Smart0c9ab6f2010-02-26 14:15:57 -05007147lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05007148{
7149 struct lpfc_vport **vports;
7150 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05007151 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05007152 int i;
James Smart695a8142010-01-26 23:08:03 -05007153
7154 /* Treat this failure as linkdown for all vports */
7155 link_state = phba->link_state;
7156 lpfc_linkdown(phba);
7157 phba->link_state = link_state;
7158
7159 vports = lpfc_create_vport_work_array(phba);
7160
7161 if (vports) {
7162 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
7163 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
7164 if (ndlp)
7165 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
7166 lpfc_els_flush_cmd(vports[i]);
7167 }
7168 lpfc_destroy_vport_work_array(phba, vports);
7169 }
James Smart0c9ab6f2010-02-26 14:15:57 -05007170}
7171
7172/**
7173 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7174 * @phba: pointer to lpfc hba data structure.
7175 *
7176 * This routine abort all pending discovery commands and
7177 * start a timer to retry FLOGI for the physical port
7178 * discovery.
7179 **/
7180void
7181lpfc_retry_pport_discovery(struct lpfc_hba *phba)
7182{
7183 struct lpfc_nodelist *ndlp;
7184 struct Scsi_Host *shost;
7185
7186 /* Cancel the all vports retry delay retry timers */
7187 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05007188
7189 /* If fabric require FLOGI, then re-instantiate physical login */
7190 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
7191 if (!ndlp)
7192 return;
7193
James Smart695a8142010-01-26 23:08:03 -05007194 shost = lpfc_shost_from_vport(phba->pport);
7195 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
7196 spin_lock_irq(shost->host_lock);
7197 ndlp->nlp_flag |= NLP_DELAY_TMO;
7198 spin_unlock_irq(shost->host_lock);
7199 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7200 phba->pport->port_state = LPFC_FLOGI;
7201 return;
7202}
7203
7204/**
7205 * lpfc_fabric_login_reqd - Check if FLOGI required.
7206 * @phba: pointer to lpfc hba data structure.
7207 * @cmdiocb: pointer to FDISC command iocb.
7208 * @rspiocb: pointer to FDISC response iocb.
7209 *
7210 * This routine checks if a FLOGI is reguired for FDISC
7211 * to succeed.
7212 **/
7213static int
7214lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7215 struct lpfc_iocbq *cmdiocb,
7216 struct lpfc_iocbq *rspiocb)
7217{
7218
7219 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7220 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7221 return 0;
7222 else
7223 return 1;
7224}
7225
7226/**
James Smart3621a712009-04-06 18:47:14 -04007227 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007228 * @phba: pointer to lpfc hba data structure.
7229 * @cmdiocb: pointer to lpfc command iocb data structure.
7230 * @rspiocb: pointer to lpfc response iocb data structure.
7231 *
7232 * This routine is the completion callback function to a Fabric Discover
7233 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7234 * single threaded, each FDISC completion callback function will reset
7235 * the discovery timer for all vports such that the timers will not get
7236 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7237 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7238 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7239 * assigned to the vport has been changed with the completion of the FDISC
7240 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7241 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7242 * routine is invoked to register new vport with the HBA. Otherwise, the
7243 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7244 * Server for State Change Request (SCR).
7245 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007246static void
7247lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7248 struct lpfc_iocbq *rspiocb)
7249{
7250 struct lpfc_vport *vport = cmdiocb->vport;
7251 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7252 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7253 struct lpfc_nodelist *np;
7254 struct lpfc_nodelist *next_np;
7255 IOCB_t *irsp = &rspiocb->iocb;
7256 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05007257 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7258 struct serv_parm *sp;
7259 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05007260
James Smarte8b62012007-08-02 11:10:09 -04007261 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7262 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7263 irsp->ulpStatus, irsp->un.ulpWord[4],
7264 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05007265 /* Since all FDISCs are being single threaded, we
7266 * must reset the discovery timer for ALL vports
7267 * waiting to send FDISC when one completes.
7268 */
7269 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7270 lpfc_set_disctmo(piocb->vport);
7271 }
7272
James Smart858c9f62007-06-17 19:56:39 -05007273 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7274 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7275 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7276
James Smart92d7f7b2007-06-17 19:56:38 -05007277 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05007278
7279 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7280 lpfc_retry_pport_discovery(phba);
7281 goto out;
7282 }
7283
James Smart92d7f7b2007-06-17 19:56:38 -05007284 /* Check for retry */
7285 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7286 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007287 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04007288 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart6b5151f2012-01-18 16:24:06 -05007289 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04007290 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04007291 goto fdisc_failed;
7292 }
James Smartd7c255b2008-08-24 21:50:00 -04007293 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05007294 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04007295 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04007296 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05007297 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04007298 vport->fc_flag |= FC_PUBLIC_LOOP;
7299 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007300
James Smartd7c255b2008-08-24 21:50:00 -04007301 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7302 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05007303 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7304 sp = prsp->virt + sizeof(uint32_t);
7305 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7306 memcpy(&vport->fabric_portname, &sp->portName,
7307 sizeof(struct lpfc_name));
7308 memcpy(&vport->fabric_nodename, &sp->nodeName,
7309 sizeof(struct lpfc_name));
7310 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04007311 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7312 /* If our NportID changed, we need to ensure all
7313 * remaining NPORTs get unreg_login'ed so we can
7314 * issue unreg_vpi.
7315 */
7316 list_for_each_entry_safe(np, next_np,
7317 &vport->fc_nodes, nlp_listp) {
7318 if (!NLP_CHK_NODE_ACT(ndlp) ||
7319 (np->nlp_state != NLP_STE_NPR_NODE) ||
7320 !(np->nlp_flag & NLP_NPR_ADISC))
7321 continue;
James Smart09372822008-01-11 01:52:54 -05007322 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007323 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007324 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007325 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007326 }
James Smart78730cf2010-04-06 15:06:30 -04007327 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007328
7329 if (phba->sli_rev == LPFC_SLI_REV4)
7330 lpfc_sli4_unreg_all_rpis(vport);
7331
James Smartd7c255b2008-08-24 21:50:00 -04007332 lpfc_mbx_unreg_vpi(vport);
7333 spin_lock_irq(shost->host_lock);
7334 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007335 if (phba->sli_rev == LPFC_SLI_REV4)
7336 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007337 else
7338 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007339 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007340 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7341 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7342 /*
7343 * Driver needs to re-reg VPI in order for f/w
7344 * to update the MAC address.
7345 */
7346 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007347 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007348 }
7349
James Smartecfd03c2010-02-12 14:41:27 -05007350 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7351 lpfc_issue_init_vpi(vport);
7352 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007353 lpfc_register_new_vport(phba, vport, ndlp);
7354 else
7355 lpfc_do_scr_ns_plogi(phba, vport);
7356 goto out;
7357fdisc_failed:
7358 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7359 /* Cancel discovery timer */
7360 lpfc_can_disctmo(vport);
7361 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007362out:
7363 lpfc_els_free_iocb(phba, cmdiocb);
7364}
7365
James Smarte59058c2008-08-24 21:49:00 -04007366/**
James Smart3621a712009-04-06 18:47:14 -04007367 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007368 * @vport: pointer to a virtual N_Port data structure.
7369 * @ndlp: pointer to a node-list data structure.
7370 * @retry: number of retries to the command IOCB.
7371 *
7372 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7373 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7374 * routine to issue the IOCB, which makes sure only one outstanding fabric
7375 * IOCB will be sent off HBA at any given time.
7376 *
7377 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7378 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7379 * will be stored into the context1 field of the IOCB for the completion
7380 * callback function to the FDISC ELS command.
7381 *
7382 * Return code
7383 * 0 - Successfully issued fdisc iocb command
7384 * 1 - Failed to issue fdisc iocb command
7385 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007386static int
James Smart92d7f7b2007-06-17 19:56:38 -05007387lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7388 uint8_t retry)
7389{
7390 struct lpfc_hba *phba = vport->phba;
7391 IOCB_t *icmd;
7392 struct lpfc_iocbq *elsiocb;
7393 struct serv_parm *sp;
7394 uint8_t *pcmd;
7395 uint16_t cmdsize;
7396 int did = ndlp->nlp_DID;
7397 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007398
James Smart5ffc2662009-11-18 15:39:44 -05007399 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05007400 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007401 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7402 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7403 ELS_CMD_FDISC);
7404 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007405 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007406 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7407 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007408 return 1;
7409 }
7410
7411 icmd = &elsiocb->iocb;
7412 icmd->un.elsreq64.myID = 0;
7413 icmd->un.elsreq64.fl = 1;
7414
James Smart73d91e52011-10-10 21:32:10 -04007415 /*
7416 * SLI3 ports require a different context type value than SLI4.
7417 * Catch SLI3 ports here and override the prep.
7418 */
7419 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04007420 icmd->ulpCt_h = 1;
7421 icmd->ulpCt_l = 0;
7422 }
James Smart92d7f7b2007-06-17 19:56:38 -05007423
7424 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7425 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7426 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7427 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7428 sp = (struct serv_parm *) pcmd;
7429 /* Setup CSPs accordingly for Fabric */
7430 sp->cmn.e_d_tov = 0;
7431 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05007432 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007433 sp->cls1.classValid = 0;
7434 sp->cls2.seqDelivery = 1;
7435 sp->cls3.seqDelivery = 1;
7436
7437 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7438 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7439 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7440 pcmd += sizeof(uint32_t); /* Port Name */
7441 memcpy(pcmd, &vport->fc_portname, 8);
7442 pcmd += sizeof(uint32_t); /* Node Name */
7443 pcmd += sizeof(uint32_t); /* Node Name */
7444 memcpy(pcmd, &vport->fc_nodename, 8);
7445
7446 lpfc_set_disctmo(vport);
7447
7448 phba->fc_stat.elsXmitFDISC++;
7449 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7450
James Smart858c9f62007-06-17 19:56:39 -05007451 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7452 "Issue FDISC: did:x%x",
7453 did, 0, 0);
7454
James Smart92d7f7b2007-06-17 19:56:38 -05007455 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7456 if (rc == IOCB_ERROR) {
7457 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007458 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007459 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7460 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007461 return 1;
7462 }
7463 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007464 return 0;
7465}
7466
James Smarte59058c2008-08-24 21:49:00 -04007467/**
James Smart3621a712009-04-06 18:47:14 -04007468 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007469 * @phba: pointer to lpfc hba data structure.
7470 * @cmdiocb: pointer to lpfc command iocb data structure.
7471 * @rspiocb: pointer to lpfc response iocb data structure.
7472 *
7473 * This routine is the completion callback function to the issuing of a LOGO
7474 * ELS command off a vport. It frees the command IOCB and then decrement the
7475 * reference count held on ndlp for this completion function, indicating that
7476 * the reference to the ndlp is no long needed. Note that the
7477 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7478 * callback function and an additional explicit ndlp reference decrementation
7479 * will trigger the actual release of the ndlp.
7480 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007481static void
7482lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7483 struct lpfc_iocbq *rspiocb)
7484{
7485 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007486 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007487 struct lpfc_nodelist *ndlp;
James Smart9589b062011-04-16 11:03:17 -04007488 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05007489
James Smart9589b062011-04-16 11:03:17 -04007490 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007491 irsp = &rspiocb->iocb;
7492 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7493 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7494 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007495
7496 lpfc_els_free_iocb(phba, cmdiocb);
7497 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007498
7499 /* Trigger the release of the ndlp after logo */
7500 lpfc_nlp_put(ndlp);
James Smart9589b062011-04-16 11:03:17 -04007501
7502 /* NPIV LOGO completes to NPort <nlp_DID> */
7503 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7504 "2928 NPIV LOGO completes to NPort x%x "
7505 "Data: x%x x%x x%x x%x\n",
7506 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
7507 irsp->ulpTimeout, vport->num_disc_nodes);
7508
7509 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
7510 spin_lock_irq(shost->host_lock);
7511 vport->fc_flag &= ~FC_FABRIC;
7512 spin_unlock_irq(shost->host_lock);
7513 }
James Smart92d7f7b2007-06-17 19:56:38 -05007514}
7515
James Smarte59058c2008-08-24 21:49:00 -04007516/**
James Smart3621a712009-04-06 18:47:14 -04007517 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007518 * @vport: pointer to a virtual N_Port data structure.
7519 * @ndlp: pointer to a node-list data structure.
7520 *
7521 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7522 *
7523 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7524 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7525 * will be stored into the context1 field of the IOCB for the completion
7526 * callback function to the LOGO ELS command.
7527 *
7528 * Return codes
7529 * 0 - Successfully issued logo off the @vport
7530 * 1 - Failed to issue logo off the @vport
7531 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007532int
7533lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7534{
7535 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7536 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007537 IOCB_t *icmd;
7538 struct lpfc_iocbq *elsiocb;
7539 uint8_t *pcmd;
7540 uint16_t cmdsize;
7541
7542 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7543 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7544 ELS_CMD_LOGO);
7545 if (!elsiocb)
7546 return 1;
7547
7548 icmd = &elsiocb->iocb;
7549 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7550 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7551 pcmd += sizeof(uint32_t);
7552
7553 /* Fill in LOGO payload */
7554 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7555 pcmd += sizeof(uint32_t);
7556 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7557
James Smart858c9f62007-06-17 19:56:39 -05007558 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7559 "Issue LOGO npiv did:x%x flg:x%x",
7560 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7561
James Smart92d7f7b2007-06-17 19:56:38 -05007562 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7563 spin_lock_irq(shost->host_lock);
7564 ndlp->nlp_flag |= NLP_LOGO_SND;
7565 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007566 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7567 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007568 spin_lock_irq(shost->host_lock);
7569 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7570 spin_unlock_irq(shost->host_lock);
7571 lpfc_els_free_iocb(phba, elsiocb);
7572 return 1;
7573 }
7574 return 0;
7575}
7576
James Smarte59058c2008-08-24 21:49:00 -04007577/**
James Smart3621a712009-04-06 18:47:14 -04007578 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007579 * @ptr: holder for the timer function associated data.
7580 *
7581 * This routine is invoked by the fabric iocb block timer after
7582 * timeout. It posts the fabric iocb block timeout event by setting the
7583 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7584 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7585 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7586 * posted event WORKER_FABRIC_BLOCK_TMO.
7587 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007588void
7589lpfc_fabric_block_timeout(unsigned long ptr)
7590{
7591 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7592 unsigned long iflags;
7593 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007594
James Smart92d7f7b2007-06-17 19:56:38 -05007595 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7596 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7597 if (!tmo_posted)
7598 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7599 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7600
James Smart5e9d9b82008-06-14 22:52:53 -04007601 if (!tmo_posted)
7602 lpfc_worker_wake_up(phba);
7603 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007604}
7605
James Smarte59058c2008-08-24 21:49:00 -04007606/**
James Smart3621a712009-04-06 18:47:14 -04007607 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007608 * @phba: pointer to lpfc hba data structure.
7609 *
7610 * This routine issues one fabric iocb from the driver internal list to
7611 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7612 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7613 * remove one pending fabric iocb from the driver internal list and invokes
7614 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7615 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007616static void
7617lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7618{
7619 struct lpfc_iocbq *iocb;
7620 unsigned long iflags;
7621 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007622 IOCB_t *cmd;
7623
7624repeat:
7625 iocb = NULL;
7626 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007627 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007628 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7629 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7630 list);
7631 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007632 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007633 atomic_inc(&phba->fabric_iocb_count);
7634 }
7635 spin_unlock_irqrestore(&phba->hbalock, iflags);
7636 if (iocb) {
7637 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7638 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7639 iocb->iocb_flag |= LPFC_IO_FABRIC;
7640
James Smart858c9f62007-06-17 19:56:39 -05007641 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7642 "Fabric sched1: ste:x%x",
7643 iocb->vport->port_state, 0, 0);
7644
James Smart3772a992009-05-22 14:50:54 -04007645 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007646
7647 if (ret == IOCB_ERROR) {
7648 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7649 iocb->fabric_iocb_cmpl = NULL;
7650 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7651 cmd = &iocb->iocb;
7652 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7653 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7654 iocb->iocb_cmpl(phba, iocb, iocb);
7655
7656 atomic_dec(&phba->fabric_iocb_count);
7657 goto repeat;
7658 }
7659 }
7660
7661 return;
7662}
7663
James Smarte59058c2008-08-24 21:49:00 -04007664/**
James Smart3621a712009-04-06 18:47:14 -04007665 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007666 * @phba: pointer to lpfc hba data structure.
7667 *
7668 * This routine unblocks the issuing fabric iocb command. The function
7669 * will clear the fabric iocb block bit and then invoke the routine
7670 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7671 * from the driver internal fabric iocb list.
7672 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007673void
7674lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7675{
7676 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7677
7678 lpfc_resume_fabric_iocbs(phba);
7679 return;
7680}
7681
James Smarte59058c2008-08-24 21:49:00 -04007682/**
James Smart3621a712009-04-06 18:47:14 -04007683 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007684 * @phba: pointer to lpfc hba data structure.
7685 *
7686 * This routine blocks the issuing fabric iocb for a specified amount of
7687 * time (currently 100 ms). This is done by set the fabric iocb block bit
7688 * and set up a timeout timer for 100ms. When the block bit is set, no more
7689 * fabric iocb will be issued out of the HBA.
7690 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007691static void
7692lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7693{
7694 int blocked;
7695
7696 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007697 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007698 if (!blocked)
7699 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7700
7701 return;
7702}
7703
James Smarte59058c2008-08-24 21:49:00 -04007704/**
James Smart3621a712009-04-06 18:47:14 -04007705 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007706 * @phba: pointer to lpfc hba data structure.
7707 * @cmdiocb: pointer to lpfc command iocb data structure.
7708 * @rspiocb: pointer to lpfc response iocb data structure.
7709 *
7710 * This routine is the callback function that is put to the fabric iocb's
7711 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7712 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7713 * function first restores and invokes the original iocb's callback function
7714 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7715 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7716 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007717static void
7718lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7719 struct lpfc_iocbq *rspiocb)
7720{
7721 struct ls_rjt stat;
7722
7723 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7724 BUG();
7725
7726 switch (rspiocb->iocb.ulpStatus) {
7727 case IOSTAT_NPORT_RJT:
7728 case IOSTAT_FABRIC_RJT:
7729 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7730 lpfc_block_fabric_iocbs(phba);
7731 }
7732 break;
7733
7734 case IOSTAT_NPORT_BSY:
7735 case IOSTAT_FABRIC_BSY:
7736 lpfc_block_fabric_iocbs(phba);
7737 break;
7738
7739 case IOSTAT_LS_RJT:
7740 stat.un.lsRjtError =
7741 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7742 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7743 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7744 lpfc_block_fabric_iocbs(phba);
7745 break;
7746 }
7747
7748 if (atomic_read(&phba->fabric_iocb_count) == 0)
7749 BUG();
7750
7751 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7752 cmdiocb->fabric_iocb_cmpl = NULL;
7753 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7754 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7755
7756 atomic_dec(&phba->fabric_iocb_count);
7757 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007758 /* Post any pending iocbs to HBA */
7759 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007760 }
7761}
7762
James Smarte59058c2008-08-24 21:49:00 -04007763/**
James Smart3621a712009-04-06 18:47:14 -04007764 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007765 * @phba: pointer to lpfc hba data structure.
7766 * @iocb: pointer to lpfc command iocb data structure.
7767 *
7768 * This routine is used as the top-level API for issuing a fabric iocb command
7769 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7770 * function makes sure that only one fabric bound iocb will be outstanding at
7771 * any given time. As such, this function will first check to see whether there
7772 * is already an outstanding fabric iocb on the wire. If so, it will put the
7773 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7774 * issued later. Otherwise, it will issue the iocb on the wire and update the
7775 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7776 *
7777 * Note, this implementation has a potential sending out fabric IOCBs out of
7778 * order. The problem is caused by the construction of the "ready" boolen does
7779 * not include the condition that the internal fabric IOCB list is empty. As
7780 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7781 * ahead of the fabric IOCBs in the internal list.
7782 *
7783 * Return code
7784 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7785 * IOCB_ERROR - failed to issue fabric iocb
7786 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007787static int
James Smart92d7f7b2007-06-17 19:56:38 -05007788lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7789{
7790 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007791 int ready;
7792 int ret;
7793
7794 if (atomic_read(&phba->fabric_iocb_count) > 1)
7795 BUG();
7796
7797 spin_lock_irqsave(&phba->hbalock, iflags);
7798 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7799 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7800
James Smart7f5f3d02008-02-08 18:50:14 -05007801 if (ready)
7802 /* Increment fabric iocb count to hold the position */
7803 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007804 spin_unlock_irqrestore(&phba->hbalock, iflags);
7805 if (ready) {
7806 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7807 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7808 iocb->iocb_flag |= LPFC_IO_FABRIC;
7809
James Smart858c9f62007-06-17 19:56:39 -05007810 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7811 "Fabric sched2: ste:x%x",
7812 iocb->vport->port_state, 0, 0);
7813
James Smart3772a992009-05-22 14:50:54 -04007814 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007815
7816 if (ret == IOCB_ERROR) {
7817 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7818 iocb->fabric_iocb_cmpl = NULL;
7819 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7820 atomic_dec(&phba->fabric_iocb_count);
7821 }
7822 } else {
7823 spin_lock_irqsave(&phba->hbalock, iflags);
7824 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7825 spin_unlock_irqrestore(&phba->hbalock, iflags);
7826 ret = IOCB_SUCCESS;
7827 }
7828 return ret;
7829}
7830
James Smarte59058c2008-08-24 21:49:00 -04007831/**
James Smart3621a712009-04-06 18:47:14 -04007832 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007833 * @vport: pointer to a virtual N_Port data structure.
7834 *
7835 * This routine aborts all the IOCBs associated with a @vport from the
7836 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7837 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7838 * list, removes each IOCB associated with the @vport off the list, set the
7839 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7840 * associated with the IOCB.
7841 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007842static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007843{
7844 LIST_HEAD(completions);
7845 struct lpfc_hba *phba = vport->phba;
7846 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007847
7848 spin_lock_irq(&phba->hbalock);
7849 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7850 list) {
7851
7852 if (piocb->vport != vport)
7853 continue;
7854
7855 list_move_tail(&piocb->list, &completions);
7856 }
7857 spin_unlock_irq(&phba->hbalock);
7858
James Smarta257bf92009-04-06 18:48:10 -04007859 /* Cancel all the IOCBs from the completions list */
7860 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7861 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007862}
7863
James Smarte59058c2008-08-24 21:49:00 -04007864/**
James Smart3621a712009-04-06 18:47:14 -04007865 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007866 * @ndlp: pointer to a node-list data structure.
7867 *
7868 * This routine aborts all the IOCBs associated with an @ndlp from the
7869 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7870 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7871 * list, removes each IOCB associated with the @ndlp off the list, set the
7872 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7873 * associated with the IOCB.
7874 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007875void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7876{
7877 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007878 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007879 struct lpfc_iocbq *tmp_iocb, *piocb;
7880 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007881
7882 spin_lock_irq(&phba->hbalock);
7883 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7884 list) {
7885 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7886
7887 list_move_tail(&piocb->list, &completions);
7888 }
7889 }
7890 spin_unlock_irq(&phba->hbalock);
7891
James Smarta257bf92009-04-06 18:48:10 -04007892 /* Cancel all the IOCBs from the completions list */
7893 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7894 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007895}
7896
James Smarte59058c2008-08-24 21:49:00 -04007897/**
James Smart3621a712009-04-06 18:47:14 -04007898 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007899 * @phba: pointer to lpfc hba data structure.
7900 *
7901 * This routine aborts all the IOCBs currently on the driver internal
7902 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7903 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7904 * list, removes IOCBs off the list, set the status feild to
7905 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7906 * the IOCB.
7907 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007908void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7909{
7910 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007911
7912 spin_lock_irq(&phba->hbalock);
7913 list_splice_init(&phba->fabric_iocb_list, &completions);
7914 spin_unlock_irq(&phba->hbalock);
7915
James Smarta257bf92009-04-06 18:48:10 -04007916 /* Cancel all the IOCBs from the completions list */
7917 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7918 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007919}
James Smart6fb120a2009-05-22 14:52:59 -04007920
7921/**
James Smart1151e3e2011-02-16 12:39:35 -05007922 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7923 * @vport: pointer to lpfc vport data structure.
7924 *
7925 * This routine is invoked by the vport cleanup for deletions and the cleanup
7926 * for an ndlp on removal.
7927 **/
7928void
7929lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
7930{
7931 struct lpfc_hba *phba = vport->phba;
7932 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7933 unsigned long iflag = 0;
7934
7935 spin_lock_irqsave(&phba->hbalock, iflag);
7936 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7937 list_for_each_entry_safe(sglq_entry, sglq_next,
7938 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7939 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
7940 sglq_entry->ndlp = NULL;
7941 }
7942 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7943 spin_unlock_irqrestore(&phba->hbalock, iflag);
7944 return;
7945}
7946
7947/**
James Smart6fb120a2009-05-22 14:52:59 -04007948 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7949 * @phba: pointer to lpfc hba data structure.
7950 * @axri: pointer to the els xri abort wcqe structure.
7951 *
7952 * This routine is invoked by the worker thread to process a SLI4 slow-path
7953 * ELS aborted xri.
7954 **/
7955void
7956lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7957 struct sli4_wcqe_xri_aborted *axri)
7958{
7959 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05007960 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04007961 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05007962
James Smart6fb120a2009-05-22 14:52:59 -04007963 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7964 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05007965 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04007966 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007967
James Smart0f65ff62010-02-26 14:14:23 -05007968 spin_lock_irqsave(&phba->hbalock, iflag);
7969 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007970 list_for_each_entry_safe(sglq_entry, sglq_next,
7971 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7972 if (sglq_entry->sli4_xritag == xri) {
7973 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05007974 ndlp = sglq_entry->ndlp;
7975 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04007976 list_add_tail(&sglq_entry->list,
7977 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007978 sglq_entry->state = SGL_FREED;
7979 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007980 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartee0f4fe2012-05-09 21:19:14 -04007981 lpfc_set_rrq_active(phba, ndlp,
7982 sglq_entry->sli4_lxritag,
7983 rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04007984
7985 /* Check if TXQ queue needs to be serviced */
7986 if (pring->txq_cnt)
7987 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007988 return;
7989 }
7990 }
James Smart0f65ff62010-02-26 14:14:23 -05007991 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04007992 lxri = lpfc_sli4_xri_inrange(phba, xri);
7993 if (lxri == NO_XRI) {
7994 spin_unlock_irqrestore(&phba->hbalock, iflag);
7995 return;
7996 }
7997 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05007998 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7999 spin_unlock_irqrestore(&phba->hbalock, iflag);
8000 return;
8001 }
8002 sglq_entry->state = SGL_XRI_ABORTED;
8003 spin_unlock_irqrestore(&phba->hbalock, iflag);
8004 return;
James Smart6fb120a2009-05-22 14:52:59 -04008005}