blob: 1725b81770e92b5a99fe24afa7661082f3cf68d2 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart92494142011-02-16 12:39:44 -05004 * Copyright (C) 2004-2011 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050021/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_transport_fc.h>
31
James Smartda0436e2009-05-22 14:51:39 -040032#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050033#include "lpfc_hw.h"
34#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040036#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_disc.h"
38#include "lpfc_scsi.h"
39#include "lpfc.h"
40#include "lpfc_logmsg.h"
41#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050042#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050043#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050044
45static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
46 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050047static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
48 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010049static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
50static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
51 struct lpfc_nodelist *ndlp, uint8_t retry);
52static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
53 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050054
dea31012005-04-17 16:05:31 -050055static int lpfc_max_els_tries = 3;
56
James Smarte59058c2008-08-24 21:49:00 -040057/**
James Smart3621a712009-04-06 18:47:14 -040058 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040059 * @vport: pointer to a host virtual N_Port data structure.
60 *
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
68 * had happened.
69 *
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
74 *
75 * Return codes
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
78 **/
James Smart858c9f62007-06-17 19:56:39 -050079int
James Smart2e0fef82007-06-17 19:56:36 -050080lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050081{
James Smart2e0fef82007-06-17 19:56:36 -050082 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
83 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050084 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050085
James Smart2e0fef82007-06-17 19:56:36 -050086 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040087 phba->link_state == LPFC_LINK_DOWN ||
88 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050089 return 0;
90
91 /* Read the HBA Host Attention Register */
James Smart9940b972011-03-11 16:06:12 -050092 if (lpfc_readl(phba->HAregaddr, &ha_copy))
93 return 1;
dea31012005-04-17 16:05:31 -050094
95 if (!(ha_copy & HA_LATT))
96 return 0;
97
98 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040099 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
100 "0237 Pending Link Event during "
101 "Discovery: State x%x\n",
102 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500103
104 /* CLEAR_LA should re-enable link attention events and
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300105 * we should then immediately take a LATT event. The
dea31012005-04-17 16:05:31 -0500106 * LATT processing should call lpfc_linkdown() which
107 * will cleanup any left over in-progress discovery
108 * events.
109 */
James Smart2e0fef82007-06-17 19:56:36 -0500110 spin_lock_irq(shost->host_lock);
111 vport->fc_flag |= FC_ABORT_DISCOVERY;
112 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500113
James Smart92d7f7b2007-06-17 19:56:38 -0500114 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500115 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500116
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500117 return 1;
dea31012005-04-17 16:05:31 -0500118}
119
James Smarte59058c2008-08-24 21:49:00 -0400120/**
James Smart3621a712009-04-06 18:47:14 -0400121 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400122 * @vport: pointer to a host virtual N_Port data structure.
123 * @expectRsp: flag indicating whether response is expected.
124 * @cmdSize: size of the ELS command.
125 * @retry: number of retries to the command IOCB when it fails.
126 * @ndlp: pointer to a node-list data structure.
127 * @did: destination identifier.
128 * @elscmd: the ELS command code.
129 *
130 * This routine is used for allocating a lpfc-IOCB data structure from
131 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
132 * passed into the routine for discovery state machine to issue an Extended
133 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
134 * and preparation routine that is used by all the discovery state machine
135 * routines and the ELS command-specific fields will be later set up by
136 * the individual discovery machine routines after calling this routine
137 * allocating and preparing a generic IOCB data structure. It fills in the
138 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
139 * payload and response payload (if expected). The reference count on the
140 * ndlp is incremented by 1 and the reference to the ndlp is put into
141 * context1 of the IOCB data structure for this IOCB to hold the ndlp
142 * reference for the command's callback function to access later.
143 *
144 * Return code
145 * Pointer to the newly allocated/prepared els iocb data structure
146 * NULL - when els iocb data structure allocation/preparation failed
147 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400148struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500149lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
150 uint16_t cmdSize, uint8_t retry,
151 struct lpfc_nodelist *ndlp, uint32_t did,
152 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500153{
James Smart2e0fef82007-06-17 19:56:36 -0500154 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400155 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500156 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
157 struct ulp_bde64 *bpl;
158 IOCB_t *icmd;
159
dea31012005-04-17 16:05:31 -0500160
James Smart2e0fef82007-06-17 19:56:36 -0500161 if (!lpfc_is_link_up(phba))
162 return NULL;
dea31012005-04-17 16:05:31 -0500163
dea31012005-04-17 16:05:31 -0500164 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400165 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500166
167 if (elsiocb == NULL)
168 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500169
James Smart0c287582009-06-10 17:22:56 -0400170 /*
171 * If this command is for fabric controller and HBA running
172 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
173 */
174 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400175 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400176 ((elscmd == ELS_CMD_FLOGI) ||
177 (elscmd == ELS_CMD_FDISC) ||
178 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500179 switch (elscmd) {
180 case ELS_CMD_FLOGI:
James Smartf0d9bcc2010-10-22 11:07:09 -0400181 elsiocb->iocb_flag |=
182 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500183 & LPFC_FIP_ELS_ID_MASK);
184 break;
185 case ELS_CMD_FDISC:
James Smartf0d9bcc2010-10-22 11:07:09 -0400186 elsiocb->iocb_flag |=
187 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500188 & LPFC_FIP_ELS_ID_MASK);
189 break;
190 case ELS_CMD_LOGO:
James Smartf0d9bcc2010-10-22 11:07:09 -0400191 elsiocb->iocb_flag |=
192 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500193 & LPFC_FIP_ELS_ID_MASK);
194 break;
195 }
James Smart0c287582009-06-10 17:22:56 -0400196 else
James Smartc8685952009-11-18 15:39:16 -0500197 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400198
dea31012005-04-17 16:05:31 -0500199 icmd = &elsiocb->iocb;
200
201 /* fill in BDEs for command */
202 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400203 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
204 if (pcmd)
205 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500206 if (!pcmd || !pcmd->virt)
207 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500208
209 INIT_LIST_HEAD(&pcmd->list);
210
211 /* Allocate buffer for response payload */
212 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500213 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500214 if (prsp)
215 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
216 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500217 if (!prsp || !prsp->virt)
218 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500219 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500220 } else
dea31012005-04-17 16:05:31 -0500221 prsp = NULL;
dea31012005-04-17 16:05:31 -0500222
223 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500224 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500225 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500226 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
227 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500228 if (!pbuflist || !pbuflist->virt)
229 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500230
231 INIT_LIST_HEAD(&pbuflist->list);
232
233 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
234 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400235 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart2e0fef82007-06-17 19:56:36 -0500236 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500237 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500238 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500239 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400240 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500241 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500242 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500243 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
244 }
dea31012005-04-17 16:05:31 -0500245 icmd->ulpBdeCount = 1;
246 icmd->ulpLe = 1;
247 icmd->ulpClass = CLASS3;
248
James Smart92d7f7b2007-06-17 19:56:38 -0500249 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
250 icmd->un.elsreq64.myID = vport->fc_myDID;
251
252 /* For ELS_REQUEST64_CR, use the VPI by default */
James Smart6d368e52011-05-24 11:44:12 -0400253 icmd->ulpContext = phba->vpi_ids[vport->vpi];
James Smart92d7f7b2007-06-17 19:56:38 -0500254 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500255 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
256 if (elscmd == ELS_CMD_ECHO)
257 icmd->ulpCt_l = 0; /* context = invalid RPI */
258 else
259 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500260 }
261
dea31012005-04-17 16:05:31 -0500262 bpl = (struct ulp_bde64 *) pbuflist->virt;
263 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
264 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
265 bpl->tus.f.bdeSize = cmdSize;
266 bpl->tus.f.bdeFlags = 0;
267 bpl->tus.w = le32_to_cpu(bpl->tus.w);
268
269 if (expectRsp) {
270 bpl++;
271 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
272 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
273 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400274 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500275 bpl->tus.w = le32_to_cpu(bpl->tus.w);
276 }
277
James Smartfa4066b2008-01-11 01:53:27 -0500278 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400279 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500280 if (!elsiocb->context1)
281 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400282 elsiocb->context2 = pcmd;
283 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500284 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500285 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500286 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
287
288 if (prsp) {
289 list_add(&prsp->list, &pcmd->list);
290 }
dea31012005-04-17 16:05:31 -0500291 if (expectRsp) {
292 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400293 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
294 "0116 Xmit ELS command x%x to remote "
295 "NPORT x%x I/O tag: x%x, port state: x%x\n",
296 elscmd, did, elsiocb->iotag,
297 vport->port_state);
dea31012005-04-17 16:05:31 -0500298 } else {
299 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400300 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
301 "0117 Xmit ELS response x%x to remote "
302 "NPORT x%x I/O tag: x%x, size: x%x\n",
303 elscmd, ndlp->nlp_DID, elsiocb->iotag,
304 cmdSize);
dea31012005-04-17 16:05:31 -0500305 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500306 return elsiocb;
dea31012005-04-17 16:05:31 -0500307
James Smartfa4066b2008-01-11 01:53:27 -0500308els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500309 if (expectRsp)
310 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500311 kfree(pbuflist);
312
313els_iocb_free_prsp_exit:
314 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
315 kfree(prsp);
316
317els_iocb_free_pcmb_exit:
318 kfree(pcmd);
319 lpfc_sli_release_iocbq(phba, elsiocb);
320 return NULL;
321}
dea31012005-04-17 16:05:31 -0500322
James Smarte59058c2008-08-24 21:49:00 -0400323/**
James Smart3621a712009-04-06 18:47:14 -0400324 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400325 * @vport: pointer to a host virtual N_Port data structure.
326 *
327 * This routine issues a fabric registration login for a @vport. An
328 * active ndlp node with Fabric_DID must already exist for this @vport.
329 * The routine invokes two mailbox commands to carry out fabric registration
330 * login through the HBA firmware: the first mailbox command requests the
331 * HBA to perform link configuration for the @vport; and the second mailbox
332 * command requests the HBA to perform the actual fabric registration login
333 * with the @vport.
334 *
335 * Return code
336 * 0 - successfully issued fabric registration login for @vport
337 * -ENXIO -- failed to issue fabric registration login for @vport
338 **/
James Smart3772a992009-05-22 14:50:54 -0400339int
James Smart92d7f7b2007-06-17 19:56:38 -0500340lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
341{
342 struct lpfc_hba *phba = vport->phba;
343 LPFC_MBOXQ_t *mbox;
344 struct lpfc_dmabuf *mp;
345 struct lpfc_nodelist *ndlp;
346 struct serv_parm *sp;
347 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400348 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500349
350 sp = &phba->fc_fabparam;
351 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500352 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400353 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500354 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400355 }
James Smart92d7f7b2007-06-17 19:56:38 -0500356
357 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400358 if (!mbox) {
359 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500360 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400361 }
James Smart92d7f7b2007-06-17 19:56:38 -0500362
363 vport->port_state = LPFC_FABRIC_CFG_LINK;
364 lpfc_config_link(phba, mbox);
365 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
366 mbox->vport = vport;
367
James Smart0b727fe2007-10-27 13:37:25 -0400368 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400369 if (rc == MBX_NOT_FINISHED) {
370 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500371 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400372 }
James Smart92d7f7b2007-06-17 19:56:38 -0500373
374 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400375 if (!mbox) {
376 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500377 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400378 }
James Smart40426292010-12-15 17:58:10 -0500379 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
380 ndlp->nlp_rpi);
James Smart98c9ea52007-10-27 13:37:33 -0400381 if (rc) {
382 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500383 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400384 }
James Smart92d7f7b2007-06-17 19:56:38 -0500385
386 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
387 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500388 /* increment the reference count on ndlp to hold reference
389 * for the callback routine.
390 */
James Smart92d7f7b2007-06-17 19:56:38 -0500391 mbox->context2 = lpfc_nlp_get(ndlp);
392
James Smart0b727fe2007-10-27 13:37:25 -0400393 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400394 if (rc == MBX_NOT_FINISHED) {
395 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500396 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400397 }
James Smart92d7f7b2007-06-17 19:56:38 -0500398
399 return 0;
400
401fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500402 /* decrement the reference count on ndlp just incremented
403 * for the failed mbox command.
404 */
James Smart92d7f7b2007-06-17 19:56:38 -0500405 lpfc_nlp_put(ndlp);
406 mp = (struct lpfc_dmabuf *) mbox->context1;
407 lpfc_mbuf_free(phba, mp->virt, mp->phys);
408 kfree(mp);
409fail_free_mbox:
410 mempool_free(mbox, phba->mbox_mem_pool);
411
412fail:
413 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400414 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400415 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500416 return -ENXIO;
417}
418
James Smarte59058c2008-08-24 21:49:00 -0400419/**
James Smart6fb120a2009-05-22 14:52:59 -0400420 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
421 * @vport: pointer to a host virtual N_Port data structure.
422 *
423 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
424 * the @vport. This mailbox command is necessary for FCoE only.
425 *
426 * Return code
427 * 0 - successfully issued REG_VFI for @vport
428 * A failure code otherwise.
429 **/
430static int
431lpfc_issue_reg_vfi(struct lpfc_vport *vport)
432{
433 struct lpfc_hba *phba = vport->phba;
434 LPFC_MBOXQ_t *mboxq;
435 struct lpfc_nodelist *ndlp;
436 struct serv_parm *sp;
437 struct lpfc_dmabuf *dmabuf;
438 int rc = 0;
439
440 sp = &phba->fc_fabparam;
441 ndlp = lpfc_findnode_did(vport, Fabric_DID);
442 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
443 rc = -ENODEV;
444 goto fail;
445 }
446
447 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
448 if (!dmabuf) {
449 rc = -ENOMEM;
450 goto fail;
451 }
452 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
453 if (!dmabuf->virt) {
454 rc = -ENOMEM;
455 goto fail_free_dmabuf;
456 }
James Smart6d368e52011-05-24 11:44:12 -0400457
James Smart6fb120a2009-05-22 14:52:59 -0400458 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
459 if (!mboxq) {
460 rc = -ENOMEM;
461 goto fail_free_coherent;
462 }
463 vport->port_state = LPFC_FABRIC_CFG_LINK;
464 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
465 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
466 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
467 mboxq->vport = vport;
468 mboxq->context1 = dmabuf;
469 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
470 if (rc == MBX_NOT_FINISHED) {
471 rc = -ENXIO;
472 goto fail_free_mbox;
473 }
474 return 0;
475
476fail_free_mbox:
477 mempool_free(mboxq, phba->mbox_mem_pool);
478fail_free_coherent:
479 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
480fail_free_dmabuf:
481 kfree(dmabuf);
482fail:
483 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
484 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
485 "0289 Issue Register VFI failed: Err %d\n", rc);
486 return rc;
487}
488
489/**
James Smart92494142011-02-16 12:39:44 -0500490 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
491 * @vport: pointer to a host virtual N_Port data structure.
492 * @sp: pointer to service parameter data structure.
493 *
494 * This routine is called from FLOGI/FDISC completion handler functions.
495 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
496 * node nodename is changed in the completion service parameter else return
497 * 0. This function also set flag in the vport data structure to delay
498 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
499 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
500 * node nodename is changed in the completion service parameter.
501 *
502 * Return code
503 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
504 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
505 *
506 **/
507static uint8_t
508lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
509 struct serv_parm *sp)
510{
511 uint8_t fabric_param_changed = 0;
512 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
513
514 if ((vport->fc_prevDID != vport->fc_myDID) ||
515 memcmp(&vport->fabric_portname, &sp->portName,
516 sizeof(struct lpfc_name)) ||
517 memcmp(&vport->fabric_nodename, &sp->nodeName,
518 sizeof(struct lpfc_name)))
519 fabric_param_changed = 1;
520
521 /*
522 * Word 1 Bit 31 in common service parameter is overloaded.
523 * Word 1 Bit 31 in FLOGI request is multiple NPort request
524 * Word 1 Bit 31 in FLOGI response is clean address bit
525 *
526 * If fabric parameter is changed and clean address bit is
527 * cleared delay nport discovery if
528 * - vport->fc_prevDID != 0 (not initial discovery) OR
529 * - lpfc_delay_discovery module parameter is set.
530 */
531 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
532 (vport->fc_prevDID || lpfc_delay_discovery)) {
533 spin_lock_irq(shost->host_lock);
534 vport->fc_flag |= FC_DISC_DELAYED;
535 spin_unlock_irq(shost->host_lock);
536 }
537
538 return fabric_param_changed;
539}
540
541
542/**
James Smart3621a712009-04-06 18:47:14 -0400543 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400544 * @vport: pointer to a host virtual N_Port data structure.
545 * @ndlp: pointer to a node-list data structure.
546 * @sp: pointer to service parameter data structure.
547 * @irsp: pointer to the IOCB within the lpfc response IOCB.
548 *
549 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
550 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
551 * port in a fabric topology. It properly sets up the parameters to the @ndlp
552 * from the IOCB response. It also check the newly assigned N_Port ID to the
553 * @vport against the previously assigned N_Port ID. If it is different from
554 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
555 * is invoked on all the remaining nodes with the @vport to unregister the
556 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
557 * is invoked to register login to the fabric.
558 *
559 * Return code
560 * 0 - Success (currently, always return 0)
561 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500562static int
James Smart2e0fef82007-06-17 19:56:36 -0500563lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
564 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500565{
James Smart2e0fef82007-06-17 19:56:36 -0500566 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
567 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500568 struct lpfc_nodelist *np;
569 struct lpfc_nodelist *next_np;
James Smart92494142011-02-16 12:39:44 -0500570 uint8_t fabric_param_changed;
dea31012005-04-17 16:05:31 -0500571
James Smart2e0fef82007-06-17 19:56:36 -0500572 spin_lock_irq(shost->host_lock);
573 vport->fc_flag |= FC_FABRIC;
574 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500575
576 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
577 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
578 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
579
James Smart12265f62010-10-22 11:05:53 -0400580 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500581 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
582
James Smart76a95d72010-11-20 23:11:48 -0500583 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500584 spin_lock_irq(shost->host_lock);
585 vport->fc_flag |= FC_PUBLIC_LOOP;
586 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500587 }
588
James Smart2e0fef82007-06-17 19:56:36 -0500589 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500590 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500591 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500592 ndlp->nlp_class_sup = 0;
593 if (sp->cls1.classValid)
594 ndlp->nlp_class_sup |= FC_COS_CLASS1;
595 if (sp->cls2.classValid)
596 ndlp->nlp_class_sup |= FC_COS_CLASS2;
597 if (sp->cls3.classValid)
598 ndlp->nlp_class_sup |= FC_COS_CLASS3;
599 if (sp->cls4.classValid)
600 ndlp->nlp_class_sup |= FC_COS_CLASS4;
601 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
602 sp->cmn.bbRcvSizeLsb;
James Smart92494142011-02-16 12:39:44 -0500603
604 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
605 memcpy(&vport->fabric_portname, &sp->portName,
606 sizeof(struct lpfc_name));
607 memcpy(&vport->fabric_nodename, &sp->nodeName,
608 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500609 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
610
James Smart92d7f7b2007-06-17 19:56:38 -0500611 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
612 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400613 lpfc_printf_vlog(vport, KERN_WARNING,
614 LOG_ELS | LOG_VPORT,
615 "1816 FLOGI NPIV supported, "
616 "response data 0x%x\n",
617 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500618 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500619 } else {
620 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400621 to call reg_vnpid atleast for the physcial host */
622 lpfc_printf_vlog(vport, KERN_WARNING,
623 LOG_ELS | LOG_VPORT,
624 "1817 Fabric does not support NPIV "
625 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500626 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
627 }
628 }
629
James Smart92494142011-02-16 12:39:44 -0500630 if (fabric_param_changed &&
James Smart92d7f7b2007-06-17 19:56:38 -0500631 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
632
633 /* If our NportID changed, we need to ensure all
634 * remaining NPORTs get unreg_login'ed.
635 */
636 list_for_each_entry_safe(np, next_np,
637 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400638 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500639 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500640 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
641 !(np->nlp_flag & NLP_NPR_ADISC))
642 continue;
643 spin_lock_irq(shost->host_lock);
644 np->nlp_flag &= ~NLP_NPR_ADISC;
645 spin_unlock_irq(shost->host_lock);
646 lpfc_unreg_rpi(vport, np);
647 }
James Smart78730cf2010-04-06 15:06:30 -0400648 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400649
James Smart5248a742011-07-22 18:37:06 -0400650 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart5af5eee2010-10-22 11:06:38 -0400651 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500652 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500653 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500654 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart5248a742011-07-22 18:37:06 -0400655 /*
656 * If VPI is unreged, driver need to do INIT_VPI
657 * before re-registering
658 */
James Smartecfd03c2010-02-12 14:41:27 -0500659 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
660 spin_unlock_irq(shost->host_lock);
661 }
James Smart38b92ef2010-08-04 16:11:39 -0400662 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
663 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
664 /*
665 * Driver needs to re-reg VPI in order for f/w
666 * to update the MAC address.
667 */
James Smart9589b062011-04-16 11:03:17 -0400668 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400669 lpfc_register_new_vport(phba, vport, ndlp);
670 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500671 }
672
James Smart6fb120a2009-05-22 14:52:59 -0400673 if (phba->sli_rev < LPFC_SLI_REV4) {
674 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
675 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
676 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
677 lpfc_register_new_vport(phba, vport, ndlp);
678 else
679 lpfc_issue_fabric_reglogin(vport);
680 } else {
681 ndlp->nlp_type |= NLP_FABRIC;
682 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500683 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
684 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400685 lpfc_start_fdiscs(phba);
686 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500687 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500688 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500689 else
James Smart6fb120a2009-05-22 14:52:59 -0400690 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500691 }
dea31012005-04-17 16:05:31 -0500692 return 0;
dea31012005-04-17 16:05:31 -0500693}
James Smarte59058c2008-08-24 21:49:00 -0400694/**
James Smart3621a712009-04-06 18:47:14 -0400695 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400696 * @vport: pointer to a host virtual N_Port data structure.
697 * @ndlp: pointer to a node-list data structure.
698 * @sp: pointer to service parameter data structure.
699 *
700 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
701 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
702 * in a point-to-point topology. First, the @vport's N_Port Name is compared
703 * with the received N_Port Name: if the @vport's N_Port Name is greater than
704 * the received N_Port Name lexicographically, this node shall assign local
705 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
706 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
707 * this node shall just wait for the remote node to issue PLOGI and assign
708 * N_Port IDs.
709 *
710 * Return code
711 * 0 - Success
712 * -ENXIO - Fail
713 **/
dea31012005-04-17 16:05:31 -0500714static int
James Smart2e0fef82007-06-17 19:56:36 -0500715lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
716 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500717{
James Smart2e0fef82007-06-17 19:56:36 -0500718 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
719 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500720 LPFC_MBOXQ_t *mbox;
721 int rc;
722
James Smart2e0fef82007-06-17 19:56:36 -0500723 spin_lock_irq(shost->host_lock);
724 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
725 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500726
727 phba->fc_edtov = FF_DEF_EDTOV;
728 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500729 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500730 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500731 if (rc >= 0) {
732 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500733 spin_lock_irq(shost->host_lock);
734 vport->fc_flag |= FC_PT2PT_PLOGI;
735 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500736
737 /*
738 * N_Port ID cannot be 0, set our to LocalID the other
739 * side will be RemoteID.
740 */
741
742 /* not equal */
743 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500744 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500745
746 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
747 if (!mbox)
748 goto fail;
749
750 lpfc_config_link(phba, mbox);
751
752 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500753 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400754 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500755 if (rc == MBX_NOT_FINISHED) {
756 mempool_free(mbox, phba->mbox_mem_pool);
757 goto fail;
758 }
James Smarte47c9092008-02-08 18:49:26 -0500759 /* Decrement ndlp reference count indicating that ndlp can be
760 * safely released when other references to it are done.
761 */
James Smart329f9bc2007-04-25 09:53:01 -0400762 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500763
James Smart2e0fef82007-06-17 19:56:36 -0500764 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500765 if (!ndlp) {
766 /*
767 * Cannot find existing Fabric ndlp, so allocate a
768 * new one
769 */
770 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
771 if (!ndlp)
772 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500773 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500774 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
775 ndlp = lpfc_enable_node(vport, ndlp,
776 NLP_STE_UNUSED_NODE);
777 if(!ndlp)
778 goto fail;
dea31012005-04-17 16:05:31 -0500779 }
780
781 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500782 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500783 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500784 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500785 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500786 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
787 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500788 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500789 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500790 } else
791 /* This side will wait for the PLOGI, decrement ndlp reference
792 * count indicating that ndlp can be released when other
793 * references to it are done.
794 */
James Smart329f9bc2007-04-25 09:53:01 -0400795 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500796
James Smart09372822008-01-11 01:52:54 -0500797 /* If we are pt2pt with another NPort, force NPIV off! */
798 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
799
James Smart2e0fef82007-06-17 19:56:36 -0500800 spin_lock_irq(shost->host_lock);
801 vport->fc_flag |= FC_PT2PT;
802 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500803
804 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500805 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500806 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500807fail:
dea31012005-04-17 16:05:31 -0500808 return -ENXIO;
809}
810
James Smarte59058c2008-08-24 21:49:00 -0400811/**
James Smart3621a712009-04-06 18:47:14 -0400812 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400813 * @phba: pointer to lpfc hba data structure.
814 * @cmdiocb: pointer to lpfc command iocb data structure.
815 * @rspiocb: pointer to lpfc response iocb data structure.
816 *
817 * This routine is the top-level completion callback function for issuing
818 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
819 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
820 * retry has been made (either immediately or delayed with lpfc_els_retry()
821 * returning 1), the command IOCB will be released and function returned.
822 * If the retry attempt has been given up (possibly reach the maximum
823 * number of retries), one additional decrement of ndlp reference shall be
824 * invoked before going out after releasing the command IOCB. This will
825 * actually release the remote node (Note, lpfc_els_free_iocb() will also
826 * invoke one decrement of ndlp reference count). If no error reported in
827 * the IOCB status, the command Port ID field is used to determine whether
828 * this is a point-to-point topology or a fabric topology: if the Port ID
829 * field is assigned, it is a fabric topology; otherwise, it is a
830 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
831 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
832 * specific topology completion conditions.
833 **/
dea31012005-04-17 16:05:31 -0500834static void
James Smart329f9bc2007-04-25 09:53:01 -0400835lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
836 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500837{
James Smart2e0fef82007-06-17 19:56:36 -0500838 struct lpfc_vport *vport = cmdiocb->vport;
839 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500840 IOCB_t *irsp = &rspiocb->iocb;
841 struct lpfc_nodelist *ndlp = cmdiocb->context1;
842 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
843 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500844 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500845 int rc;
846
847 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500848 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500849 /* One additional decrement on node reference count to
850 * trigger the release of the node
851 */
James Smart329f9bc2007-04-25 09:53:01 -0400852 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500853 goto out;
854 }
855
James Smart858c9f62007-06-17 19:56:39 -0500856 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
857 "FLOGI cmpl: status:x%x/x%x state:x%x",
858 irsp->ulpStatus, irsp->un.ulpWord[4],
859 vport->port_state);
860
dea31012005-04-17 16:05:31 -0500861 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500862 /*
James Smarta93ff372010-10-22 11:06:08 -0400863 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500864 * due to new FCF discovery
865 */
866 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smartdbb6b3a2010-06-08 18:31:37 -0400867 (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
James Smart9589b062011-04-16 11:03:17 -0400868 !((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
869 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500870 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400871 "2611 FLOGI failed on FCF (x%x), "
872 "status:x%x/x%x, tmo:x%x, perform "
873 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -0400874 phba->fcf.current_rec.fcf_indx,
875 irsp->ulpStatus, irsp->un.ulpWord[4],
876 irsp->ulpTimeout);
James Smart0c9ab6f2010-02-26 14:15:57 -0500877 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -0400878 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
879 if (rc)
880 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500881 }
882
James Smart38b92ef2010-08-04 16:11:39 -0400883 /* FLOGI failure */
884 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
885 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
886 irsp->ulpStatus, irsp->un.ulpWord[4],
887 irsp->ulpTimeout);
888
dea31012005-04-17 16:05:31 -0500889 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500890 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500891 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500892
James Smart76a95d72010-11-20 23:11:48 -0500893 /* FLOGI failure */
894 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
895 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
896 irsp->ulpStatus, irsp->un.ulpWord[4],
897 irsp->ulpTimeout);
898
dea31012005-04-17 16:05:31 -0500899 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500900 spin_lock_irq(shost->host_lock);
901 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
902 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500903
James Smart329f9bc2007-04-25 09:53:01 -0400904 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500905 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
906 * alpa map would take too long otherwise.
907 */
908 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400909 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smart76a95d72010-11-20 23:11:48 -0500910 if ((phba->sli_rev == LPFC_SLI_REV4) &&
911 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
912 (vport->fc_prevDID != vport->fc_myDID))) {
913 if (vport->fc_flag & FC_VFI_REGISTERED)
914 lpfc_sli4_unreg_all_rpis(vport);
915 lpfc_issue_reg_vfi(vport);
916 lpfc_nlp_put(ndlp);
917 goto out;
918 }
dea31012005-04-17 16:05:31 -0500919 }
dea31012005-04-17 16:05:31 -0500920 goto flogifail;
921 }
James Smart695a8142010-01-26 23:08:03 -0500922 spin_lock_irq(shost->host_lock);
923 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400924 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500925 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500926
927 /*
928 * The FLogI succeeded. Sync the data for the CPU before
929 * accessing it.
930 */
931 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
932
933 sp = prsp->virt + sizeof(uint32_t);
934
935 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400936 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200937 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400938 "Data: x%x x%x x%x x%x\n",
939 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
940 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500941
James Smart2e0fef82007-06-17 19:56:36 -0500942 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500943 /*
944 * If Common Service Parameters indicate Nport
945 * we are point to point, if Fport we are Fabric.
946 */
947 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500948 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -0500949 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -0500950 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400951 else {
952 lpfc_printf_vlog(vport, KERN_ERR,
953 LOG_FIP | LOG_ELS,
954 "2831 FLOGI response with cleared Fabric "
955 "bit fcf_index 0x%x "
956 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
957 "Fabric Name "
958 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
959 phba->fcf.current_rec.fcf_indx,
960 phba->fcf.current_rec.switch_name[0],
961 phba->fcf.current_rec.switch_name[1],
962 phba->fcf.current_rec.switch_name[2],
963 phba->fcf.current_rec.switch_name[3],
964 phba->fcf.current_rec.switch_name[4],
965 phba->fcf.current_rec.switch_name[5],
966 phba->fcf.current_rec.switch_name[6],
967 phba->fcf.current_rec.switch_name[7],
968 phba->fcf.current_rec.fabric_name[0],
969 phba->fcf.current_rec.fabric_name[1],
970 phba->fcf.current_rec.fabric_name[2],
971 phba->fcf.current_rec.fabric_name[3],
972 phba->fcf.current_rec.fabric_name[4],
973 phba->fcf.current_rec.fabric_name[5],
974 phba->fcf.current_rec.fabric_name[6],
975 phba->fcf.current_rec.fabric_name[7]);
976 lpfc_nlp_put(ndlp);
977 spin_lock_irq(&phba->hbalock);
978 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400979 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -0400980 spin_unlock_irq(&phba->hbalock);
981 goto out;
982 }
James Smart0c9ab6f2010-02-26 14:15:57 -0500983 if (!rc) {
984 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400985 if (phba->hba_flag & HBA_FIP_SUPPORT)
986 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
987 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400988 "2769 FLOGI to FCF (x%x) "
989 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -0400990 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500991 spin_lock_irq(&phba->hbalock);
992 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400993 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -0500994 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500995 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500996 }
dea31012005-04-17 16:05:31 -0500997 }
998
999flogifail:
James Smart329f9bc2007-04-25 09:53:01 -04001000 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001001
James Smart858c9f62007-06-17 19:56:39 -05001002 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001003 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001004 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001005
1006 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001007 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001008 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1009 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
1010 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
1011 (phba->link_state != LPFC_CLEAR_LA)) {
1012 /* If FLOGI failed enable link interrupt. */
1013 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001014 }
dea31012005-04-17 16:05:31 -05001015out:
1016 lpfc_els_free_iocb(phba, cmdiocb);
1017}
1018
James Smarte59058c2008-08-24 21:49:00 -04001019/**
James Smart3621a712009-04-06 18:47:14 -04001020 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001021 * @vport: pointer to a host virtual N_Port data structure.
1022 * @ndlp: pointer to a node-list data structure.
1023 * @retry: number of retries to the command IOCB.
1024 *
1025 * This routine issues a Fabric Login (FLOGI) Request ELS command
1026 * for a @vport. The initiator service parameters are put into the payload
1027 * of the FLOGI Request IOCB and the top-level callback function pointer
1028 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1029 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1030 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1031 *
1032 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1033 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1034 * will be stored into the context1 field of the IOCB for the completion
1035 * callback function to the FLOGI ELS command.
1036 *
1037 * Return code
1038 * 0 - successfully issued flogi iocb for @vport
1039 * 1 - failed to issue flogi iocb for @vport
1040 **/
dea31012005-04-17 16:05:31 -05001041static int
James Smart2e0fef82007-06-17 19:56:36 -05001042lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001043 uint8_t retry)
1044{
James Smart2e0fef82007-06-17 19:56:36 -05001045 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001046 struct serv_parm *sp;
1047 IOCB_t *icmd;
1048 struct lpfc_iocbq *elsiocb;
1049 struct lpfc_sli_ring *pring;
1050 uint8_t *pcmd;
1051 uint16_t cmdsize;
1052 uint32_t tmo;
1053 int rc;
1054
1055 pring = &phba->sli.ring[LPFC_ELS_RING];
1056
James Smart92d7f7b2007-06-17 19:56:38 -05001057 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001058 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1059 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001060
James Smart488d1462006-03-07 15:02:37 -05001061 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001062 return 1;
dea31012005-04-17 16:05:31 -05001063
1064 icmd = &elsiocb->iocb;
1065 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1066
1067 /* For FLOGI request, remainder of payload is service parameters */
1068 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001069 pcmd += sizeof(uint32_t);
1070 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001071 sp = (struct serv_parm *) pcmd;
1072
1073 /* Setup CSPs accordingly for Fabric */
1074 sp->cmn.e_d_tov = 0;
1075 sp->cmn.w2.r_a_tov = 0;
1076 sp->cls1.classValid = 0;
1077 sp->cls2.seqDelivery = 1;
1078 sp->cls3.seqDelivery = 1;
1079 if (sp->cmn.fcphLow < FC_PH3)
1080 sp->cmn.fcphLow = FC_PH3;
1081 if (sp->cmn.fcphHigh < FC_PH3)
1082 sp->cmn.fcphHigh = FC_PH3;
1083
James Smartc31098c2011-04-16 11:03:33 -04001084 if (phba->sli_rev == LPFC_SLI_REV4) {
1085 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1086 LPFC_SLI_INTF_IF_TYPE_0) {
1087 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1088 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1089 /* FLOGI needs to be 3 for WQE FCFI */
1090 /* Set the fcfi to the fcfi we registered with */
1091 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1092 }
James Smart5248a742011-07-22 18:37:06 -04001093 } else {
1094 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1095 sp->cmn.request_multiple_Nport = 1;
1096 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1097 icmd->ulpCt_h = 1;
1098 icmd->ulpCt_l = 0;
1099 } else
1100 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001101 }
1102
James Smart76a95d72010-11-20 23:11:48 -05001103 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001104 icmd->un.elsreq64.myID = 0;
1105 icmd->un.elsreq64.fl = 1;
1106 }
1107
dea31012005-04-17 16:05:31 -05001108 tmo = phba->fc_ratov;
1109 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001110 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001111 phba->fc_ratov = tmo;
1112
1113 phba->fc_stat.elsXmitFLOGI++;
1114 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001115
1116 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1117 "Issue FLOGI: opt:x%x",
1118 phba->sli3_options, 0, 0);
1119
James Smart92d7f7b2007-06-17 19:56:38 -05001120 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001121 if (rc == IOCB_ERROR) {
1122 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001123 return 1;
dea31012005-04-17 16:05:31 -05001124 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001125 return 0;
dea31012005-04-17 16:05:31 -05001126}
1127
James Smarte59058c2008-08-24 21:49:00 -04001128/**
James Smart3621a712009-04-06 18:47:14 -04001129 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001130 * @phba: pointer to lpfc hba data structure.
1131 *
1132 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1133 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1134 * list and issues an abort IOCB commond on each outstanding IOCB that
1135 * contains a active Fabric_DID ndlp. Note that this function is to issue
1136 * the abort IOCB command on all the outstanding IOCBs, thus when this
1137 * function returns, it does not guarantee all the IOCBs are actually aborted.
1138 *
1139 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001140 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001141 **/
dea31012005-04-17 16:05:31 -05001142int
James Smart2e0fef82007-06-17 19:56:36 -05001143lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001144{
1145 struct lpfc_sli_ring *pring;
1146 struct lpfc_iocbq *iocb, *next_iocb;
1147 struct lpfc_nodelist *ndlp;
1148 IOCB_t *icmd;
1149
1150 /* Abort outstanding I/O on NPort <nlp_DID> */
1151 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001152 "0201 Abort outstanding I/O on NPort x%x\n",
1153 Fabric_DID);
dea31012005-04-17 16:05:31 -05001154
1155 pring = &phba->sli.ring[LPFC_ELS_RING];
1156
1157 /*
1158 * Check the txcmplq for an iocb that matches the nport the driver is
1159 * searching for.
1160 */
James Smart2e0fef82007-06-17 19:56:36 -05001161 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001162 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1163 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001164 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1165 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001166 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001167 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1168 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001169 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001170 }
1171 }
James Smart2e0fef82007-06-17 19:56:36 -05001172 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001173
1174 return 0;
1175}
1176
James Smarte59058c2008-08-24 21:49:00 -04001177/**
James Smart3621a712009-04-06 18:47:14 -04001178 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001179 * @vport: pointer to a host virtual N_Port data structure.
1180 *
1181 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1182 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1183 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1184 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1185 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1186 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1187 * @vport.
1188 *
1189 * Return code
1190 * 0 - failed to issue initial flogi for @vport
1191 * 1 - successfully issued initial flogi for @vport
1192 **/
dea31012005-04-17 16:05:31 -05001193int
James Smart2e0fef82007-06-17 19:56:36 -05001194lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001195{
James Smart2e0fef82007-06-17 19:56:36 -05001196 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001197 struct lpfc_nodelist *ndlp;
1198
James Smart98c9ea52007-10-27 13:37:33 -04001199 vport->port_state = LPFC_FLOGI;
1200 lpfc_set_disctmo(vport);
1201
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001202 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001203 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001204 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001205 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001206 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1207 if (!ndlp)
1208 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001209 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001210 /* Set the node type */
1211 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001212 /* Put ndlp onto node list */
1213 lpfc_enqueue_node(vport, ndlp);
1214 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1215 /* re-setup ndlp without removing from node list */
1216 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1217 if (!ndlp)
1218 return 0;
dea31012005-04-17 16:05:31 -05001219 }
James Smart87af33f2007-10-27 13:37:43 -04001220
James Smart5ac6b302010-10-22 11:05:36 -04001221 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001222 /* This decrement of reference count to node shall kick off
1223 * the release of the node.
1224 */
James Smart329f9bc2007-04-25 09:53:01 -04001225 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001226 return 0;
1227 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001228 return 1;
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_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001233 * @vport: pointer to a host virtual N_Port data structure.
1234 *
1235 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1236 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1237 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1238 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1239 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1240 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1241 * @vport.
1242 *
1243 * Return code
1244 * 0 - failed to issue initial fdisc for @vport
1245 * 1 - successfully issued initial fdisc for @vport
1246 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001247int
1248lpfc_initial_fdisc(struct lpfc_vport *vport)
1249{
1250 struct lpfc_hba *phba = vport->phba;
1251 struct lpfc_nodelist *ndlp;
1252
1253 /* First look for the Fabric ndlp */
1254 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1255 if (!ndlp) {
1256 /* Cannot find existing Fabric ndlp, so allocate a new one */
1257 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1258 if (!ndlp)
1259 return 0;
1260 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001261 /* Put ndlp onto node list */
1262 lpfc_enqueue_node(vport, ndlp);
1263 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1264 /* re-setup ndlp without removing from node list */
1265 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1266 if (!ndlp)
1267 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001268 }
James Smarte47c9092008-02-08 18:49:26 -05001269
James Smart92d7f7b2007-06-17 19:56:38 -05001270 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001271 /* decrement node reference count to trigger the release of
1272 * the node.
1273 */
James Smart92d7f7b2007-06-17 19:56:38 -05001274 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001275 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001276 }
1277 return 1;
1278}
James Smart87af33f2007-10-27 13:37:43 -04001279
James Smarte59058c2008-08-24 21:49:00 -04001280/**
James Smart3621a712009-04-06 18:47:14 -04001281 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001282 * @vport: pointer to a host virtual N_Port data structure.
1283 *
1284 * This routine checks whether there are more remaining Port Logins
1285 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1286 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1287 * to issue ELS PLOGIs up to the configured discover threads with the
1288 * @vport (@vport->cfg_discovery_threads). The function also decrement
1289 * the @vport's num_disc_node by 1 if it is not already 0.
1290 **/
James Smart87af33f2007-10-27 13:37:43 -04001291void
James Smart2e0fef82007-06-17 19:56:36 -05001292lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001293{
1294 int sentplogi;
1295
James Smart2e0fef82007-06-17 19:56:36 -05001296 if (vport->num_disc_nodes)
1297 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001298
1299 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001300 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1301 "0232 Continue discovery with %d PLOGIs to go "
1302 "Data: x%x x%x x%x\n",
1303 vport->num_disc_nodes, vport->fc_plogi_cnt,
1304 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001305 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001306 if (vport->fc_flag & FC_NLP_MORE)
1307 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1308 sentplogi = lpfc_els_disc_plogi(vport);
1309
dea31012005-04-17 16:05:31 -05001310 return;
1311}
1312
James Smarte59058c2008-08-24 21:49:00 -04001313/**
James Smart3621a712009-04-06 18:47:14 -04001314 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001315 * @phba: pointer to lpfc hba data structure.
1316 * @prsp: pointer to response IOCB payload.
1317 * @ndlp: pointer to a node-list data structure.
1318 *
1319 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1320 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1321 * The following cases are considered N_Port confirmed:
1322 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1323 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1324 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1325 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1326 * 1) if there is a node on vport list other than the @ndlp with the same
1327 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1328 * on that node to release the RPI associated with the node; 2) if there is
1329 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1330 * into, a new node shall be allocated (or activated). In either case, the
1331 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1332 * be released and the new_ndlp shall be put on to the vport node list and
1333 * its pointer returned as the confirmed node.
1334 *
1335 * Note that before the @ndlp got "released", the keepDID from not-matching
1336 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1337 * of the @ndlp. This is because the release of @ndlp is actually to put it
1338 * into an inactive state on the vport node list and the vport node list
1339 * management algorithm does not allow two node with a same DID.
1340 *
1341 * Return code
1342 * pointer to the PLOGI N_Port @ndlp
1343 **/
James Smart488d1462006-03-07 15:02:37 -05001344static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001345lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001346 struct lpfc_nodelist *ndlp)
1347{
James Smart2e0fef82007-06-17 19:56:36 -05001348 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001349 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001350 struct lpfc_rport_data *rdata;
1351 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001352 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001353 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001354 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001355 int put_node;
1356 int put_rport;
James Smart19ca7602010-11-20 23:11:55 -05001357 struct lpfc_node_rrqs rrq;
James Smart488d1462006-03-07 15:02:37 -05001358
James Smart2fb9bd82006-12-02 13:33:57 -05001359 /* Fabric nodes can have the same WWPN so we don't bother searching
1360 * by WWPN. Just return the ndlp that was given to us.
1361 */
1362 if (ndlp->nlp_type & NLP_FABRIC)
1363 return ndlp;
1364
James Smart92d7f7b2007-06-17 19:56:38 -05001365 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001366 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001367
James Smart685f0bf2007-04-25 09:53:08 -04001368 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001369 * we have for that ndlp. If not, we have some work to do.
1370 */
James Smart2e0fef82007-06-17 19:56:36 -05001371 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001372
James Smarte47c9092008-02-08 18:49:26 -05001373 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001374 return ndlp;
James Smart19ca7602010-11-20 23:11:55 -05001375 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
James Smart488d1462006-03-07 15:02:37 -05001376
1377 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001378 rc = memcmp(&ndlp->nlp_portname, name,
1379 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001380 if (!rc)
1381 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001382 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1383 if (!new_ndlp)
1384 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001385 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001386 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001387 rc = memcmp(&ndlp->nlp_portname, name,
1388 sizeof(struct lpfc_name));
1389 if (!rc)
1390 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001391 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1392 NLP_STE_UNUSED_NODE);
1393 if (!new_ndlp)
1394 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001395 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001396 if (phba->sli_rev == LPFC_SLI_REV4)
1397 memcpy(&rrq.xri_bitmap,
1398 &new_ndlp->active_rrqs.xri_bitmap,
1399 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1400 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001401 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001402 if (phba->sli_rev == LPFC_SLI_REV4)
1403 memcpy(&rrq.xri_bitmap,
1404 &new_ndlp->active_rrqs.xri_bitmap,
1405 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1406 }
James Smart488d1462006-03-07 15:02:37 -05001407
James Smart2e0fef82007-06-17 19:56:36 -05001408 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001409 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001410 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001411 if (phba->sli_rev == LPFC_SLI_REV4)
1412 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1413 &ndlp->active_rrqs.xri_bitmap,
1414 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart0ff10d42008-01-11 01:52:36 -05001415
1416 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1417 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1418 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1419
James Smarte47c9092008-02-08 18:49:26 -05001420 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001421 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001422
James Smart2e0fef82007-06-17 19:56:36 -05001423 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001424 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1425 /* The new_ndlp is replacing ndlp totally, so we need
1426 * to put ndlp on UNUSED list and try to free it.
1427 */
James Smart0ff10d42008-01-11 01:52:36 -05001428
1429 /* Fix up the rport accordingly */
1430 rport = ndlp->rport;
1431 if (rport) {
1432 rdata = rport->dd_data;
1433 if (rdata->pnode == ndlp) {
1434 lpfc_nlp_put(ndlp);
1435 ndlp->rport = NULL;
1436 rdata->pnode = lpfc_nlp_get(new_ndlp);
1437 new_ndlp->rport = rport;
1438 }
1439 new_ndlp->nlp_type = ndlp->nlp_type;
1440 }
James Smart58da1ff2008-04-07 10:15:56 -04001441 /* We shall actually free the ndlp with both nlp_DID and
1442 * nlp_portname fields equals 0 to avoid any ndlp on the
1443 * nodelist never to be used.
1444 */
1445 if (ndlp->nlp_DID == 0) {
1446 spin_lock_irq(&phba->ndlp_lock);
1447 NLP_SET_FREE_REQ(ndlp);
1448 spin_unlock_irq(&phba->ndlp_lock);
1449 }
James Smart0ff10d42008-01-11 01:52:36 -05001450
James Smart58da1ff2008-04-07 10:15:56 -04001451 /* Two ndlps cannot have the same did on the nodelist */
1452 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001453 if (phba->sli_rev == LPFC_SLI_REV4)
1454 memcpy(&ndlp->active_rrqs.xri_bitmap,
1455 &rrq.xri_bitmap,
1456 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001457 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001458 }
James Smart92795652006-07-06 15:50:02 -04001459 else {
James Smart2e0fef82007-06-17 19:56:36 -05001460 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001461 /* Two ndlps cannot have the same did */
1462 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001463 if (phba->sli_rev == LPFC_SLI_REV4)
1464 memcpy(&ndlp->active_rrqs.xri_bitmap,
1465 &rrq.xri_bitmap,
1466 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001467 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart38b92ef2010-08-04 16:11:39 -04001468 /* Since we are swapping the ndlp passed in with the new one
1469 * and the did has already been swapped, copy over the
1470 * state and names.
1471 */
1472 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1473 sizeof(struct lpfc_name));
1474 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1475 sizeof(struct lpfc_name));
1476 new_ndlp->nlp_state = ndlp->nlp_state;
1477 /* Fix up the rport accordingly */
1478 rport = ndlp->rport;
1479 if (rport) {
1480 rdata = rport->dd_data;
1481 put_node = rdata->pnode != NULL;
1482 put_rport = ndlp->rport != NULL;
1483 rdata->pnode = NULL;
1484 ndlp->rport = NULL;
1485 if (put_node)
1486 lpfc_nlp_put(ndlp);
1487 if (put_rport)
1488 put_device(&rport->dev);
1489 }
James Smart92795652006-07-06 15:50:02 -04001490 }
James Smart488d1462006-03-07 15:02:37 -05001491 return new_ndlp;
1492}
1493
James Smarte59058c2008-08-24 21:49:00 -04001494/**
James Smart3621a712009-04-06 18:47:14 -04001495 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001496 * @vport: pointer to a host virtual N_Port data structure.
1497 *
1498 * This routine checks whether more Registration State Change
1499 * Notifications (RSCNs) came in while the discovery state machine was in
1500 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1501 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1502 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1503 * handling the RSCNs.
1504 **/
James Smart87af33f2007-10-27 13:37:43 -04001505void
1506lpfc_end_rscn(struct lpfc_vport *vport)
1507{
1508 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1509
1510 if (vport->fc_flag & FC_RSCN_MODE) {
1511 /*
1512 * Check to see if more RSCNs came in while we were
1513 * processing this one.
1514 */
1515 if (vport->fc_rscn_id_cnt ||
1516 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1517 lpfc_els_handle_rscn(vport);
1518 else {
1519 spin_lock_irq(shost->host_lock);
1520 vport->fc_flag &= ~FC_RSCN_MODE;
1521 spin_unlock_irq(shost->host_lock);
1522 }
1523 }
1524}
1525
James Smarte59058c2008-08-24 21:49:00 -04001526/**
James Smart19ca7602010-11-20 23:11:55 -05001527 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1528 * @phba: pointer to lpfc hba data structure.
1529 * @cmdiocb: pointer to lpfc command iocb data structure.
1530 * @rspiocb: pointer to lpfc response iocb data structure.
1531 *
1532 * This routine will call the clear rrq function to free the rrq and
1533 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1534 * exist then the clear_rrq is still called because the rrq needs to
1535 * be freed.
1536 **/
1537
1538static void
1539lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1540 struct lpfc_iocbq *rspiocb)
1541{
1542 struct lpfc_vport *vport = cmdiocb->vport;
1543 IOCB_t *irsp;
1544 struct lpfc_nodelist *ndlp;
1545 struct lpfc_node_rrq *rrq;
1546
1547 /* we pass cmdiocb to state machine which needs rspiocb as well */
1548 rrq = cmdiocb->context_un.rrq;
1549 cmdiocb->context_un.rsp_iocb = rspiocb;
1550
1551 irsp = &rspiocb->iocb;
1552 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1553 "RRQ cmpl: status:x%x/x%x did:x%x",
1554 irsp->ulpStatus, irsp->un.ulpWord[4],
1555 irsp->un.elsreq64.remoteID);
1556
1557 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1558 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1559 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1560 "2882 RRQ completes to NPort x%x "
1561 "with no ndlp. Data: x%x x%x x%x\n",
1562 irsp->un.elsreq64.remoteID,
1563 irsp->ulpStatus, irsp->un.ulpWord[4],
1564 irsp->ulpIoTag);
1565 goto out;
1566 }
1567
1568 /* rrq completes to NPort <nlp_DID> */
1569 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1570 "2880 RRQ completes to NPort x%x "
1571 "Data: x%x x%x x%x x%x x%x\n",
1572 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1573 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1574
1575 if (irsp->ulpStatus) {
1576 /* Check for retry */
1577 /* RRQ failed Don't print the vport to vport rjts */
1578 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1579 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1580 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1581 (phba)->pport->cfg_log_verbose & LOG_ELS)
1582 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1583 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1584 ndlp->nlp_DID, irsp->ulpStatus,
1585 irsp->un.ulpWord[4]);
1586 }
1587out:
1588 if (rrq)
1589 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1590 lpfc_els_free_iocb(phba, cmdiocb);
1591 return;
1592}
1593/**
James Smart3621a712009-04-06 18:47:14 -04001594 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001595 * @phba: pointer to lpfc hba data structure.
1596 * @cmdiocb: pointer to lpfc command iocb data structure.
1597 * @rspiocb: pointer to lpfc response iocb data structure.
1598 *
1599 * This routine is the completion callback function for issuing the Port
1600 * Login (PLOGI) command. For PLOGI completion, there must be an active
1601 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001602 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001603 * ignored and command IOCB released. The PLOGI response IOCB status is
1604 * checked for error conditons. If there is error status reported, PLOGI
1605 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1606 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1607 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1608 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1609 * there are additional N_Port nodes with the vport that need to perform
1610 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1611 * PLOGIs.
1612 **/
dea31012005-04-17 16:05:31 -05001613static void
James Smart2e0fef82007-06-17 19:56:36 -05001614lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1615 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001616{
James Smart2e0fef82007-06-17 19:56:36 -05001617 struct lpfc_vport *vport = cmdiocb->vport;
1618 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001619 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001620 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001621 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001622 int disc, rc, did, type;
1623
dea31012005-04-17 16:05:31 -05001624 /* we pass cmdiocb to state machine which needs rspiocb as well */
1625 cmdiocb->context_un.rsp_iocb = rspiocb;
1626
1627 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001628 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1629 "PLOGI cmpl: status:x%x/x%x did:x%x",
1630 irsp->ulpStatus, irsp->un.ulpWord[4],
1631 irsp->un.elsreq64.remoteID);
1632
James Smart2e0fef82007-06-17 19:56:36 -05001633 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001634 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001635 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1636 "0136 PLOGI completes to NPort x%x "
1637 "with no ndlp. Data: x%x x%x x%x\n",
1638 irsp->un.elsreq64.remoteID,
1639 irsp->ulpStatus, irsp->un.ulpWord[4],
1640 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001641 goto out;
James Smarted957682007-06-17 19:56:37 -05001642 }
dea31012005-04-17 16:05:31 -05001643
1644 /* Since ndlp can be freed in the disc state machine, note if this node
1645 * is being used during discovery.
1646 */
James Smart2e0fef82007-06-17 19:56:36 -05001647 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001648 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001649 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001650 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001651 rc = 0;
1652
1653 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001654 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1655 "0102 PLOGI completes to NPort x%x "
1656 "Data: x%x x%x x%x x%x x%x\n",
1657 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1658 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001659 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001660 if (lpfc_els_chk_latt(vport)) {
1661 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001662 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001663 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001664 goto out;
1665 }
1666
1667 /* ndlp could be freed in DSM, save these values now */
1668 type = ndlp->nlp_type;
1669 did = ndlp->nlp_DID;
1670
1671 if (irsp->ulpStatus) {
1672 /* Check for retry */
1673 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1674 /* ELS command is being retried */
1675 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001676 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001677 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001678 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001679 }
1680 goto out;
1681 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001682 /* PLOGI failed Don't print the vport to vport rjts */
1683 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1684 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1685 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1686 (phba)->pport->cfg_log_verbose & LOG_ELS)
1687 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001688 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1689 ndlp->nlp_DID, irsp->ulpStatus,
1690 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001691 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001692 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001693 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001694 else
James Smart2e0fef82007-06-17 19:56:36 -05001695 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001696 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001697 } else {
1698 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001699 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001700 cmdiocb->context2)->list.next,
1701 struct lpfc_dmabuf, list);
1702 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001703 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001704 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001705 }
1706
James Smart2e0fef82007-06-17 19:56:36 -05001707 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001708 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001709 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001710
James Smart2e0fef82007-06-17 19:56:36 -05001711 if (vport->num_disc_nodes == 0) {
1712 spin_lock_irq(shost->host_lock);
1713 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1714 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001715
James Smart2e0fef82007-06-17 19:56:36 -05001716 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001717 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001718 }
1719 }
1720
1721out:
1722 lpfc_els_free_iocb(phba, cmdiocb);
1723 return;
1724}
1725
James Smarte59058c2008-08-24 21:49:00 -04001726/**
James Smart3621a712009-04-06 18:47:14 -04001727 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001728 * @vport: pointer to a host virtual N_Port data structure.
1729 * @did: destination port identifier.
1730 * @retry: number of retries to the command IOCB.
1731 *
1732 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1733 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1734 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1735 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1736 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1737 *
1738 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1739 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1740 * will be stored into the context1 field of the IOCB for the completion
1741 * callback function to the PLOGI ELS command.
1742 *
1743 * Return code
1744 * 0 - Successfully issued a plogi for @vport
1745 * 1 - failed to issue a plogi for @vport
1746 **/
dea31012005-04-17 16:05:31 -05001747int
James Smart2e0fef82007-06-17 19:56:36 -05001748lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001749{
James Smart2e0fef82007-06-17 19:56:36 -05001750 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001751 struct serv_parm *sp;
1752 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001753 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001754 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001755 struct lpfc_sli *psli;
1756 uint8_t *pcmd;
1757 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001758 int ret;
dea31012005-04-17 16:05:31 -05001759
1760 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001761
James Smart98c9ea52007-10-27 13:37:33 -04001762 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001763 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1764 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001765
James Smarte47c9092008-02-08 18:49:26 -05001766 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001767 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001768 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001769 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001770 if (!elsiocb)
1771 return 1;
dea31012005-04-17 16:05:31 -05001772
1773 icmd = &elsiocb->iocb;
1774 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1775
1776 /* For PLOGI request, remainder of payload is service parameters */
1777 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001778 pcmd += sizeof(uint32_t);
1779 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001780 sp = (struct serv_parm *) pcmd;
1781
James Smart5ac6b302010-10-22 11:05:36 -04001782 /*
1783 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1784 * to device on remote loops work.
1785 */
1786 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1787 sp->cmn.altBbCredit = 1;
1788
dea31012005-04-17 16:05:31 -05001789 if (sp->cmn.fcphLow < FC_PH_4_3)
1790 sp->cmn.fcphLow = FC_PH_4_3;
1791
1792 if (sp->cmn.fcphHigh < FC_PH3)
1793 sp->cmn.fcphHigh = FC_PH3;
1794
James Smart858c9f62007-06-17 19:56:39 -05001795 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1796 "Issue PLOGI: did:x%x",
1797 did, 0, 0);
1798
dea31012005-04-17 16:05:31 -05001799 phba->fc_stat.elsXmitPLOGI++;
1800 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001801 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001802
1803 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001804 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001805 return 1;
dea31012005-04-17 16:05:31 -05001806 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001807 return 0;
dea31012005-04-17 16:05:31 -05001808}
1809
James Smarte59058c2008-08-24 21:49:00 -04001810/**
James Smart3621a712009-04-06 18:47:14 -04001811 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001812 * @phba: pointer to lpfc hba data structure.
1813 * @cmdiocb: pointer to lpfc command iocb data structure.
1814 * @rspiocb: pointer to lpfc response iocb data structure.
1815 *
1816 * This routine is the completion callback function for a Process Login
1817 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1818 * status. If there is error status reported, PRLI retry shall be attempted
1819 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1820 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1821 * ndlp to mark the PRLI completion.
1822 **/
dea31012005-04-17 16:05:31 -05001823static void
James Smart2e0fef82007-06-17 19:56:36 -05001824lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1825 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001826{
James Smart2e0fef82007-06-17 19:56:36 -05001827 struct lpfc_vport *vport = cmdiocb->vport;
1828 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001829 IOCB_t *irsp;
1830 struct lpfc_sli *psli;
1831 struct lpfc_nodelist *ndlp;
1832
1833 psli = &phba->sli;
1834 /* we pass cmdiocb to state machine which needs rspiocb as well */
1835 cmdiocb->context_un.rsp_iocb = rspiocb;
1836
1837 irsp = &(rspiocb->iocb);
1838 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001839 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001840 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001841 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001842
James Smart858c9f62007-06-17 19:56:39 -05001843 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1844 "PRLI cmpl: status:x%x/x%x did:x%x",
1845 irsp->ulpStatus, irsp->un.ulpWord[4],
1846 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001847 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001848 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1849 "0103 PRLI completes to NPort x%x "
1850 "Data: x%x x%x x%x x%x\n",
1851 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1852 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001853
James Smart2e0fef82007-06-17 19:56:36 -05001854 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001855 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001856 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001857 goto out;
1858
1859 if (irsp->ulpStatus) {
1860 /* Check for retry */
1861 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1862 /* ELS command is being retried */
1863 goto out;
1864 }
1865 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001866 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1867 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1868 ndlp->nlp_DID, irsp->ulpStatus,
1869 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001870 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001871 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001872 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001873 else
James Smart2e0fef82007-06-17 19:56:36 -05001874 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001875 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001876 } else
dea31012005-04-17 16:05:31 -05001877 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001878 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001879 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001880out:
1881 lpfc_els_free_iocb(phba, cmdiocb);
1882 return;
1883}
1884
James Smarte59058c2008-08-24 21:49:00 -04001885/**
James Smart3621a712009-04-06 18:47:14 -04001886 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001887 * @vport: pointer to a host virtual N_Port data structure.
1888 * @ndlp: pointer to a node-list data structure.
1889 * @retry: number of retries to the command IOCB.
1890 *
1891 * This routine issues a Process Login (PRLI) ELS command for the
1892 * @vport. The PRLI service parameters are set up in the payload of the
1893 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1894 * is put to the IOCB completion callback func field before invoking the
1895 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1896 *
1897 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1898 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1899 * will be stored into the context1 field of the IOCB for the completion
1900 * callback function to the PRLI ELS command.
1901 *
1902 * Return code
1903 * 0 - successfully issued prli iocb command for @vport
1904 * 1 - failed to issue prli iocb command for @vport
1905 **/
dea31012005-04-17 16:05:31 -05001906int
James Smart2e0fef82007-06-17 19:56:36 -05001907lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001908 uint8_t retry)
1909{
James Smart2e0fef82007-06-17 19:56:36 -05001910 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1911 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001912 PRLI *npr;
1913 IOCB_t *icmd;
1914 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001915 uint8_t *pcmd;
1916 uint16_t cmdsize;
1917
James Smart92d7f7b2007-06-17 19:56:38 -05001918 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001919 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1920 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001921 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001922 return 1;
dea31012005-04-17 16:05:31 -05001923
1924 icmd = &elsiocb->iocb;
1925 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1926
1927 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001928 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001929 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001930 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001931
1932 /* For PRLI, remainder of payload is PRLI parameter page */
1933 npr = (PRLI *) pcmd;
1934 /*
1935 * If our firmware version is 3.20 or later,
1936 * set the following bits for FC-TAPE support.
1937 */
1938 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1939 npr->ConfmComplAllowed = 1;
1940 npr->Retry = 1;
1941 npr->TaskRetryIdReq = 1;
1942 }
1943 npr->estabImagePair = 1;
1944 npr->readXferRdyDis = 1;
1945
1946 /* For FCP support */
1947 npr->prliType = PRLI_FCP_TYPE;
1948 npr->initiatorFunc = 1;
1949
James Smart858c9f62007-06-17 19:56:39 -05001950 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1951 "Issue PRLI: did:x%x",
1952 ndlp->nlp_DID, 0, 0);
1953
dea31012005-04-17 16:05:31 -05001954 phba->fc_stat.elsXmitPRLI++;
1955 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001956 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001957 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001958 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001959 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1960 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001961 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001962 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001963 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001964 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001965 return 1;
dea31012005-04-17 16:05:31 -05001966 }
James Smart2e0fef82007-06-17 19:56:36 -05001967 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001968 return 0;
dea31012005-04-17 16:05:31 -05001969}
1970
James Smarte59058c2008-08-24 21:49:00 -04001971/**
James Smart3621a712009-04-06 18:47:14 -04001972 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001973 * @vport: pointer to a host virtual N_Port data structure.
1974 *
1975 * This routine performs Registration State Change Notification (RSCN)
1976 * discovery for a @vport. If the @vport's node port recovery count is not
1977 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1978 * the nodes that need recovery. If none of the PLOGI were needed through
1979 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1980 * invoked to check and handle possible more RSCN came in during the period
1981 * of processing the current ones.
1982 **/
1983static void
1984lpfc_rscn_disc(struct lpfc_vport *vport)
1985{
1986 lpfc_can_disctmo(vport);
1987
1988 /* RSCN discovery */
1989 /* go thru NPR nodes and issue ELS PLOGIs */
1990 if (vport->fc_npr_cnt)
1991 if (lpfc_els_disc_plogi(vport))
1992 return;
1993
1994 lpfc_end_rscn(vport);
1995}
1996
1997/**
James Smart3621a712009-04-06 18:47:14 -04001998 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001999 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2000 *
2001 * This function is called when the final ADISC is completed during discovery.
2002 * This function handles clearing link attention or issuing reg_vpi depending
2003 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2004 * discovery.
2005 * This function is called with no locks held.
2006 **/
2007static void
2008lpfc_adisc_done(struct lpfc_vport *vport)
2009{
2010 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2011 struct lpfc_hba *phba = vport->phba;
2012
2013 /*
2014 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2015 * and continue discovery.
2016 */
2017 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002018 !(vport->fc_flag & FC_RSCN_MODE) &&
2019 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04002020 lpfc_issue_reg_vpi(phba, vport);
2021 return;
2022 }
2023 /*
2024 * For SLI2, we need to set port_state to READY
2025 * and continue discovery.
2026 */
2027 if (vport->port_state < LPFC_VPORT_READY) {
2028 /* If we get here, there is nothing to ADISC */
2029 if (vport->port_type == LPFC_PHYSICAL_PORT)
2030 lpfc_issue_clear_la(phba, vport);
2031 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2032 vport->num_disc_nodes = 0;
2033 /* go thru NPR list, issue ELS PLOGIs */
2034 if (vport->fc_npr_cnt)
2035 lpfc_els_disc_plogi(vport);
2036 if (!vport->num_disc_nodes) {
2037 spin_lock_irq(shost->host_lock);
2038 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2039 spin_unlock_irq(shost->host_lock);
2040 lpfc_can_disctmo(vport);
2041 lpfc_end_rscn(vport);
2042 }
2043 }
2044 vport->port_state = LPFC_VPORT_READY;
2045 } else
2046 lpfc_rscn_disc(vport);
2047}
2048
2049/**
James Smart3621a712009-04-06 18:47:14 -04002050 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002051 * @vport: pointer to a host virtual N_Port data structure.
2052 *
2053 * This routine determines whether there are more ndlps on a @vport
2054 * node list need to have Address Discover (ADISC) issued. If so, it will
2055 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2056 * remaining nodes which need to have ADISC sent.
2057 **/
James Smart0ff10d42008-01-11 01:52:36 -05002058void
James Smart2e0fef82007-06-17 19:56:36 -05002059lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002060{
2061 int sentadisc;
2062
James Smart2e0fef82007-06-17 19:56:36 -05002063 if (vport->num_disc_nodes)
2064 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002065 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002066 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2067 "0210 Continue discovery with %d ADISCs to go "
2068 "Data: x%x x%x x%x\n",
2069 vport->num_disc_nodes, vport->fc_adisc_cnt,
2070 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002071 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002072 if (vport->fc_flag & FC_NLP_MORE) {
2073 lpfc_set_disctmo(vport);
2074 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2075 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002076 }
James Smart90160e02008-08-24 21:49:45 -04002077 if (!vport->num_disc_nodes)
2078 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002079 return;
2080}
2081
James Smarte59058c2008-08-24 21:49:00 -04002082/**
James Smart3621a712009-04-06 18:47:14 -04002083 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002084 * @phba: pointer to lpfc hba data structure.
2085 * @cmdiocb: pointer to lpfc command iocb data structure.
2086 * @rspiocb: pointer to lpfc response iocb data structure.
2087 *
2088 * This routine is the completion function for issuing the Address Discover
2089 * (ADISC) command. It first checks to see whether link went down during
2090 * the discovery process. If so, the node will be marked as node port
2091 * recovery for issuing discover IOCB by the link attention handler and
2092 * exit. Otherwise, the response status is checked. If error was reported
2093 * in the response status, the ADISC command shall be retried by invoking
2094 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2095 * the response status, the state machine is invoked to set transition
2096 * with respect to NLP_EVT_CMPL_ADISC event.
2097 **/
dea31012005-04-17 16:05:31 -05002098static void
James Smart2e0fef82007-06-17 19:56:36 -05002099lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2100 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002101{
James Smart2e0fef82007-06-17 19:56:36 -05002102 struct lpfc_vport *vport = cmdiocb->vport;
2103 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002104 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002105 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002106 int disc;
dea31012005-04-17 16:05:31 -05002107
2108 /* we pass cmdiocb to state machine which needs rspiocb as well */
2109 cmdiocb->context_un.rsp_iocb = rspiocb;
2110
2111 irsp = &(rspiocb->iocb);
2112 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002113
James Smart858c9f62007-06-17 19:56:39 -05002114 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2115 "ADISC cmpl: status:x%x/x%x did:x%x",
2116 irsp->ulpStatus, irsp->un.ulpWord[4],
2117 ndlp->nlp_DID);
2118
dea31012005-04-17 16:05:31 -05002119 /* Since ndlp can be freed in the disc state machine, note if this node
2120 * is being used during discovery.
2121 */
James Smart2e0fef82007-06-17 19:56:36 -05002122 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002123 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002124 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002125 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002126 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002127 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2128 "0104 ADISC completes to NPort x%x "
2129 "Data: x%x x%x x%x x%x x%x\n",
2130 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2131 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002132 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002133 if (lpfc_els_chk_latt(vport)) {
2134 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002135 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002136 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002137 goto out;
2138 }
2139
2140 if (irsp->ulpStatus) {
2141 /* Check for retry */
2142 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2143 /* ELS command is being retried */
2144 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002145 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002146 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002147 spin_unlock_irq(shost->host_lock);
2148 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002149 }
2150 goto out;
2151 }
2152 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002153 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2154 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2155 ndlp->nlp_DID, irsp->ulpStatus,
2156 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002157 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002158 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002159 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002160 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002161 } else
dea31012005-04-17 16:05:31 -05002162 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002163 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002164 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002165
James Smart90160e02008-08-24 21:49:45 -04002166 /* Check to see if there are more ADISCs to be sent */
2167 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002168 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002169out:
2170 lpfc_els_free_iocb(phba, cmdiocb);
2171 return;
2172}
2173
James Smarte59058c2008-08-24 21:49:00 -04002174/**
James Smart3621a712009-04-06 18:47:14 -04002175 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002176 * @vport: pointer to a virtual N_Port data structure.
2177 * @ndlp: pointer to a node-list data structure.
2178 * @retry: number of retries to the command IOCB.
2179 *
2180 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2181 * @vport. It prepares the payload of the ADISC ELS command, updates the
2182 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2183 * to issue the ADISC ELS command.
2184 *
2185 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2186 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2187 * will be stored into the context1 field of the IOCB for the completion
2188 * callback function to the ADISC ELS command.
2189 *
2190 * Return code
2191 * 0 - successfully issued adisc
2192 * 1 - failed to issue adisc
2193 **/
dea31012005-04-17 16:05:31 -05002194int
James Smart2e0fef82007-06-17 19:56:36 -05002195lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002196 uint8_t retry)
2197{
James Smart2e0fef82007-06-17 19:56:36 -05002198 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2199 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002200 ADISC *ap;
2201 IOCB_t *icmd;
2202 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002203 uint8_t *pcmd;
2204 uint16_t cmdsize;
2205
James Smart92d7f7b2007-06-17 19:56:38 -05002206 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002207 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2208 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002209 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002210 return 1;
dea31012005-04-17 16:05:31 -05002211
2212 icmd = &elsiocb->iocb;
2213 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2214
2215 /* For ADISC request, remainder of payload is service parameters */
2216 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002217 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002218
2219 /* Fill in ADISC payload */
2220 ap = (ADISC *) pcmd;
2221 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002222 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2223 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002224 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002225
James Smart858c9f62007-06-17 19:56:39 -05002226 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2227 "Issue ADISC: did:x%x",
2228 ndlp->nlp_DID, 0, 0);
2229
dea31012005-04-17 16:05:31 -05002230 phba->fc_stat.elsXmitADISC++;
2231 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002232 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002233 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002234 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002235 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2236 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002237 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002238 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002239 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002240 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002241 return 1;
dea31012005-04-17 16:05:31 -05002242 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002243 return 0;
dea31012005-04-17 16:05:31 -05002244}
2245
James Smarte59058c2008-08-24 21:49:00 -04002246/**
James Smart3621a712009-04-06 18:47:14 -04002247 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002248 * @phba: pointer to lpfc hba data structure.
2249 * @cmdiocb: pointer to lpfc command iocb data structure.
2250 * @rspiocb: pointer to lpfc response iocb data structure.
2251 *
2252 * This routine is the completion function for issuing the ELS Logout (LOGO)
2253 * command. If no error status was reported from the LOGO response, the
2254 * state machine of the associated ndlp shall be invoked for transition with
2255 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2256 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2257 **/
dea31012005-04-17 16:05:31 -05002258static void
James Smart2e0fef82007-06-17 19:56:36 -05002259lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2260 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002261{
James Smart2e0fef82007-06-17 19:56:36 -05002262 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2263 struct lpfc_vport *vport = ndlp->vport;
2264 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002265 IOCB_t *irsp;
2266 struct lpfc_sli *psli;
James Smart92494142011-02-16 12:39:44 -05002267 struct lpfcMboxq *mbox;
dea31012005-04-17 16:05:31 -05002268
2269 psli = &phba->sli;
2270 /* we pass cmdiocb to state machine which needs rspiocb as well */
2271 cmdiocb->context_un.rsp_iocb = rspiocb;
2272
2273 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002274 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002275 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002276 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002277
James Smart858c9f62007-06-17 19:56:39 -05002278 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2279 "LOGO cmpl: status:x%x/x%x did:x%x",
2280 irsp->ulpStatus, irsp->un.ulpWord[4],
2281 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002282 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002283 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2284 "0105 LOGO completes to NPort x%x "
2285 "Data: x%x x%x x%x x%x\n",
2286 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2287 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002288 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002289 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002290 goto out;
2291
James Smart92d7f7b2007-06-17 19:56:38 -05002292 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2293 /* NLP_EVT_DEVICE_RM should unregister the RPI
2294 * which should abort all outstanding IOs.
2295 */
2296 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2297 NLP_EVT_DEVICE_RM);
2298 goto out;
2299 }
2300
dea31012005-04-17 16:05:31 -05002301 if (irsp->ulpStatus) {
2302 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002303 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002304 /* ELS command is being retried */
2305 goto out;
dea31012005-04-17 16:05:31 -05002306 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002307 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2308 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2309 ndlp->nlp_DID, irsp->ulpStatus,
2310 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002311 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002312 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002313 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002314 else
James Smart2e0fef82007-06-17 19:56:36 -05002315 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002316 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002317 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002318 /* Good status, call state machine.
2319 * This will unregister the rpi if needed.
2320 */
James Smart2e0fef82007-06-17 19:56:36 -05002321 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002322 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002323out:
2324 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002325 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2326 if ((vport->fc_flag & FC_PT2PT) &&
2327 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2328 phba->pport->fc_myDID = 0;
2329 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2330 if (mbox) {
2331 lpfc_config_link(phba, mbox);
2332 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2333 mbox->vport = vport;
2334 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2335 MBX_NOT_FINISHED) {
2336 mempool_free(mbox, phba->mbox_mem_pool);
2337 }
2338 }
2339 }
dea31012005-04-17 16:05:31 -05002340 return;
2341}
2342
James Smarte59058c2008-08-24 21:49:00 -04002343/**
James Smart3621a712009-04-06 18:47:14 -04002344 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002345 * @vport: pointer to a virtual N_Port data structure.
2346 * @ndlp: pointer to a node-list data structure.
2347 * @retry: number of retries to the command IOCB.
2348 *
2349 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2350 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2351 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2352 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2353 *
2354 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2355 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2356 * will be stored into the context1 field of the IOCB for the completion
2357 * callback function to the LOGO ELS command.
2358 *
2359 * Return code
2360 * 0 - successfully issued logo
2361 * 1 - failed to issue logo
2362 **/
dea31012005-04-17 16:05:31 -05002363int
James Smart2e0fef82007-06-17 19:56:36 -05002364lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002365 uint8_t retry)
2366{
James Smart2e0fef82007-06-17 19:56:36 -05002367 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2368 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002369 IOCB_t *icmd;
2370 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002371 uint8_t *pcmd;
2372 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002373 int rc;
dea31012005-04-17 16:05:31 -05002374
James Smart98c9ea52007-10-27 13:37:33 -04002375 spin_lock_irq(shost->host_lock);
2376 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2377 spin_unlock_irq(shost->host_lock);
2378 return 0;
2379 }
2380 spin_unlock_irq(shost->host_lock);
2381
James Smart92d7f7b2007-06-17 19:56:38 -05002382 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002383 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2384 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002385 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002386 return 1;
dea31012005-04-17 16:05:31 -05002387
2388 icmd = &elsiocb->iocb;
2389 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2390 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002391 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002392
2393 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002394 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002395 pcmd += sizeof(uint32_t);
2396 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
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 "Issue LOGO: did:x%x",
2400 ndlp->nlp_DID, 0, 0);
2401
dea31012005-04-17 16:05:31 -05002402 phba->fc_stat.elsXmitLOGO++;
2403 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002404 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002405 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002406 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002407 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002408
2409 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002410 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002411 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002412 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002413 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002414 return 1;
dea31012005-04-17 16:05:31 -05002415 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002416 return 0;
dea31012005-04-17 16:05:31 -05002417}
2418
James Smarte59058c2008-08-24 21:49:00 -04002419/**
James Smart3621a712009-04-06 18:47:14 -04002420 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002421 * @phba: pointer to lpfc hba data structure.
2422 * @cmdiocb: pointer to lpfc command iocb data structure.
2423 * @rspiocb: pointer to lpfc response iocb data structure.
2424 *
2425 * This routine is a generic completion callback function for ELS commands.
2426 * Specifically, it is the callback function which does not need to perform
2427 * any command specific operations. It is currently used by the ELS command
2428 * issuing routines for the ELS State Change Request (SCR),
2429 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2430 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2431 * certain debug loggings, this callback function simply invokes the
2432 * lpfc_els_chk_latt() routine to check whether link went down during the
2433 * discovery process.
2434 **/
dea31012005-04-17 16:05:31 -05002435static void
James Smart2e0fef82007-06-17 19:56:36 -05002436lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2437 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002438{
James Smart2e0fef82007-06-17 19:56:36 -05002439 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002440 IOCB_t *irsp;
2441
2442 irsp = &rspiocb->iocb;
2443
James Smart858c9f62007-06-17 19:56:39 -05002444 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2445 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2446 irsp->ulpStatus, irsp->un.ulpWord[4],
2447 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002448 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002449 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2450 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2451 irsp->ulpIoTag, irsp->ulpStatus,
2452 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002453 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002454 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002455 lpfc_els_free_iocb(phba, cmdiocb);
2456 return;
2457}
2458
James Smarte59058c2008-08-24 21:49:00 -04002459/**
James Smart3621a712009-04-06 18:47:14 -04002460 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002461 * @vport: pointer to a host virtual N_Port data structure.
2462 * @nportid: N_Port identifier to the remote node.
2463 * @retry: number of retries to the command IOCB.
2464 *
2465 * This routine issues a State Change Request (SCR) to a fabric node
2466 * on a @vport. The remote node @nportid is passed into the function. It
2467 * first search the @vport node list to find the matching ndlp. If no such
2468 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2469 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2470 * routine is invoked to send the SCR IOCB.
2471 *
2472 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2473 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2474 * will be stored into the context1 field of the IOCB for the completion
2475 * callback function to the SCR ELS command.
2476 *
2477 * Return code
2478 * 0 - Successfully issued scr command
2479 * 1 - Failed to issue scr command
2480 **/
dea31012005-04-17 16:05:31 -05002481int
James Smart2e0fef82007-06-17 19:56:36 -05002482lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002483{
James Smart2e0fef82007-06-17 19:56:36 -05002484 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002485 IOCB_t *icmd;
2486 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002487 struct lpfc_sli *psli;
2488 uint8_t *pcmd;
2489 uint16_t cmdsize;
2490 struct lpfc_nodelist *ndlp;
2491
2492 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002493 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002494
James Smarte47c9092008-02-08 18:49:26 -05002495 ndlp = lpfc_findnode_did(vport, nportid);
2496 if (!ndlp) {
2497 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2498 if (!ndlp)
2499 return 1;
2500 lpfc_nlp_init(vport, ndlp, nportid);
2501 lpfc_enqueue_node(vport, ndlp);
2502 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2503 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2504 if (!ndlp)
2505 return 1;
2506 }
dea31012005-04-17 16:05:31 -05002507
James Smart2e0fef82007-06-17 19:56:36 -05002508 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2509 ndlp->nlp_DID, ELS_CMD_SCR);
2510
James Smart488d1462006-03-07 15:02:37 -05002511 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002512 /* This will trigger the release of the node just
2513 * allocated
2514 */
James Smart329f9bc2007-04-25 09:53:01 -04002515 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002516 return 1;
dea31012005-04-17 16:05:31 -05002517 }
2518
2519 icmd = &elsiocb->iocb;
2520 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2521
2522 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002523 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002524
2525 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002526 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002527 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2528
James Smart858c9f62007-06-17 19:56:39 -05002529 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2530 "Issue SCR: did:x%x",
2531 ndlp->nlp_DID, 0, 0);
2532
dea31012005-04-17 16:05:31 -05002533 phba->fc_stat.elsXmitSCR++;
2534 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002535 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2536 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002537 /* The additional lpfc_nlp_put will cause the following
2538 * lpfc_els_free_iocb routine to trigger the rlease of
2539 * the node.
2540 */
James Smart329f9bc2007-04-25 09:53:01 -04002541 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002542 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002543 return 1;
dea31012005-04-17 16:05:31 -05002544 }
James Smartfa4066b2008-01-11 01:53:27 -05002545 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2546 * trigger the release of node.
2547 */
James Smart329f9bc2007-04-25 09:53:01 -04002548 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002549 return 0;
dea31012005-04-17 16:05:31 -05002550}
2551
James Smarte59058c2008-08-24 21:49:00 -04002552/**
James Smart3621a712009-04-06 18:47:14 -04002553 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002554 * @vport: pointer to a host virtual N_Port data structure.
2555 * @nportid: N_Port identifier to the remote node.
2556 * @retry: number of retries to the command IOCB.
2557 *
2558 * This routine issues a Fibre Channel Address Resolution Response
2559 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2560 * is passed into the function. It first search the @vport node list to find
2561 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2562 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2563 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2564 *
2565 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2566 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2567 * will be stored into the context1 field of the IOCB for the completion
2568 * callback function to the PARPR ELS command.
2569 *
2570 * Return code
2571 * 0 - Successfully issued farpr command
2572 * 1 - Failed to issue farpr command
2573 **/
dea31012005-04-17 16:05:31 -05002574static int
James Smart2e0fef82007-06-17 19:56:36 -05002575lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002576{
James Smart2e0fef82007-06-17 19:56:36 -05002577 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002578 IOCB_t *icmd;
2579 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002580 struct lpfc_sli *psli;
2581 FARP *fp;
2582 uint8_t *pcmd;
2583 uint32_t *lp;
2584 uint16_t cmdsize;
2585 struct lpfc_nodelist *ondlp;
2586 struct lpfc_nodelist *ndlp;
2587
2588 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002589 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002590
James Smarte47c9092008-02-08 18:49:26 -05002591 ndlp = lpfc_findnode_did(vport, nportid);
2592 if (!ndlp) {
2593 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2594 if (!ndlp)
2595 return 1;
2596 lpfc_nlp_init(vport, ndlp, nportid);
2597 lpfc_enqueue_node(vport, ndlp);
2598 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2599 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2600 if (!ndlp)
2601 return 1;
2602 }
James Smart2e0fef82007-06-17 19:56:36 -05002603
2604 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2605 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002606 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002607 /* This will trigger the release of the node just
2608 * allocated
2609 */
James Smart329f9bc2007-04-25 09:53:01 -04002610 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002611 return 1;
dea31012005-04-17 16:05:31 -05002612 }
2613
2614 icmd = &elsiocb->iocb;
2615 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2616
2617 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002618 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002619
2620 /* Fill in FARPR payload */
2621 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002622 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002623 lp = (uint32_t *) pcmd;
2624 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002625 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002626 fp->Rflags = 0;
2627 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2628
James Smart92d7f7b2007-06-17 19:56:38 -05002629 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2630 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002631 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002632 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002633 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002634 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002635 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002636 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002637 }
2638
James Smart858c9f62007-06-17 19:56:39 -05002639 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2640 "Issue FARPR: did:x%x",
2641 ndlp->nlp_DID, 0, 0);
2642
dea31012005-04-17 16:05:31 -05002643 phba->fc_stat.elsXmitFARPR++;
2644 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002645 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2646 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002647 /* The additional lpfc_nlp_put will cause the following
2648 * lpfc_els_free_iocb routine to trigger the release of
2649 * the node.
2650 */
James Smart329f9bc2007-04-25 09:53:01 -04002651 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002652 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002653 return 1;
dea31012005-04-17 16:05:31 -05002654 }
James Smartfa4066b2008-01-11 01:53:27 -05002655 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2656 * trigger the release of the node.
2657 */
James Smart329f9bc2007-04-25 09:53:01 -04002658 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002659 return 0;
dea31012005-04-17 16:05:31 -05002660}
2661
James Smarte59058c2008-08-24 21:49:00 -04002662/**
James Smart3621a712009-04-06 18:47:14 -04002663 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002664 * @vport: pointer to a host virtual N_Port data structure.
2665 * @nlp: pointer to a node-list data structure.
2666 *
2667 * This routine cancels the timer with a delayed IOCB-command retry for
2668 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2669 * removes the ELS retry event if it presents. In addition, if the
2670 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2671 * commands are sent for the @vport's nodes that require issuing discovery
2672 * ADISC.
2673 **/
dea31012005-04-17 16:05:31 -05002674void
James Smart2e0fef82007-06-17 19:56:36 -05002675lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002676{
James Smart2e0fef82007-06-17 19:56:36 -05002677 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002678 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002679
James Smart0d2b6b82008-06-14 22:52:47 -04002680 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2681 return;
James Smart2e0fef82007-06-17 19:56:36 -05002682 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002683 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002684 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002685 del_timer_sync(&nlp->nlp_delayfunc);
2686 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002687 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002688 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002689 /* Decrement nlp reference count held for the delayed retry */
2690 evtp = &nlp->els_retry_evt;
2691 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2692 }
James Smartfdcebe22006-03-07 15:04:01 -05002693 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002694 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002695 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002696 spin_unlock_irq(shost->host_lock);
2697 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002698 if (vport->port_state < LPFC_VPORT_READY) {
2699 /* Check if there are more ADISCs to be sent */
2700 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002701 } else {
2702 /* Check if there are more PLOGIs to be sent */
2703 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002704 if (vport->num_disc_nodes == 0) {
2705 spin_lock_irq(shost->host_lock);
2706 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2707 spin_unlock_irq(shost->host_lock);
2708 lpfc_can_disctmo(vport);
2709 lpfc_end_rscn(vport);
2710 }
James Smartfdcebe22006-03-07 15:04:01 -05002711 }
2712 }
2713 }
2714 return;
2715}
2716
James Smarte59058c2008-08-24 21:49:00 -04002717/**
James Smart3621a712009-04-06 18:47:14 -04002718 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002719 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2720 *
2721 * This routine is invoked by the ndlp delayed-function timer to check
2722 * whether there is any pending ELS retry event(s) with the node. If not, it
2723 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2724 * adds the delayed events to the HBA work list and invokes the
2725 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2726 * event. Note that lpfc_nlp_get() is called before posting the event to
2727 * the work list to hold reference count of ndlp so that it guarantees the
2728 * reference to ndlp will still be available when the worker thread gets
2729 * to the event associated with the ndlp.
2730 **/
James Smartfdcebe22006-03-07 15:04:01 -05002731void
dea31012005-04-17 16:05:31 -05002732lpfc_els_retry_delay(unsigned long ptr)
2733{
James Smart2e0fef82007-06-17 19:56:36 -05002734 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2735 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002736 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002737 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002738 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002739
James Smart92d7f7b2007-06-17 19:56:38 -05002740 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002741 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002742 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002743 return;
2744 }
2745
James Smartfa4066b2008-01-11 01:53:27 -05002746 /* We need to hold the node by incrementing the reference
2747 * count until the queued work is done
2748 */
2749 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002750 if (evtp->evt_arg1) {
2751 evtp->evt = LPFC_EVT_ELS_RETRY;
2752 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002753 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002754 }
James Smart92d7f7b2007-06-17 19:56:38 -05002755 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002756 return;
2757}
2758
James Smarte59058c2008-08-24 21:49:00 -04002759/**
James Smart3621a712009-04-06 18:47:14 -04002760 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002761 * @ndlp: pointer to a node-list data structure.
2762 *
2763 * This routine is the worker-thread handler for processing the @ndlp delayed
2764 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2765 * the last ELS command from the associated ndlp and invokes the proper ELS
2766 * function according to the delayed ELS command to retry the command.
2767 **/
dea31012005-04-17 16:05:31 -05002768void
2769lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2770{
James Smart2e0fef82007-06-17 19:56:36 -05002771 struct lpfc_vport *vport = ndlp->vport;
2772 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2773 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002774
James Smart2e0fef82007-06-17 19:56:36 -05002775 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002776 did = ndlp->nlp_DID;
2777 cmd = ndlp->nlp_last_elscmd;
2778 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002779
2780 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002781 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002782 return;
2783 }
2784
2785 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002786 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002787 /*
2788 * If a discovery event readded nlp_delayfunc after timer
2789 * firing and before processing the timer, cancel the
2790 * nlp_delayfunc.
2791 */
2792 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002793 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002794 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002795
2796 switch (cmd) {
2797 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002798 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002799 break;
2800 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002801 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002802 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002803 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002804 }
dea31012005-04-17 16:05:31 -05002805 break;
2806 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002807 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002808 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002809 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002810 }
dea31012005-04-17 16:05:31 -05002811 break;
2812 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002813 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002814 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002815 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002816 }
dea31012005-04-17 16:05:31 -05002817 break;
2818 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002819 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002820 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002821 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002822 }
dea31012005-04-17 16:05:31 -05002823 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002824 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05002825 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
2826 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05002827 break;
dea31012005-04-17 16:05:31 -05002828 }
2829 return;
2830}
2831
James Smarte59058c2008-08-24 21:49:00 -04002832/**
James Smart3621a712009-04-06 18:47:14 -04002833 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002834 * @phba: pointer to lpfc hba data structure.
2835 * @cmdiocb: pointer to lpfc command iocb data structure.
2836 * @rspiocb: pointer to lpfc response iocb data structure.
2837 *
2838 * This routine makes a retry decision on an ELS command IOCB, which has
2839 * failed. The following ELS IOCBs use this function for retrying the command
2840 * when previously issued command responsed with error status: FLOGI, PLOGI,
2841 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2842 * returned error status, it makes the decision whether a retry shall be
2843 * issued for the command, and whether a retry shall be made immediately or
2844 * delayed. In the former case, the corresponding ELS command issuing-function
2845 * is called to retry the command. In the later case, the ELS command shall
2846 * be posted to the ndlp delayed event and delayed function timer set to the
2847 * ndlp for the delayed command issusing.
2848 *
2849 * Return code
2850 * 0 - No retry of els command is made
2851 * 1 - Immediate or delayed retry of els command is made
2852 **/
dea31012005-04-17 16:05:31 -05002853static int
James Smart2e0fef82007-06-17 19:56:36 -05002854lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2855 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002856{
James Smart2e0fef82007-06-17 19:56:36 -05002857 struct lpfc_vport *vport = cmdiocb->vport;
2858 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2859 IOCB_t *irsp = &rspiocb->iocb;
2860 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2861 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002862 uint32_t *elscmd;
2863 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002864 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002865 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002866 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002867 uint32_t did;
dea31012005-04-17 16:05:31 -05002868
James Smart488d1462006-03-07 15:02:37 -05002869
dea31012005-04-17 16:05:31 -05002870 /* Note: context2 may be 0 for internal driver abort
2871 * of delays ELS command.
2872 */
2873
2874 if (pcmd && pcmd->virt) {
2875 elscmd = (uint32_t *) (pcmd->virt);
2876 cmd = *elscmd++;
2877 }
2878
James Smarte47c9092008-02-08 18:49:26 -05002879 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002880 did = ndlp->nlp_DID;
2881 else {
2882 /* We should only hit this case for retrying PLOGI */
2883 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002884 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002885 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2886 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002887 return 1;
2888 }
2889
James Smart858c9f62007-06-17 19:56:39 -05002890 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2891 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2892 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2893
dea31012005-04-17 16:05:31 -05002894 switch (irsp->ulpStatus) {
2895 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05002896 break;
James Smart1151e3e2011-02-16 12:39:35 -05002897 case IOSTAT_REMOTE_STOP:
2898 if (phba->sli_rev == LPFC_SLI_REV4) {
2899 /* This IO was aborted by the target, we don't
2900 * know the rxid and because we did not send the
2901 * ABTS we cannot generate and RRQ.
2902 */
2903 lpfc_set_rrq_active(phba, ndlp,
2904 cmdiocb->sli4_xritag, 0, 0);
2905 }
2906 break;
dea31012005-04-17 16:05:31 -05002907 case IOSTAT_LOCAL_REJECT:
2908 switch ((irsp->un.ulpWord[4] & 0xff)) {
2909 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002910 if (cmd == ELS_CMD_FLOGI) {
2911 if (PCI_DEVICE_ID_HORNET ==
2912 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05002913 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05002914 phba->pport->fc_myDID = 0;
2915 phba->alpa_map[0] = 0;
2916 phba->alpa_map[1] = 0;
2917 }
2918 }
James Smart2e0fef82007-06-17 19:56:36 -05002919 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002920 delay = 1000;
dea31012005-04-17 16:05:31 -05002921 retry = 1;
2922 break;
2923
James Smart92d7f7b2007-06-17 19:56:38 -05002924 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002925 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2926 "0124 Retry illegal cmd x%x "
2927 "retry:x%x delay:x%x\n",
2928 cmd, cmdiocb->retry, delay);
2929 retry = 1;
2930 /* All command's retry policy */
2931 maxretry = 8;
2932 if (cmdiocb->retry > 2)
2933 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002934 break;
2935
dea31012005-04-17 16:05:31 -05002936 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002937 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002938 retry = 1;
2939 if (cmdiocb->retry > 100)
2940 delay = 100;
2941 maxretry = 250;
2942 break;
2943
2944 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002945 delay = 100;
dea31012005-04-17 16:05:31 -05002946 retry = 1;
2947 break;
2948
James Smart858c9f62007-06-17 19:56:39 -05002949 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002950 case IOERR_INVALID_RPI:
2951 retry = 1;
2952 break;
2953 }
2954 break;
2955
2956 case IOSTAT_NPORT_RJT:
2957 case IOSTAT_FABRIC_RJT:
2958 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2959 retry = 1;
2960 break;
2961 }
2962 break;
2963
2964 case IOSTAT_NPORT_BSY:
2965 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002966 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002967 retry = 1;
2968 break;
2969
2970 case IOSTAT_LS_RJT:
2971 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2972 /* Added for Vendor specifc support
2973 * Just keep retrying for these Rsn / Exp codes
2974 */
2975 switch (stat.un.b.lsRjtRsnCode) {
2976 case LSRJT_UNABLE_TPC:
2977 if (stat.un.b.lsRjtRsnCodeExp ==
2978 LSEXP_CMD_IN_PROGRESS) {
2979 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002980 delay = 1000;
dea31012005-04-17 16:05:31 -05002981 maxretry = 48;
2982 }
2983 retry = 1;
2984 break;
2985 }
James Smartffc95492010-06-07 15:23:17 -04002986 if (stat.un.b.lsRjtRsnCodeExp ==
2987 LSEXP_CANT_GIVE_DATA) {
2988 if (cmd == ELS_CMD_PLOGI) {
2989 delay = 1000;
2990 maxretry = 48;
2991 }
2992 retry = 1;
2993 break;
2994 }
dea31012005-04-17 16:05:31 -05002995 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002996 delay = 1000;
dea31012005-04-17 16:05:31 -05002997 maxretry = lpfc_max_els_tries + 1;
2998 retry = 1;
2999 break;
3000 }
James Smart92d7f7b2007-06-17 19:56:38 -05003001 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3002 (cmd == ELS_CMD_FDISC) &&
3003 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003004 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3005 "0125 FDISC Failed (x%x). "
3006 "Fabric out of resources\n",
3007 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003008 lpfc_vport_set_state(vport,
3009 FC_VPORT_NO_FABRIC_RSCS);
3010 }
dea31012005-04-17 16:05:31 -05003011 break;
3012
3013 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003014 if ((cmd == ELS_CMD_PLOGI) ||
3015 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003016 delay = 1000;
dea31012005-04-17 16:05:31 -05003017 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003018 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003019 /* FDISC retry policy */
3020 maxretry = 48;
3021 if (cmdiocb->retry >= 32)
3022 delay = 1000;
dea31012005-04-17 16:05:31 -05003023 }
3024 retry = 1;
3025 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003026
3027 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003028 /* There are some cases where switches return this
3029 * error when they are not ready and should be returning
3030 * Logical Busy. We should delay every time.
3031 */
3032 if (cmd == ELS_CMD_FDISC &&
3033 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3034 maxretry = 3;
3035 delay = 1000;
3036 retry = 1;
3037 break;
3038 }
James Smart92d7f7b2007-06-17 19:56:38 -05003039 case LSRJT_PROTOCOL_ERR:
3040 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3041 (cmd == ELS_CMD_FDISC) &&
3042 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3043 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3044 ) {
James Smarte8b62012007-08-02 11:10:09 -04003045 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003046 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003047 "Fabric Detected Bad WWN\n",
3048 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003049 lpfc_vport_set_state(vport,
3050 FC_VPORT_FABRIC_REJ_WWN);
3051 }
3052 break;
dea31012005-04-17 16:05:31 -05003053 }
3054 break;
3055
3056 case IOSTAT_INTERMED_RSP:
3057 case IOSTAT_BA_RJT:
3058 break;
3059
3060 default:
3061 break;
3062 }
3063
James Smart488d1462006-03-07 15:02:37 -05003064 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003065 retry = 1;
dea31012005-04-17 16:05:31 -05003066
James Smart695a8142010-01-26 23:08:03 -05003067 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart76a95d72010-11-20 23:11:48 -05003068 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003069 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003070 /* FLOGI retry policy */
3071 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04003072 /* retry forever */
3073 maxretry = 0;
3074 if (cmdiocb->retry >= 100)
3075 delay = 5000;
3076 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003077 delay = 1000;
3078 }
3079
James Smart6669f9b2009-10-02 15:16:45 -04003080 cmdiocb->retry++;
3081 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003082 phba->fc_stat.elsRetryExceeded++;
3083 retry = 0;
3084 }
3085
James Smarted957682007-06-17 19:56:37 -05003086 if ((vport->load_flag & FC_UNLOADING) != 0)
3087 retry = 0;
3088
dea31012005-04-17 16:05:31 -05003089 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003090 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3091 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3092 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3093 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3094 "2849 Stop retry ELS command "
3095 "x%x to remote NPORT x%x, "
3096 "Data: x%x x%x\n", cmd, did,
3097 cmdiocb->retry, delay);
3098 return 0;
3099 }
3100 }
dea31012005-04-17 16:05:31 -05003101
3102 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003103 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3104 "0107 Retry ELS command x%x to remote "
3105 "NPORT x%x Data: x%x x%x\n",
3106 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003107
James Smart858c9f62007-06-17 19:56:39 -05003108 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3109 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3110 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
3111 /* Don't reset timer for no resources */
3112
dea31012005-04-17 16:05:31 -05003113 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003114 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003115 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003116 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003117 }
3118
3119 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003120 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003121 phba->fc_stat.elsDelayRetry++;
3122 ndlp->nlp_retry = cmdiocb->retry;
3123
James Smart92d7f7b2007-06-17 19:56:38 -05003124 /* delay is specified in milliseconds */
3125 mod_timer(&ndlp->nlp_delayfunc,
3126 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003127 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003128 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003129 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003130
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003131 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003132 if (cmd == ELS_CMD_PRLI)
3133 lpfc_nlp_set_state(vport, ndlp,
3134 NLP_STE_REG_LOGIN_ISSUE);
3135 else
3136 lpfc_nlp_set_state(vport, ndlp,
3137 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003138 ndlp->nlp_last_elscmd = cmd;
3139
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003140 return 1;
dea31012005-04-17 16:05:31 -05003141 }
3142 switch (cmd) {
3143 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003144 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003145 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003146 case ELS_CMD_FDISC:
3147 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3148 return 1;
dea31012005-04-17 16:05:31 -05003149 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003150 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003151 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003152 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003153 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003154 }
James Smart2e0fef82007-06-17 19:56:36 -05003155 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003156 return 1;
dea31012005-04-17 16:05:31 -05003157 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003158 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003159 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3160 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003161 return 1;
dea31012005-04-17 16:05:31 -05003162 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003163 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003164 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3165 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003166 return 1;
dea31012005-04-17 16:05:31 -05003167 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003168 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003169 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3170 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003171 return 1;
dea31012005-04-17 16:05:31 -05003172 }
3173 }
dea31012005-04-17 16:05:31 -05003174 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003175 if (logerr) {
3176 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3177 "0137 No retry ELS command x%x to remote "
3178 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3179 cmd, did, irsp->ulpStatus,
3180 irsp->un.ulpWord[4]);
3181 }
3182 else {
3183 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003184 "0108 No retry ELS command x%x to remote "
3185 "NPORT x%x Retried:%d Error:x%x/%x\n",
3186 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3187 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003188 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003189 return 0;
dea31012005-04-17 16:05:31 -05003190}
3191
James Smarte59058c2008-08-24 21:49:00 -04003192/**
James Smart3621a712009-04-06 18:47:14 -04003193 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003194 * @phba: pointer to lpfc hba data structure.
3195 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3196 *
3197 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3198 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3199 * checks to see whether there is a lpfc DMA buffer associated with the
3200 * response of the command IOCB. If so, it will be released before releasing
3201 * the lpfc DMA buffer associated with the IOCB itself.
3202 *
3203 * Return code
3204 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3205 **/
James Smart09372822008-01-11 01:52:54 -05003206static int
James Smart87af33f2007-10-27 13:37:43 -04003207lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3208{
3209 struct lpfc_dmabuf *buf_ptr;
3210
James Smarte59058c2008-08-24 21:49:00 -04003211 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003212 if (!list_empty(&buf_ptr1->list)) {
3213 list_remove_head(&buf_ptr1->list, buf_ptr,
3214 struct lpfc_dmabuf,
3215 list);
3216 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3217 kfree(buf_ptr);
3218 }
3219 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3220 kfree(buf_ptr1);
3221 return 0;
3222}
3223
James Smarte59058c2008-08-24 21:49:00 -04003224/**
James Smart3621a712009-04-06 18:47:14 -04003225 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003226 * @phba: pointer to lpfc hba data structure.
3227 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3228 *
3229 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3230 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3231 * pool.
3232 *
3233 * Return code
3234 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3235 **/
James Smart09372822008-01-11 01:52:54 -05003236static int
James Smart87af33f2007-10-27 13:37:43 -04003237lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3238{
3239 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3240 kfree(buf_ptr);
3241 return 0;
3242}
3243
James Smarte59058c2008-08-24 21:49:00 -04003244/**
James Smart3621a712009-04-06 18:47:14 -04003245 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003246 * @phba: pointer to lpfc hba data structure.
3247 * @elsiocb: pointer to lpfc els command iocb data structure.
3248 *
3249 * This routine frees a command IOCB and its associated resources. The
3250 * command IOCB data structure contains the reference to various associated
3251 * resources, these fields must be set to NULL if the associated reference
3252 * not present:
3253 * context1 - reference to ndlp
3254 * context2 - reference to cmd
3255 * context2->next - reference to rsp
3256 * context3 - reference to bpl
3257 *
3258 * It first properly decrements the reference count held on ndlp for the
3259 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3260 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3261 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3262 * adds the DMA buffer the @phba data structure for the delayed release.
3263 * If reference to the Buffer Pointer List (BPL) is present, the
3264 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3265 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3266 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3267 *
3268 * Return code
3269 * 0 - Success (currently, always return 0)
3270 **/
James Smart87af33f2007-10-27 13:37:43 -04003271int
James Smart329f9bc2007-04-25 09:53:01 -04003272lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003273{
3274 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003275 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003276
James Smarta8adb832007-10-27 13:37:53 -04003277 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3278 if (ndlp) {
3279 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3280 lpfc_nlp_put(ndlp);
3281
3282 /* If the ndlp is not being used by another discovery
3283 * thread, free it.
3284 */
3285 if (!lpfc_nlp_not_used(ndlp)) {
3286 /* If ndlp is being used by another discovery
3287 * thread, just clear NLP_DEFER_RM
3288 */
3289 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3290 }
3291 }
3292 else
3293 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003294 elsiocb->context1 = NULL;
3295 }
dea31012005-04-17 16:05:31 -05003296 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3297 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003298 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3299 /* Firmware could still be in progress of DMAing
3300 * payload, so don't free data buffer till after
3301 * a hbeat.
3302 */
3303 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3304 buf_ptr = elsiocb->context2;
3305 elsiocb->context2 = NULL;
3306 if (buf_ptr) {
3307 buf_ptr1 = NULL;
3308 spin_lock_irq(&phba->hbalock);
3309 if (!list_empty(&buf_ptr->list)) {
3310 list_remove_head(&buf_ptr->list,
3311 buf_ptr1, struct lpfc_dmabuf,
3312 list);
3313 INIT_LIST_HEAD(&buf_ptr1->list);
3314 list_add_tail(&buf_ptr1->list,
3315 &phba->elsbuf);
3316 phba->elsbuf_cnt++;
3317 }
3318 INIT_LIST_HEAD(&buf_ptr->list);
3319 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3320 phba->elsbuf_cnt++;
3321 spin_unlock_irq(&phba->hbalock);
3322 }
3323 } else {
3324 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3325 lpfc_els_free_data(phba, buf_ptr1);
3326 }
dea31012005-04-17 16:05:31 -05003327 }
3328
3329 if (elsiocb->context3) {
3330 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003331 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003332 }
James Bottomley604a3e32005-10-29 10:28:33 -05003333 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003334 return 0;
3335}
3336
James Smarte59058c2008-08-24 21:49:00 -04003337/**
James Smart3621a712009-04-06 18:47:14 -04003338 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003339 * @phba: pointer to lpfc hba data structure.
3340 * @cmdiocb: pointer to lpfc command iocb data structure.
3341 * @rspiocb: pointer to lpfc response iocb data structure.
3342 *
3343 * This routine is the completion callback function to the Logout (LOGO)
3344 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3345 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3346 * release the ndlp if it has the last reference remaining (reference count
3347 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3348 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3349 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3350 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3351 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3352 * IOCB data structure.
3353 **/
dea31012005-04-17 16:05:31 -05003354static void
James Smart2e0fef82007-06-17 19:56:36 -05003355lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3356 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003357{
James Smart2e0fef82007-06-17 19:56:36 -05003358 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3359 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003360 IOCB_t *irsp;
3361
3362 irsp = &rspiocb->iocb;
3363 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3364 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3365 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003366 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003367 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3368 "0109 ACC to LOGO completes to NPort x%x "
3369 "Data: x%x x%x x%x\n",
3370 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3371 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003372
3373 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3374 /* NPort Recovery mode or node is just allocated */
3375 if (!lpfc_nlp_not_used(ndlp)) {
3376 /* If the ndlp is being used by another discovery
3377 * thread, just unregister the RPI.
3378 */
3379 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003380 } else {
3381 /* Indicate the node has already released, should
3382 * not reference to it from within lpfc_els_free_iocb.
3383 */
3384 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003385 }
dea31012005-04-17 16:05:31 -05003386 }
3387 lpfc_els_free_iocb(phba, cmdiocb);
3388 return;
3389}
3390
James Smarte59058c2008-08-24 21:49:00 -04003391/**
James Smart3621a712009-04-06 18:47:14 -04003392 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003393 * @phba: pointer to lpfc hba data structure.
3394 * @pmb: pointer to the driver internal queue element for mailbox command.
3395 *
3396 * This routine is the completion callback function for unregister default
3397 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3398 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3399 * decrements the ndlp reference count held for this completion callback
3400 * function. After that, it invokes the lpfc_nlp_not_used() to check
3401 * whether there is only one reference left on the ndlp. If so, it will
3402 * perform one more decrement and trigger the release of the ndlp.
3403 **/
James Smart858c9f62007-06-17 19:56:39 -05003404void
3405lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3406{
3407 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3408 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3409
3410 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003411 pmb->context2 = NULL;
3412
James Smart858c9f62007-06-17 19:56:39 -05003413 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3414 kfree(mp);
3415 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003416 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003417 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003418 /* This is the end of the default RPI cleanup logic for this
3419 * ndlp. If no other discovery threads are using this ndlp.
3420 * we should free all resources associated with it.
3421 */
3422 lpfc_nlp_not_used(ndlp);
3423 }
James Smart3772a992009-05-22 14:50:54 -04003424
James Smart858c9f62007-06-17 19:56:39 -05003425 return;
3426}
3427
James Smarte59058c2008-08-24 21:49:00 -04003428/**
James Smart3621a712009-04-06 18:47:14 -04003429 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003430 * @phba: pointer to lpfc hba data structure.
3431 * @cmdiocb: pointer to lpfc command iocb data structure.
3432 * @rspiocb: pointer to lpfc response iocb data structure.
3433 *
3434 * This routine is the completion callback function for ELS Response IOCB
3435 * command. In normal case, this callback function just properly sets the
3436 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3437 * field in the command IOCB is not NULL, the referred mailbox command will
3438 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3439 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3440 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3441 * routine shall be invoked trying to release the ndlp if no other threads
3442 * are currently referring it.
3443 **/
dea31012005-04-17 16:05:31 -05003444static void
James Smart858c9f62007-06-17 19:56:39 -05003445lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003446 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003447{
James Smart2e0fef82007-06-17 19:56:36 -05003448 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3449 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3450 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003451 IOCB_t *irsp;
3452 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003453 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003454 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003455 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003456
James Smart33ccf8d2006-08-17 11:57:58 -04003457 irsp = &rspiocb->iocb;
3458
dea31012005-04-17 16:05:31 -05003459 if (cmdiocb->context_un.mbox)
3460 mbox = cmdiocb->context_un.mbox;
3461
James Smartfa4066b2008-01-11 01:53:27 -05003462 /* First determine if this is a LS_RJT cmpl. Note, this callback
3463 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3464 */
James Smart87af33f2007-10-27 13:37:43 -04003465 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003466 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3467 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003468 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003469 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003470 */
3471 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3472 ls_rjt = 1;
3473 }
3474
dea31012005-04-17 16:05:31 -05003475 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003476 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003477 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003478 mp = (struct lpfc_dmabuf *) mbox->context1;
3479 if (mp) {
3480 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3481 kfree(mp);
3482 }
James Smart329f9bc2007-04-25 09:53:01 -04003483 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003484 }
James Smart58da1ff2008-04-07 10:15:56 -04003485 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3486 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003487 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003488 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003489 /* Indicate the node has already released,
3490 * should not reference to it from within
3491 * the routine lpfc_els_free_iocb.
3492 */
3493 cmdiocb->context1 = NULL;
3494 }
dea31012005-04-17 16:05:31 -05003495 goto out;
3496 }
3497
James Smart858c9f62007-06-17 19:56:39 -05003498 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003499 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003500 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003501 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003502 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003503 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3504 "0110 ELS response tag x%x completes "
3505 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3506 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3507 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3508 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3509 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003510 if (mbox) {
3511 if ((rspiocb->iocb.ulpStatus == 0)
3512 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003513 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003514 /* Increment reference count to ndlp to hold the
3515 * reference to ndlp for the callback function.
3516 */
James Smart329f9bc2007-04-25 09:53:01 -04003517 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003518 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003519 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3520 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3521 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3522 }
3523 else {
3524 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3525 ndlp->nlp_prev_state = ndlp->nlp_state;
3526 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003527 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003528 }
James Smart0b727fe2007-10-27 13:37:25 -04003529 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003530 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003531 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003532 else
3533 /* Decrement the ndlp reference count we
3534 * set for this failed mailbox command.
3535 */
3536 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003537
3538 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3539 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3540 "0138 ELS rsp: Cannot issue reg_login for x%x "
3541 "Data: x%x x%x x%x\n",
3542 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3543 ndlp->nlp_rpi);
3544
James Smartfa4066b2008-01-11 01:53:27 -05003545 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003546 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003547 /* Indicate node has already been released,
3548 * should not reference to it from within
3549 * the routine lpfc_els_free_iocb.
3550 */
3551 cmdiocb->context1 = NULL;
3552 }
dea31012005-04-17 16:05:31 -05003553 } else {
James Smart858c9f62007-06-17 19:56:39 -05003554 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3555 if (!lpfc_error_lost_link(irsp) &&
3556 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003557 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003558 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003559 /* Indicate node has already been
3560 * released, should not reference
3561 * to it from within the routine
3562 * lpfc_els_free_iocb.
3563 */
3564 cmdiocb->context1 = NULL;
3565 }
dea31012005-04-17 16:05:31 -05003566 }
3567 }
James Smart14691152006-12-02 13:34:28 -05003568 mp = (struct lpfc_dmabuf *) mbox->context1;
3569 if (mp) {
3570 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3571 kfree(mp);
3572 }
3573 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003574 }
3575out:
James Smart58da1ff2008-04-07 10:15:56 -04003576 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003577 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003578 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003579 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003580
3581 /* If the node is not being used by another discovery thread,
3582 * and we are sending a reject, we are done with it.
3583 * Release driver reference count here and free associated
3584 * resources.
3585 */
3586 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003587 if (lpfc_nlp_not_used(ndlp))
3588 /* Indicate node has already been released,
3589 * should not reference to it from within
3590 * the routine lpfc_els_free_iocb.
3591 */
3592 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003593 }
James Smart87af33f2007-10-27 13:37:43 -04003594
dea31012005-04-17 16:05:31 -05003595 lpfc_els_free_iocb(phba, cmdiocb);
3596 return;
3597}
3598
James Smarte59058c2008-08-24 21:49:00 -04003599/**
James Smart3621a712009-04-06 18:47:14 -04003600 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003601 * @vport: pointer to a host virtual N_Port data structure.
3602 * @flag: the els command code to be accepted.
3603 * @oldiocb: pointer to the original lpfc command iocb data structure.
3604 * @ndlp: pointer to a node-list data structure.
3605 * @mbox: pointer to the driver internal queue element for mailbox command.
3606 *
3607 * This routine prepares and issues an Accept (ACC) response IOCB
3608 * command. It uses the @flag to properly set up the IOCB field for the
3609 * specific ACC response command to be issued and invokes the
3610 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3611 * @mbox pointer is passed in, it will be put into the context_un.mbox
3612 * field of the IOCB for the completion callback function to issue the
3613 * mailbox command to the HBA later when callback is invoked.
3614 *
3615 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3616 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3617 * will be stored into the context1 field of the IOCB for the completion
3618 * callback function to the corresponding response ELS IOCB command.
3619 *
3620 * Return code
3621 * 0 - Successfully issued acc response
3622 * 1 - Failed to issue acc response
3623 **/
dea31012005-04-17 16:05:31 -05003624int
James Smart2e0fef82007-06-17 19:56:36 -05003625lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3626 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003627 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003628{
James Smart2e0fef82007-06-17 19:56:36 -05003629 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3630 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003631 IOCB_t *icmd;
3632 IOCB_t *oldcmd;
3633 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003634 struct lpfc_sli *psli;
3635 uint8_t *pcmd;
3636 uint16_t cmdsize;
3637 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003638 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003639
3640 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003641 oldcmd = &oldiocb->iocb;
3642
3643 switch (flag) {
3644 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003645 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003646 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3647 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003648 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003649 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003650 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003651 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003652 return 1;
dea31012005-04-17 16:05:31 -05003653 }
James Smart2e0fef82007-06-17 19:56:36 -05003654
dea31012005-04-17 16:05:31 -05003655 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003656 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3657 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003658 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3659 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003660 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003661
3662 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3663 "Issue ACC: did:x%x flg:x%x",
3664 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003665 break;
3666 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003667 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003668 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3669 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003670 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003671 return 1;
James Smart488d1462006-03-07 15:02:37 -05003672
dea31012005-04-17 16:05:31 -05003673 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003674 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3675 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003676 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3677
3678 if (mbox)
3679 elsiocb->context_un.mbox = mbox;
3680
3681 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003682 pcmd += sizeof(uint32_t);
3683 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003684
3685 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3686 "Issue ACC PLOGI: did:x%x flg:x%x",
3687 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003688 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003689 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003690 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003691 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003692 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3693 if (!elsiocb)
3694 return 1;
3695
3696 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003697 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3698 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04003699 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3700
3701 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003702 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003703 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3704 els_pkt_ptr = (ELS_PKT *) pcmd;
3705 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003706
3707 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3708 "Issue ACC PRLO: did:x%x flg:x%x",
3709 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003710 break;
dea31012005-04-17 16:05:31 -05003711 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003712 return 1;
dea31012005-04-17 16:05:31 -05003713 }
dea31012005-04-17 16:05:31 -05003714 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003715 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3716 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3717 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3718 elsiocb->iotag, elsiocb->iocb.ulpContext,
3719 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3720 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003721 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003722 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003723 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003724 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003725 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3726 } else {
James Smart858c9f62007-06-17 19:56:39 -05003727 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003728 }
3729
3730 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003731 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003732 if (rc == IOCB_ERROR) {
3733 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003734 return 1;
dea31012005-04-17 16:05:31 -05003735 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003736 return 0;
dea31012005-04-17 16:05:31 -05003737}
3738
James Smarte59058c2008-08-24 21:49:00 -04003739/**
James Smart3621a712009-04-06 18:47:14 -04003740 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003741 * @vport: pointer to a virtual N_Port data structure.
3742 * @rejectError:
3743 * @oldiocb: pointer to the original lpfc command iocb data structure.
3744 * @ndlp: pointer to a node-list data structure.
3745 * @mbox: pointer to the driver internal queue element for mailbox command.
3746 *
3747 * This routine prepares and issue an Reject (RJT) response IOCB
3748 * command. If a @mbox pointer is passed in, it will be put into the
3749 * context_un.mbox field of the IOCB for the completion callback function
3750 * to issue to the HBA later.
3751 *
3752 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3753 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3754 * will be stored into the context1 field of the IOCB for the completion
3755 * callback function to the reject response ELS IOCB command.
3756 *
3757 * Return code
3758 * 0 - Successfully issued reject response
3759 * 1 - Failed to issue reject response
3760 **/
dea31012005-04-17 16:05:31 -05003761int
James Smart2e0fef82007-06-17 19:56:36 -05003762lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003763 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3764 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003765{
James Smart2e0fef82007-06-17 19:56:36 -05003766 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003767 IOCB_t *icmd;
3768 IOCB_t *oldcmd;
3769 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003770 struct lpfc_sli *psli;
3771 uint8_t *pcmd;
3772 uint16_t cmdsize;
3773 int rc;
3774
3775 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003776 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003777 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3778 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003779 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003780 return 1;
dea31012005-04-17 16:05:31 -05003781
3782 icmd = &elsiocb->iocb;
3783 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003784 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3785 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003786 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3787
3788 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003789 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003790 *((uint32_t *) (pcmd)) = rejectError;
3791
James Smart51ef4c22007-08-02 11:10:31 -04003792 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003793 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003794
dea31012005-04-17 16:05:31 -05003795 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003796 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3797 "0129 Xmit ELS RJT x%x response tag x%x "
3798 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3799 "rpi x%x\n",
3800 rejectError, elsiocb->iotag,
3801 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3802 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003803 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3804 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3805 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3806
dea31012005-04-17 16:05:31 -05003807 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003808 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003809 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003810
dea31012005-04-17 16:05:31 -05003811 if (rc == IOCB_ERROR) {
3812 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003813 return 1;
dea31012005-04-17 16:05:31 -05003814 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003815 return 0;
dea31012005-04-17 16:05:31 -05003816}
3817
James Smarte59058c2008-08-24 21:49:00 -04003818/**
James Smart3621a712009-04-06 18:47:14 -04003819 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003820 * @vport: pointer to a virtual N_Port data structure.
3821 * @oldiocb: pointer to the original lpfc command iocb data structure.
3822 * @ndlp: pointer to a node-list data structure.
3823 *
3824 * This routine prepares and issues an Accept (ACC) response to Address
3825 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3826 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3827 *
3828 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3829 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3830 * will be stored into the context1 field of the IOCB for the completion
3831 * callback function to the ADISC Accept response ELS IOCB command.
3832 *
3833 * Return code
3834 * 0 - Successfully issued acc adisc response
3835 * 1 - Failed to issue adisc acc response
3836 **/
dea31012005-04-17 16:05:31 -05003837int
James Smart2e0fef82007-06-17 19:56:36 -05003838lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3839 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003840{
James Smart2e0fef82007-06-17 19:56:36 -05003841 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003842 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003843 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003844 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003845 uint8_t *pcmd;
3846 uint16_t cmdsize;
3847 int rc;
3848
James Smart92d7f7b2007-06-17 19:56:38 -05003849 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003850 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3851 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003852 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003853 return 1;
dea31012005-04-17 16:05:31 -05003854
dea31012005-04-17 16:05:31 -05003855 icmd = &elsiocb->iocb;
3856 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003857 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3858 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04003859
3860 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003861 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3862 "0130 Xmit ADISC ACC response iotag x%x xri: "
3863 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3864 elsiocb->iotag, elsiocb->iocb.ulpContext,
3865 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3866 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003867 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3868
3869 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003870 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003871
3872 ap = (ADISC *) (pcmd);
3873 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003874 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3875 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003876 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003877
James Smart858c9f62007-06-17 19:56:39 -05003878 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3879 "Issue ACC ADISC: did:x%x flg:x%x",
3880 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3881
dea31012005-04-17 16:05:31 -05003882 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003883 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003884 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003885 if (rc == IOCB_ERROR) {
3886 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003887 return 1;
dea31012005-04-17 16:05:31 -05003888 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003889 return 0;
dea31012005-04-17 16:05:31 -05003890}
3891
James Smarte59058c2008-08-24 21:49:00 -04003892/**
James Smart3621a712009-04-06 18:47:14 -04003893 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003894 * @vport: pointer to a virtual N_Port data structure.
3895 * @oldiocb: pointer to the original lpfc command iocb data structure.
3896 * @ndlp: pointer to a node-list data structure.
3897 *
3898 * This routine prepares and issues an Accept (ACC) response to Process
3899 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3900 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3901 *
3902 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3903 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3904 * will be stored into the context1 field of the IOCB for the completion
3905 * callback function to the PRLI Accept response ELS IOCB command.
3906 *
3907 * Return code
3908 * 0 - Successfully issued acc prli response
3909 * 1 - Failed to issue acc prli response
3910 **/
dea31012005-04-17 16:05:31 -05003911int
James Smart2e0fef82007-06-17 19:56:36 -05003912lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003913 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003914{
James Smart2e0fef82007-06-17 19:56:36 -05003915 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003916 PRLI *npr;
3917 lpfc_vpd_t *vpd;
3918 IOCB_t *icmd;
3919 IOCB_t *oldcmd;
3920 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003921 struct lpfc_sli *psli;
3922 uint8_t *pcmd;
3923 uint16_t cmdsize;
3924 int rc;
3925
3926 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003927
James Smart92d7f7b2007-06-17 19:56:38 -05003928 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003929 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003930 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003931 if (!elsiocb)
3932 return 1;
dea31012005-04-17 16:05:31 -05003933
dea31012005-04-17 16:05:31 -05003934 icmd = &elsiocb->iocb;
3935 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003936 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3937 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
3938
James Smart5b8bd0c2007-04-25 09:52:49 -04003939 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003940 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3941 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3942 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3943 elsiocb->iotag, elsiocb->iocb.ulpContext,
3944 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3945 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003946 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3947
3948 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003949 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003950
3951 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003952 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003953
3954 npr = (PRLI *) pcmd;
3955 vpd = &phba->vpd;
3956 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003957 * If the remote port is a target and our firmware version is 3.20 or
3958 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003959 */
James Smart0d2b6b82008-06-14 22:52:47 -04003960 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3961 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003962 npr->ConfmComplAllowed = 1;
3963 npr->Retry = 1;
3964 npr->TaskRetryIdReq = 1;
3965 }
3966
3967 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3968 npr->estabImagePair = 1;
3969 npr->readXferRdyDis = 1;
3970 npr->ConfmComplAllowed = 1;
3971
3972 npr->prliType = PRLI_FCP_TYPE;
3973 npr->initiatorFunc = 1;
3974
James Smart858c9f62007-06-17 19:56:39 -05003975 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3976 "Issue ACC PRLI: did:x%x flg:x%x",
3977 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3978
dea31012005-04-17 16:05:31 -05003979 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003980 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003981
James Smart3772a992009-05-22 14:50:54 -04003982 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003983 if (rc == IOCB_ERROR) {
3984 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003985 return 1;
dea31012005-04-17 16:05:31 -05003986 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003987 return 0;
dea31012005-04-17 16:05:31 -05003988}
3989
James Smarte59058c2008-08-24 21:49:00 -04003990/**
James Smart3621a712009-04-06 18:47:14 -04003991 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003992 * @vport: pointer to a virtual N_Port data structure.
3993 * @format: rnid command format.
3994 * @oldiocb: pointer to the original lpfc command iocb data structure.
3995 * @ndlp: pointer to a node-list data structure.
3996 *
3997 * This routine issues a Request Node Identification Data (RNID) Accept
3998 * (ACC) response. It constructs the RNID ACC response command according to
3999 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4000 * issue the response. Note that this command does not need to hold the ndlp
4001 * reference count for the callback. So, the ndlp reference count taken by
4002 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4003 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4004 * there is no ndlp reference available.
4005 *
4006 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4007 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4008 * will be stored into the context1 field of the IOCB for the completion
4009 * callback function. However, for the RNID Accept Response ELS command,
4010 * this is undone later by this routine after the IOCB is allocated.
4011 *
4012 * Return code
4013 * 0 - Successfully issued acc rnid response
4014 * 1 - Failed to issue acc rnid response
4015 **/
dea31012005-04-17 16:05:31 -05004016static int
James Smart2e0fef82007-06-17 19:56:36 -05004017lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004018 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004019{
James Smart2e0fef82007-06-17 19:56:36 -05004020 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004021 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004022 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004023 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004024 struct lpfc_sli *psli;
4025 uint8_t *pcmd;
4026 uint16_t cmdsize;
4027 int rc;
4028
4029 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004030 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4031 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004032 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004033 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004034
James Smart2e0fef82007-06-17 19:56:36 -05004035 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4036 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004037 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004038 return 1;
dea31012005-04-17 16:05:31 -05004039
dea31012005-04-17 16:05:31 -05004040 icmd = &elsiocb->iocb;
4041 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004042 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4043 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4044
James Smart5b8bd0c2007-04-25 09:52:49 -04004045 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004046 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4047 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4048 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004049 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004050 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004051 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004052
James Smart92d7f7b2007-06-17 19:56:38 -05004053 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004054 rn = (RNID *) (pcmd);
4055 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004056 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4057 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4058 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004059 switch (format) {
4060 case 0:
4061 rn->SpecificLen = 0;
4062 break;
4063 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004064 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004065 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004066 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004067 rn->un.topologyDisc.unitType = RNID_HBA;
4068 rn->un.topologyDisc.physPort = 0;
4069 rn->un.topologyDisc.attachedNodes = 0;
4070 break;
4071 default:
4072 rn->CommonLen = 0;
4073 rn->SpecificLen = 0;
4074 break;
4075 }
4076
James Smart858c9f62007-06-17 19:56:39 -05004077 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4078 "Issue ACC RNID: did:x%x flg:x%x",
4079 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4080
dea31012005-04-17 16:05:31 -05004081 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004082 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04004083 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004084 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
4085 * it could be freed */
4086
James Smart3772a992009-05-22 14:50:54 -04004087 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004088 if (rc == IOCB_ERROR) {
4089 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004090 return 1;
dea31012005-04-17 16:05:31 -05004091 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004092 return 0;
dea31012005-04-17 16:05:31 -05004093}
4094
James Smarte59058c2008-08-24 21:49:00 -04004095/**
James Smart19ca7602010-11-20 23:11:55 -05004096 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4097 * @vport: pointer to a virtual N_Port data structure.
4098 * @iocb: pointer to the lpfc command iocb data structure.
4099 * @ndlp: pointer to a node-list data structure.
4100 *
4101 * Return
4102 **/
4103static void
4104lpfc_els_clear_rrq(struct lpfc_vport *vport,
4105 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4106{
4107 struct lpfc_hba *phba = vport->phba;
4108 uint8_t *pcmd;
4109 struct RRQ *rrq;
4110 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004111 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004112 struct lpfc_node_rrq *prrq;
4113
4114
4115 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4116 pcmd += sizeof(uint32_t);
4117 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004118 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b062011-04-16 11:03:17 -04004119 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004120
4121 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4122 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4123 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004124 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b062011-04-16 11:03:17 -04004125 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004126 rxid,
4127 iocb->iotag, iocb->iocb.ulpContext);
4128
4129 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4130 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4131 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004132 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b062011-04-16 11:03:17 -04004133 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004134 else
4135 xri = rxid;
4136 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004137 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004138 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004139 return;
4140}
4141
4142/**
James Smart12265f62010-10-22 11:05:53 -04004143 * lpfc_els_rsp_echo_acc - Issue echo acc response
4144 * @vport: pointer to a virtual N_Port data structure.
4145 * @data: pointer to echo data to return in the accept.
4146 * @oldiocb: pointer to the original lpfc command iocb data structure.
4147 * @ndlp: pointer to a node-list data structure.
4148 *
4149 * Return code
4150 * 0 - Successfully issued acc echo response
4151 * 1 - Failed to issue acc echo response
4152 **/
4153static int
4154lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4155 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4156{
4157 struct lpfc_hba *phba = vport->phba;
4158 struct lpfc_iocbq *elsiocb;
4159 struct lpfc_sli *psli;
4160 uint8_t *pcmd;
4161 uint16_t cmdsize;
4162 int rc;
4163
4164 psli = &phba->sli;
4165 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4166
4167 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4168 ndlp->nlp_DID, ELS_CMD_ACC);
4169 if (!elsiocb)
4170 return 1;
4171
James Smart7851fe22011-07-22 18:36:52 -04004172 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4173 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4174
James Smart12265f62010-10-22 11:05:53 -04004175 /* Xmit ECHO ACC response tag <ulpIoTag> */
4176 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4177 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4178 elsiocb->iotag, elsiocb->iocb.ulpContext);
4179 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4180 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4181 pcmd += sizeof(uint32_t);
4182 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4183
4184 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4185 "Issue ACC ECHO: did:x%x flg:x%x",
4186 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4187
4188 phba->fc_stat.elsXmitACC++;
4189 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4190 lpfc_nlp_put(ndlp);
4191 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
4192 * it could be freed */
4193
4194 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4195 if (rc == IOCB_ERROR) {
4196 lpfc_els_free_iocb(phba, elsiocb);
4197 return 1;
4198 }
4199 return 0;
4200}
4201
4202/**
James Smart3621a712009-04-06 18:47:14 -04004203 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004204 * @vport: pointer to a host virtual N_Port data structure.
4205 *
4206 * This routine issues Address Discover (ADISC) ELS commands to those
4207 * N_Ports which are in node port recovery state and ADISC has not been issued
4208 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4209 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4210 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4211 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4212 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4213 * IOCBs quit for later pick up. On the other hand, after walking through
4214 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4215 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4216 * no more ADISC need to be sent.
4217 *
4218 * Return code
4219 * The number of N_Ports with adisc issued.
4220 **/
dea31012005-04-17 16:05:31 -05004221int
James Smart2e0fef82007-06-17 19:56:36 -05004222lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004223{
James Smart2e0fef82007-06-17 19:56:36 -05004224 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004225 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004226 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004227
James Smart685f0bf2007-04-25 09:53:08 -04004228 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004229 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004230 if (!NLP_CHK_NODE_ACT(ndlp))
4231 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004232 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4233 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4234 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004235 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004236 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004237 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004238 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004239 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4240 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004241 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004242 vport->num_disc_nodes++;
4243 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004244 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004245 spin_lock_irq(shost->host_lock);
4246 vport->fc_flag |= FC_NLP_MORE;
4247 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004248 break;
dea31012005-04-17 16:05:31 -05004249 }
4250 }
4251 }
4252 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004253 spin_lock_irq(shost->host_lock);
4254 vport->fc_flag &= ~FC_NLP_MORE;
4255 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004256 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004257 return sentadisc;
dea31012005-04-17 16:05:31 -05004258}
4259
James Smarte59058c2008-08-24 21:49:00 -04004260/**
James Smart3621a712009-04-06 18:47:14 -04004261 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004262 * @vport: pointer to a host virtual N_Port data structure.
4263 *
4264 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4265 * which are in node port recovery state, with a @vport. Each time an ELS
4266 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4267 * the per @vport number of discover count (num_disc_nodes) shall be
4268 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4269 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4270 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4271 * later pick up. On the other hand, after walking through all the ndlps with
4272 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4273 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4274 * PLOGI need to be sent.
4275 *
4276 * Return code
4277 * The number of N_Ports with plogi issued.
4278 **/
dea31012005-04-17 16:05:31 -05004279int
James Smart2e0fef82007-06-17 19:56:36 -05004280lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004281{
James Smart2e0fef82007-06-17 19:56:36 -05004282 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004283 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004284 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004285
James Smart2e0fef82007-06-17 19:56:36 -05004286 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4287 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004288 if (!NLP_CHK_NODE_ACT(ndlp))
4289 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004290 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4291 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4292 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4293 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4294 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004295 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4296 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004297 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004298 vport->num_disc_nodes++;
4299 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004300 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004301 spin_lock_irq(shost->host_lock);
4302 vport->fc_flag |= FC_NLP_MORE;
4303 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004304 break;
dea31012005-04-17 16:05:31 -05004305 }
4306 }
4307 }
James Smart87af33f2007-10-27 13:37:43 -04004308 if (sentplogi) {
4309 lpfc_set_disctmo(vport);
4310 }
4311 else {
James Smart2e0fef82007-06-17 19:56:36 -05004312 spin_lock_irq(shost->host_lock);
4313 vport->fc_flag &= ~FC_NLP_MORE;
4314 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004315 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004316 return sentplogi;
dea31012005-04-17 16:05:31 -05004317}
4318
James Smarte59058c2008-08-24 21:49:00 -04004319/**
James Smart3621a712009-04-06 18:47:14 -04004320 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004321 * @vport: pointer to a host virtual N_Port data structure.
4322 *
4323 * This routine cleans up any Registration State Change Notification
4324 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4325 * @vport together with the host_lock is used to prevent multiple thread
4326 * trying to access the RSCN array on a same @vport at the same time.
4327 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004328void
James Smart2e0fef82007-06-17 19:56:36 -05004329lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004330{
James Smart2e0fef82007-06-17 19:56:36 -05004331 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4332 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004333 int i;
4334
James Smart7f5f3d02008-02-08 18:50:14 -05004335 spin_lock_irq(shost->host_lock);
4336 if (vport->fc_rscn_flush) {
4337 /* Another thread is walking fc_rscn_id_list on this vport */
4338 spin_unlock_irq(shost->host_lock);
4339 return;
4340 }
4341 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4342 vport->fc_rscn_flush = 1;
4343 spin_unlock_irq(shost->host_lock);
4344
James Smart2e0fef82007-06-17 19:56:36 -05004345 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004346 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004347 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004348 }
James Smart2e0fef82007-06-17 19:56:36 -05004349 spin_lock_irq(shost->host_lock);
4350 vport->fc_rscn_id_cnt = 0;
4351 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4352 spin_unlock_irq(shost->host_lock);
4353 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004354 /* Indicate we are done walking this fc_rscn_id_list */
4355 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004356}
4357
James Smarte59058c2008-08-24 21:49:00 -04004358/**
James Smart3621a712009-04-06 18:47:14 -04004359 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004360 * @vport: pointer to a host virtual N_Port data structure.
4361 * @did: remote destination port identifier.
4362 *
4363 * This routine checks whether there is any pending Registration State
4364 * Configuration Notification (RSCN) to a @did on @vport.
4365 *
4366 * Return code
4367 * None zero - The @did matched with a pending rscn
4368 * 0 - not able to match @did with a pending rscn
4369 **/
dea31012005-04-17 16:05:31 -05004370int
James Smart2e0fef82007-06-17 19:56:36 -05004371lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004372{
4373 D_ID ns_did;
4374 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004375 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004376 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004377 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004378
4379 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004380
4381 /* Never match fabric nodes for RSCNs */
4382 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004383 return 0;
dea31012005-04-17 16:05:31 -05004384
4385 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004386 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004387 return did;
dea31012005-04-17 16:05:31 -05004388
James Smart7f5f3d02008-02-08 18:50:14 -05004389 spin_lock_irq(shost->host_lock);
4390 if (vport->fc_rscn_flush) {
4391 /* Another thread is walking fc_rscn_id_list on this vport */
4392 spin_unlock_irq(shost->host_lock);
4393 return 0;
4394 }
4395 /* Indicate we are walking fc_rscn_id_list on this vport */
4396 vport->fc_rscn_flush = 1;
4397 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004398 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004399 lp = vport->fc_rscn_id_list[i]->virt;
4400 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4401 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004402 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004403 rscn_did.un.word = be32_to_cpu(*lp++);
4404 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004405 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4406 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004407 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4408 && (ns_did.un.b.area == rscn_did.un.b.area)
4409 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004410 goto return_did_out;
dea31012005-04-17 16:05:31 -05004411 break;
James Smarteaf15d52008-12-04 22:39:29 -05004412 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004413 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4414 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004415 goto return_did_out;
dea31012005-04-17 16:05:31 -05004416 break;
James Smarteaf15d52008-12-04 22:39:29 -05004417 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004418 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004419 goto return_did_out;
dea31012005-04-17 16:05:31 -05004420 break;
James Smarteaf15d52008-12-04 22:39:29 -05004421 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004422 goto return_did_out;
dea31012005-04-17 16:05:31 -05004423 }
4424 }
James Smart92d7f7b2007-06-17 19:56:38 -05004425 }
James Smart7f5f3d02008-02-08 18:50:14 -05004426 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4427 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004428 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004429return_did_out:
4430 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4431 vport->fc_rscn_flush = 0;
4432 return did;
dea31012005-04-17 16:05:31 -05004433}
4434
James Smarte59058c2008-08-24 21:49:00 -04004435/**
James Smart3621a712009-04-06 18:47:14 -04004436 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004437 * @vport: pointer to a host virtual N_Port data structure.
4438 *
4439 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4440 * state machine for a @vport's nodes that are with pending RSCN (Registration
4441 * State Change Notification).
4442 *
4443 * Return code
4444 * 0 - Successful (currently alway return 0)
4445 **/
dea31012005-04-17 16:05:31 -05004446static int
James Smart2e0fef82007-06-17 19:56:36 -05004447lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004448{
James Smart685f0bf2007-04-25 09:53:08 -04004449 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004450
James Smart0d2b6b82008-06-14 22:52:47 -04004451 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004452 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004453 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004454 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4455 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004456 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004457 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004458 NLP_EVT_DEVICE_RECOVERY);
4459 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004460 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004461 return 0;
dea31012005-04-17 16:05:31 -05004462}
4463
James Smarte59058c2008-08-24 21:49:00 -04004464/**
James Smart3621a712009-04-06 18:47:14 -04004465 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004466 * @vport: pointer to a host virtual N_Port data structure.
4467 * @cmdiocb: pointer to lpfc command iocb data structure.
4468 *
4469 * lpfc_send_rscn_event sends an RSCN netlink event to management
4470 * applications.
4471 */
4472static void
4473lpfc_send_rscn_event(struct lpfc_vport *vport,
4474 struct lpfc_iocbq *cmdiocb)
4475{
4476 struct lpfc_dmabuf *pcmd;
4477 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4478 uint32_t *payload_ptr;
4479 uint32_t payload_len;
4480 struct lpfc_rscn_event_header *rscn_event_data;
4481
4482 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4483 payload_ptr = (uint32_t *) pcmd->virt;
4484 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4485
4486 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4487 payload_len, GFP_KERNEL);
4488 if (!rscn_event_data) {
4489 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4490 "0147 Failed to allocate memory for RSCN event\n");
4491 return;
4492 }
4493 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4494 rscn_event_data->payload_length = payload_len;
4495 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4496 payload_len);
4497
4498 fc_host_post_vendor_event(shost,
4499 fc_get_event_number(),
4500 sizeof(struct lpfc_els_event_header) + payload_len,
4501 (char *)rscn_event_data,
4502 LPFC_NL_VENDOR_ID);
4503
4504 kfree(rscn_event_data);
4505}
4506
4507/**
James Smart3621a712009-04-06 18:47:14 -04004508 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004509 * @vport: pointer to a host virtual N_Port data structure.
4510 * @cmdiocb: pointer to lpfc command iocb data structure.
4511 * @ndlp: pointer to a node-list data structure.
4512 *
4513 * This routine processes an unsolicited RSCN (Registration State Change
4514 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4515 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4516 * discover state machine is about to begin discovery, it just accepts the
4517 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4518 * contains N_Port IDs for other vports on this HBA, it just accepts the
4519 * RSCN and ignore processing it. If the state machine is in the recovery
4520 * state, the fc_rscn_id_list of this @vport is walked and the
4521 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4522 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4523 * routine is invoked to handle the RSCN event.
4524 *
4525 * Return code
4526 * 0 - Just sent the acc response
4527 * 1 - Sent the acc response and waited for name server completion
4528 **/
dea31012005-04-17 16:05:31 -05004529static int
James Smart2e0fef82007-06-17 19:56:36 -05004530lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004531 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004532{
James Smart2e0fef82007-06-17 19:56:36 -05004533 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4534 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004535 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004536 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004537 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004538 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004539 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004540 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004541 int i;
dea31012005-04-17 16:05:31 -05004542
4543 icmd = &cmdiocb->iocb;
4544 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4545 lp = (uint32_t *) pcmd->virt;
4546
James Smart92d7f7b2007-06-17 19:56:38 -05004547 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4548 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004549 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004550 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4551 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004552 vport->fc_flag, payload_len, *lp,
4553 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004554
4555 /* Send an RSCN event to the management application */
4556 lpfc_send_rscn_event(vport, cmdiocb);
4557
James Smartd2873e42006-08-18 17:46:43 -04004558 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004559 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004560 FCH_EVT_RSCN, lp[i]);
4561
dea31012005-04-17 16:05:31 -05004562 /* If we are about to begin discovery, just ACC the RSCN.
4563 * Discovery processing will satisfy it.
4564 */
James Smart2e0fef82007-06-17 19:56:36 -05004565 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004566 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4567 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4568 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4569
James Smart51ef4c22007-08-02 11:10:31 -04004570 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004571 return 0;
dea31012005-04-17 16:05:31 -05004572 }
4573
James Smart92d7f7b2007-06-17 19:56:38 -05004574 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4575 * just ACC and ignore it.
4576 */
4577 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004578 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004579 i = payload_len;
4580 datap = lp;
4581 while (i > 0) {
4582 nportid = *datap++;
4583 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4584 i -= sizeof(uint32_t);
4585 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004586 if (lpfc_find_vport_by_did(phba, nportid))
4587 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004588 }
4589 if (rscn_id == hba_id) {
4590 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004591 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004592 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004593 "Data: x%x x%x x%x x%x\n",
4594 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004595 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004596 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4597 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4598 ndlp->nlp_DID, vport->port_state,
4599 ndlp->nlp_flag);
4600
James Smart92d7f7b2007-06-17 19:56:38 -05004601 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004602 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004603 return 0;
4604 }
4605 }
4606
James Smart7f5f3d02008-02-08 18:50:14 -05004607 spin_lock_irq(shost->host_lock);
4608 if (vport->fc_rscn_flush) {
4609 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004610 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004611 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004612 /* Send back ACC */
4613 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004614 return 0;
4615 }
4616 /* Indicate we are walking fc_rscn_id_list on this vport */
4617 vport->fc_rscn_flush = 1;
4618 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004619 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004620 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004621 /* If we are already processing an RSCN, save the received
4622 * RSCN payload buffer, cmdiocb->context2 to process later.
4623 */
James Smart2e0fef82007-06-17 19:56:36 -05004624 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004625 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4626 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4627 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4628
James Smart09372822008-01-11 01:52:54 -05004629 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004630 vport->fc_flag |= FC_RSCN_DEFERRED;
4631 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004632 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004633 vport->fc_flag |= FC_RSCN_MODE;
4634 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004635 if (rscn_cnt) {
4636 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4637 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4638 }
4639 if ((rscn_cnt) &&
4640 (payload_len + length <= LPFC_BPL_SIZE)) {
4641 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004642 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004643 memcpy(((uint8_t *)cmd) + length, lp,
4644 payload_len);
4645 } else {
4646 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4647 vport->fc_rscn_id_cnt++;
4648 /* If we zero, cmdiocb->context2, the calling
4649 * routine will not try to free it.
4650 */
4651 cmdiocb->context2 = NULL;
4652 }
dea31012005-04-17 16:05:31 -05004653 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004654 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4655 "0235 Deferred RSCN "
4656 "Data: x%x x%x x%x\n",
4657 vport->fc_rscn_id_cnt, vport->fc_flag,
4658 vport->port_state);
dea31012005-04-17 16:05:31 -05004659 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004660 vport->fc_flag |= FC_RSCN_DISCOVERY;
4661 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004662 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004663 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4664 "0234 ReDiscovery RSCN "
4665 "Data: x%x x%x x%x\n",
4666 vport->fc_rscn_id_cnt, vport->fc_flag,
4667 vport->port_state);
dea31012005-04-17 16:05:31 -05004668 }
James Smart7f5f3d02008-02-08 18:50:14 -05004669 /* Indicate we are done walking fc_rscn_id_list on this vport */
4670 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004671 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004672 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004673 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004674 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004675 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004676 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004677 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004678 return 0;
dea31012005-04-17 16:05:31 -05004679 }
James Smart858c9f62007-06-17 19:56:39 -05004680 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4681 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4682 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4683
James Smart2e0fef82007-06-17 19:56:36 -05004684 spin_lock_irq(shost->host_lock);
4685 vport->fc_flag |= FC_RSCN_MODE;
4686 spin_unlock_irq(shost->host_lock);
4687 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004688 /* Indicate we are done walking fc_rscn_id_list on this vport */
4689 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004690 /*
4691 * If we zero, cmdiocb->context2, the calling routine will
4692 * not try to free it.
4693 */
4694 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004695 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004696 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004697 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004698 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004699 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004700 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004701}
4702
James Smarte59058c2008-08-24 21:49:00 -04004703/**
James Smart3621a712009-04-06 18:47:14 -04004704 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004705 * @vport: pointer to a host virtual N_Port data structure.
4706 *
4707 * This routine handles the Registration State Configuration Notification
4708 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4709 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4710 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4711 * NameServer shall be issued. If CT command to the NameServer fails to be
4712 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4713 * RSCN activities with the @vport.
4714 *
4715 * Return code
4716 * 0 - Cleaned up rscn on the @vport
4717 * 1 - Wait for plogi to name server before proceed
4718 **/
dea31012005-04-17 16:05:31 -05004719int
James Smart2e0fef82007-06-17 19:56:36 -05004720lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004721{
4722 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004723 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004724
James Smart92d7f7b2007-06-17 19:56:38 -05004725 /* Ignore RSCN if the port is being torn down. */
4726 if (vport->load_flag & FC_UNLOADING) {
4727 lpfc_els_flush_rscn(vport);
4728 return 0;
4729 }
4730
dea31012005-04-17 16:05:31 -05004731 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004732 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004733
4734 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004735 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4736 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4737 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4738 vport->port_state);
dea31012005-04-17 16:05:31 -05004739
4740 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004741 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004742 vport->num_disc_nodes = 0;
4743
James Smart2e0fef82007-06-17 19:56:36 -05004744 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004745 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4746 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004747 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004748 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004749 /* Wait for NameServer query cmpl before we can
4750 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004751 return 1;
dea31012005-04-17 16:05:31 -05004752 } else {
4753 /* If login to NameServer does not exist, issue one */
4754 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004755 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004756 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004757 /* Wait for NameServer login cmpl before we can
4758 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004759 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004760
James Smarte47c9092008-02-08 18:49:26 -05004761 if (ndlp) {
4762 ndlp = lpfc_enable_node(vport, ndlp,
4763 NLP_STE_PLOGI_ISSUE);
4764 if (!ndlp) {
4765 lpfc_els_flush_rscn(vport);
4766 return 0;
4767 }
4768 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004769 } else {
James Smarte47c9092008-02-08 18:49:26 -05004770 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4771 if (!ndlp) {
4772 lpfc_els_flush_rscn(vport);
4773 return 0;
4774 }
James Smart2e0fef82007-06-17 19:56:36 -05004775 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004776 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004777 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004778 }
James Smarte47c9092008-02-08 18:49:26 -05004779 ndlp->nlp_type |= NLP_FABRIC;
4780 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4781 /* Wait for NameServer login cmpl before we can
4782 * continue
4783 */
4784 return 1;
dea31012005-04-17 16:05:31 -05004785 }
4786
James Smart2e0fef82007-06-17 19:56:36 -05004787 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004788 return 0;
dea31012005-04-17 16:05:31 -05004789}
4790
James Smarte59058c2008-08-24 21:49:00 -04004791/**
James Smart3621a712009-04-06 18:47:14 -04004792 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004793 * @vport: pointer to a host virtual N_Port data structure.
4794 * @cmdiocb: pointer to lpfc command iocb data structure.
4795 * @ndlp: pointer to a node-list data structure.
4796 *
4797 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4798 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4799 * point topology. As an unsolicited FLOGI should not be received in a loop
4800 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4801 * lpfc_check_sparm() routine is invoked to check the parameters in the
4802 * unsolicited FLOGI. If parameters validation failed, the routine
4803 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4804 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4805 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4806 * will initiate PLOGI. The higher lexicographical value party shall has
4807 * higher priority (as the winning port) and will initiate PLOGI and
4808 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4809 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4810 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4811 *
4812 * Return code
4813 * 0 - Successfully processed the unsolicited flogi
4814 * 1 - Failed to process the unsolicited flogi
4815 **/
dea31012005-04-17 16:05:31 -05004816static int
James Smart2e0fef82007-06-17 19:56:36 -05004817lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004818 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004819{
James Smart2e0fef82007-06-17 19:56:36 -05004820 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4821 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004822 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4823 uint32_t *lp = (uint32_t *) pcmd->virt;
4824 IOCB_t *icmd = &cmdiocb->iocb;
4825 struct serv_parm *sp;
4826 LPFC_MBOXQ_t *mbox;
4827 struct ls_rjt stat;
4828 uint32_t cmd, did;
4829 int rc;
4830
4831 cmd = *lp++;
4832 sp = (struct serv_parm *) lp;
4833
4834 /* FLOGI received */
4835
James Smart2e0fef82007-06-17 19:56:36 -05004836 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004837
James Smart76a95d72010-11-20 23:11:48 -05004838 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004839 /* We should never receive a FLOGI in loop mode, ignore it */
4840 did = icmd->un.elsreq64.remoteID;
4841
4842 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4843 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004844 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4845 "0113 An FLOGI ELS command x%x was "
4846 "received from DID x%x in Loop Mode\n",
4847 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004848 return 1;
dea31012005-04-17 16:05:31 -05004849 }
4850
4851 did = Fabric_DID;
4852
James Smart341af102010-01-26 23:07:37 -05004853 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004854 /* For a FLOGI we accept, then if our portname is greater
4855 * then the remote portname we initiate Nport login.
4856 */
4857
James Smart2e0fef82007-06-17 19:56:36 -05004858 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004859 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004860
4861 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004862 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4863 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004864 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004865
dea31012005-04-17 16:05:31 -05004866 lpfc_linkdown(phba);
4867 lpfc_init_link(phba, mbox,
4868 phba->cfg_topology,
4869 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004870 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004871 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004872 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004873 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004874 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004875 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004876 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004877 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004878 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004879 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004880 spin_lock_irq(shost->host_lock);
4881 vport->fc_flag |= FC_PT2PT_PLOGI;
4882 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004883 }
James Smart2e0fef82007-06-17 19:56:36 -05004884 spin_lock_irq(shost->host_lock);
4885 vport->fc_flag |= FC_PT2PT;
4886 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4887 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004888 } else {
4889 /* Reject this request because invalid parameters */
4890 stat.un.b.lsRjtRsvd0 = 0;
4891 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4892 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4893 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004894 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4895 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004896 return 1;
dea31012005-04-17 16:05:31 -05004897 }
4898
4899 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004900 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004901
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004902 return 0;
dea31012005-04-17 16:05:31 -05004903}
4904
James Smarte59058c2008-08-24 21:49:00 -04004905/**
James Smart3621a712009-04-06 18:47:14 -04004906 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004907 * @vport: pointer to a host virtual N_Port data structure.
4908 * @cmdiocb: pointer to lpfc command iocb data structure.
4909 * @ndlp: pointer to a node-list data structure.
4910 *
4911 * This routine processes Request Node Identification Data (RNID) IOCB
4912 * received as an ELS unsolicited event. Only when the RNID specified format
4913 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4914 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4915 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4916 * rejected by invoking the lpfc_els_rsp_reject() routine.
4917 *
4918 * Return code
4919 * 0 - Successfully processed rnid iocb (currently always return 0)
4920 **/
dea31012005-04-17 16:05:31 -05004921static int
James Smart2e0fef82007-06-17 19:56:36 -05004922lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4923 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004924{
4925 struct lpfc_dmabuf *pcmd;
4926 uint32_t *lp;
4927 IOCB_t *icmd;
4928 RNID *rn;
4929 struct ls_rjt stat;
4930 uint32_t cmd, did;
4931
4932 icmd = &cmdiocb->iocb;
4933 did = icmd->un.elsreq64.remoteID;
4934 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4935 lp = (uint32_t *) pcmd->virt;
4936
4937 cmd = *lp++;
4938 rn = (RNID *) lp;
4939
4940 /* RNID received */
4941
4942 switch (rn->Format) {
4943 case 0:
4944 case RNID_TOPOLOGY_DISC:
4945 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004946 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004947 break;
4948 default:
4949 /* Reject this request because format not supported */
4950 stat.un.b.lsRjtRsvd0 = 0;
4951 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4952 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4953 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004954 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4955 NULL);
dea31012005-04-17 16:05:31 -05004956 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004957 return 0;
dea31012005-04-17 16:05:31 -05004958}
4959
James Smarte59058c2008-08-24 21:49:00 -04004960/**
James Smart12265f62010-10-22 11:05:53 -04004961 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4962 * @vport: pointer to a host virtual N_Port data structure.
4963 * @cmdiocb: pointer to lpfc command iocb data structure.
4964 * @ndlp: pointer to a node-list data structure.
4965 *
4966 * Return code
4967 * 0 - Successfully processed echo iocb (currently always return 0)
4968 **/
4969static int
4970lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4971 struct lpfc_nodelist *ndlp)
4972{
4973 uint8_t *pcmd;
4974
4975 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4976
4977 /* skip over first word of echo command to find echo data */
4978 pcmd += sizeof(uint32_t);
4979
4980 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
4981 return 0;
4982}
4983
4984/**
James Smart3621a712009-04-06 18:47:14 -04004985 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004986 * @vport: pointer to a host virtual N_Port data structure.
4987 * @cmdiocb: pointer to lpfc command iocb data structure.
4988 * @ndlp: pointer to a node-list data structure.
4989 *
4990 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4991 * received as an ELS unsolicited event. Currently, this function just invokes
4992 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4993 *
4994 * Return code
4995 * 0 - Successfully processed lirr iocb (currently always return 0)
4996 **/
dea31012005-04-17 16:05:31 -05004997static int
James Smart2e0fef82007-06-17 19:56:36 -05004998lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4999 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005000{
5001 struct ls_rjt stat;
5002
5003 /* For now, unconditionally reject this command */
5004 stat.un.b.lsRjtRsvd0 = 0;
5005 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5006 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5007 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005008 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005009 return 0;
5010}
5011
James Smarte59058c2008-08-24 21:49:00 -04005012/**
James Smart5ffc2662009-11-18 15:39:44 -05005013 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5014 * @vport: pointer to a host virtual N_Port data structure.
5015 * @cmdiocb: pointer to lpfc command iocb data structure.
5016 * @ndlp: pointer to a node-list data structure.
5017 *
5018 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5019 * received as an ELS unsolicited event. A request to RRQ shall only
5020 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5021 * Nx_Port N_Port_ID of the target Exchange is the same as the
5022 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5023 * not accepted, an LS_RJT with reason code "Unable to perform
5024 * command request" and reason code explanation "Invalid Originator
5025 * S_ID" shall be returned. For now, we just unconditionally accept
5026 * RRQ from the target.
5027 **/
5028static void
5029lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5030 struct lpfc_nodelist *ndlp)
5031{
5032 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05005033 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5034 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05005035}
5036
5037/**
James Smart12265f62010-10-22 11:05:53 -04005038 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5039 * @phba: pointer to lpfc hba data structure.
5040 * @pmb: pointer to the driver internal queue element for mailbox command.
5041 *
5042 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5043 * mailbox command. This callback function is to actually send the Accept
5044 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5045 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5046 * mailbox command, constructs the RPS response with the link statistics
5047 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5048 * response to the RPS.
5049 *
5050 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5051 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5052 * will be stored into the context1 field of the IOCB for the completion
5053 * callback function to the RPS Accept Response ELS IOCB command.
5054 *
5055 **/
5056static void
5057lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5058{
5059 MAILBOX_t *mb;
5060 IOCB_t *icmd;
5061 struct RLS_RSP *rls_rsp;
5062 uint8_t *pcmd;
5063 struct lpfc_iocbq *elsiocb;
5064 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005065 uint16_t oxid;
5066 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04005067 uint32_t cmdsize;
5068
5069 mb = &pmb->u.mb;
5070
5071 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005072 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5073 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04005074 pmb->context1 = NULL;
5075 pmb->context2 = NULL;
5076
5077 if (mb->mbxStatus) {
5078 mempool_free(pmb, phba->mbox_mem_pool);
5079 return;
5080 }
5081
5082 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
5083 mempool_free(pmb, phba->mbox_mem_pool);
5084 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5085 lpfc_max_els_tries, ndlp,
5086 ndlp->nlp_DID, ELS_CMD_ACC);
5087
5088 /* Decrement the ndlp reference count from previous mbox command */
5089 lpfc_nlp_put(ndlp);
5090
5091 if (!elsiocb)
5092 return;
5093
5094 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005095 icmd->ulpContext = rxid;
5096 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04005097
5098 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5099 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5100 pcmd += sizeof(uint32_t); /* Skip past command */
5101 rls_rsp = (struct RLS_RSP *)pcmd;
5102
5103 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5104 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5105 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5106 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5107 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5108 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
5109
5110 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5111 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5112 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5113 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5114 elsiocb->iotag, elsiocb->iocb.ulpContext,
5115 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5116 ndlp->nlp_rpi);
5117 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5118 phba->fc_stat.elsXmitACC++;
5119 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5120 lpfc_els_free_iocb(phba, elsiocb);
5121}
5122
5123/**
James Smart3621a712009-04-06 18:47:14 -04005124 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005125 * @phba: pointer to lpfc hba data structure.
5126 * @pmb: pointer to the driver internal queue element for mailbox command.
5127 *
5128 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5129 * mailbox command. This callback function is to actually send the Accept
5130 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5131 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5132 * mailbox command, constructs the RPS response with the link statistics
5133 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5134 * response to the RPS.
5135 *
5136 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5137 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5138 * will be stored into the context1 field of the IOCB for the completion
5139 * callback function to the RPS Accept Response ELS IOCB command.
5140 *
5141 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005142static void
James Smart329f9bc2007-04-25 09:53:01 -04005143lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005144{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005145 MAILBOX_t *mb;
5146 IOCB_t *icmd;
5147 RPS_RSP *rps_rsp;
5148 uint8_t *pcmd;
5149 struct lpfc_iocbq *elsiocb;
5150 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005151 uint16_t status;
5152 uint16_t oxid;
5153 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005154 uint32_t cmdsize;
5155
James Smart04c68492009-05-22 14:52:52 -04005156 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005157
5158 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005159 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5160 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07005161 pmb->context1 = NULL;
5162 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005163
5164 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005165 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005166 return;
5167 }
5168
5169 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005170 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005171 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5172 lpfc_max_els_tries, ndlp,
5173 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005174
5175 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005176 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005177
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005178 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005179 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005180
5181 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005182 icmd->ulpContext = rxid;
5183 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005184
5185 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5186 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005187 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005188 rps_rsp = (RPS_RSP *)pcmd;
5189
James Smart76a95d72010-11-20 23:11:48 -05005190 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005191 status = 0x10;
5192 else
5193 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005194 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005195 status |= 0x4;
5196
5197 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005198 rps_rsp->portStatus = cpu_to_be16(status);
5199 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5200 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5201 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5202 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5203 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5204 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005205 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005206 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5207 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5208 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5209 elsiocb->iotag, elsiocb->iocb.ulpContext,
5210 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5211 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005212 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005213 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005214 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005215 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005216 return;
5217}
5218
James Smarte59058c2008-08-24 21:49:00 -04005219/**
James Smart12265f62010-10-22 11:05:53 -04005220 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5221 * @vport: pointer to a host virtual N_Port data structure.
5222 * @cmdiocb: pointer to lpfc command iocb data structure.
5223 * @ndlp: pointer to a node-list data structure.
5224 *
5225 * This routine processes Read Port Status (RPL) IOCB received as an
5226 * ELS unsolicited event. It first checks the remote port state. If the
5227 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5228 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5229 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5230 * for reading the HBA link statistics. It is for the callback function,
5231 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5232 * to actually sending out RPL Accept (ACC) response.
5233 *
5234 * Return codes
5235 * 0 - Successfully processed rls iocb (currently always return 0)
5236 **/
5237static int
5238lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5239 struct lpfc_nodelist *ndlp)
5240{
5241 struct lpfc_hba *phba = vport->phba;
5242 LPFC_MBOXQ_t *mbox;
5243 struct lpfc_dmabuf *pcmd;
5244 struct ls_rjt stat;
5245
5246 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5247 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5248 /* reject the unsolicited RPS request and done with it */
5249 goto reject_out;
5250
5251 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5252
5253 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5254 if (mbox) {
5255 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005256 mbox->context1 = (void *)((unsigned long)
5257 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5258 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04005259 mbox->context2 = lpfc_nlp_get(ndlp);
5260 mbox->vport = vport;
5261 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5262 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5263 != MBX_NOT_FINISHED)
5264 /* Mbox completion will send ELS Response */
5265 return 0;
5266 /* Decrement reference count used for the failed mbox
5267 * command.
5268 */
5269 lpfc_nlp_put(ndlp);
5270 mempool_free(mbox, phba->mbox_mem_pool);
5271 }
5272reject_out:
5273 /* issue rejection response */
5274 stat.un.b.lsRjtRsvd0 = 0;
5275 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5276 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5277 stat.un.b.vendorUnique = 0;
5278 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5279 return 0;
5280}
5281
5282/**
5283 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5284 * @vport: pointer to a host virtual N_Port data structure.
5285 * @cmdiocb: pointer to lpfc command iocb data structure.
5286 * @ndlp: pointer to a node-list data structure.
5287 *
5288 * This routine processes Read Timout Value (RTV) IOCB received as an
5289 * ELS unsolicited event. It first checks the remote port state. If the
5290 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5291 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5292 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5293 * Value (RTV) unsolicited IOCB event.
5294 *
5295 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5296 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5297 * will be stored into the context1 field of the IOCB for the completion
5298 * callback function to the RPS Accept Response ELS IOCB command.
5299 *
5300 * Return codes
5301 * 0 - Successfully processed rtv iocb (currently always return 0)
5302 **/
5303static int
5304lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5305 struct lpfc_nodelist *ndlp)
5306{
5307 struct lpfc_hba *phba = vport->phba;
5308 struct ls_rjt stat;
5309 struct RTV_RSP *rtv_rsp;
5310 uint8_t *pcmd;
5311 struct lpfc_iocbq *elsiocb;
5312 uint32_t cmdsize;
5313
5314
5315 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5316 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5317 /* reject the unsolicited RPS request and done with it */
5318 goto reject_out;
5319
5320 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5321 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5322 lpfc_max_els_tries, ndlp,
5323 ndlp->nlp_DID, ELS_CMD_ACC);
5324
5325 if (!elsiocb)
5326 return 1;
5327
5328 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5329 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5330 pcmd += sizeof(uint32_t); /* Skip past command */
5331
5332 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04005333 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
5334 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04005335
5336 rtv_rsp = (struct RTV_RSP *)pcmd;
5337
5338 /* populate RTV payload */
5339 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5340 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5341 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5342 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5343 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5344
5345 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5346 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5347 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5348 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5349 "Data: x%x x%x x%x\n",
5350 elsiocb->iotag, elsiocb->iocb.ulpContext,
5351 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5352 ndlp->nlp_rpi,
5353 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5354 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5355 phba->fc_stat.elsXmitACC++;
5356 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5357 lpfc_els_free_iocb(phba, elsiocb);
5358 return 0;
5359
5360reject_out:
5361 /* issue rejection response */
5362 stat.un.b.lsRjtRsvd0 = 0;
5363 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5364 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5365 stat.un.b.vendorUnique = 0;
5366 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5367 return 0;
5368}
5369
5370/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005371 * @vport: pointer to a host virtual N_Port data structure.
5372 * @cmdiocb: pointer to lpfc command iocb data structure.
5373 * @ndlp: pointer to a node-list data structure.
5374 *
5375 * This routine processes Read Port Status (RPS) IOCB received as an
5376 * ELS unsolicited event. It first checks the remote port state. If the
5377 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5378 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5379 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5380 * for reading the HBA link statistics. It is for the callback function,
5381 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5382 * to actually sending out RPS Accept (ACC) response.
5383 *
5384 * Return codes
5385 * 0 - Successfully processed rps iocb (currently always return 0)
5386 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005387static int
James Smart2e0fef82007-06-17 19:56:36 -05005388lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5389 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005390{
James Smart2e0fef82007-06-17 19:56:36 -05005391 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005392 uint32_t *lp;
5393 uint8_t flag;
5394 LPFC_MBOXQ_t *mbox;
5395 struct lpfc_dmabuf *pcmd;
5396 RPS *rps;
5397 struct ls_rjt stat;
5398
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005399 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005400 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5401 /* reject the unsolicited RPS request and done with it */
5402 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005403
5404 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5405 lp = (uint32_t *) pcmd->virt;
5406 flag = (be32_to_cpu(*lp++) & 0xf);
5407 rps = (RPS *) lp;
5408
5409 if ((flag == 0) ||
5410 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005411 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005412 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005413
James Smart92d7f7b2007-06-17 19:56:38 -05005414 printk("Fix me....\n");
5415 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005416 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5417 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005418 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005419 mbox->context1 = (void *)((unsigned long)
5420 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5421 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04005422 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005423 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005424 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005425 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005426 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005427 /* Mbox completion will send ELS Response */
5428 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005429 /* Decrement reference count used for the failed mbox
5430 * command.
5431 */
James Smart329f9bc2007-04-25 09:53:01 -04005432 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005433 mempool_free(mbox, phba->mbox_mem_pool);
5434 }
5435 }
James Smart90160e02008-08-24 21:49:45 -04005436
5437reject_out:
5438 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005439 stat.un.b.lsRjtRsvd0 = 0;
5440 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5441 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5442 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005443 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005444 return 0;
5445}
5446
James Smart19ca7602010-11-20 23:11:55 -05005447/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5448 * @vport: pointer to a host virtual N_Port data structure.
5449 * @ndlp: pointer to a node-list data structure.
5450 * @did: DID of the target.
5451 * @rrq: Pointer to the rrq struct.
5452 *
5453 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5454 * Successful the the completion handler will clear the RRQ.
5455 *
5456 * Return codes
5457 * 0 - Successfully sent rrq els iocb.
5458 * 1 - Failed to send rrq els iocb.
5459 **/
5460static int
5461lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5462 uint32_t did, struct lpfc_node_rrq *rrq)
5463{
5464 struct lpfc_hba *phba = vport->phba;
5465 struct RRQ *els_rrq;
5466 IOCB_t *icmd;
5467 struct lpfc_iocbq *elsiocb;
5468 uint8_t *pcmd;
5469 uint16_t cmdsize;
5470 int ret;
5471
5472
5473 if (ndlp != rrq->ndlp)
5474 ndlp = rrq->ndlp;
5475 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5476 return 1;
5477
5478 /* If ndlp is not NULL, we will bump the reference count on it */
5479 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5480 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5481 ELS_CMD_RRQ);
5482 if (!elsiocb)
5483 return 1;
5484
5485 icmd = &elsiocb->iocb;
5486 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5487
5488 /* For RRQ request, remainder of payload is Exchange IDs */
5489 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5490 pcmd += sizeof(uint32_t);
5491 els_rrq = (struct RRQ *) pcmd;
5492
5493 bf_set(rrq_oxid, els_rrq, rrq->xritag);
5494 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5495 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5496 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5497 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5498
5499
5500 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5501 "Issue RRQ: did:x%x",
5502 did, rrq->xritag, rrq->rxid);
5503 elsiocb->context_un.rrq = rrq;
5504 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5505 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5506
5507 if (ret == IOCB_ERROR) {
5508 lpfc_els_free_iocb(phba, elsiocb);
5509 return 1;
5510 }
5511 return 0;
5512}
5513
5514/**
5515 * lpfc_send_rrq - Sends ELS RRQ if needed.
5516 * @phba: pointer to lpfc hba data structure.
5517 * @rrq: pointer to the active rrq.
5518 *
5519 * This routine will call the lpfc_issue_els_rrq if the rrq is
5520 * still active for the xri. If this function returns a failure then
5521 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5522 *
5523 * Returns 0 Success.
5524 * 1 Failure.
5525 **/
5526int
5527lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5528{
5529 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5530 rrq->nlp_DID);
5531 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5532 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5533 rrq->nlp_DID, rrq);
5534 else
5535 return 1;
5536}
5537
James Smarte59058c2008-08-24 21:49:00 -04005538/**
James Smart3621a712009-04-06 18:47:14 -04005539 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005540 * @vport: pointer to a host virtual N_Port data structure.
5541 * @cmdsize: size of the ELS command.
5542 * @oldiocb: pointer to the original lpfc command iocb data structure.
5543 * @ndlp: pointer to a node-list data structure.
5544 *
5545 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5546 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5547 *
5548 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5549 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5550 * will be stored into the context1 field of the IOCB for the completion
5551 * callback function to the RPL Accept Response ELS command.
5552 *
5553 * Return code
5554 * 0 - Successfully issued ACC RPL ELS command
5555 * 1 - Failed to issue ACC RPL ELS command
5556 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005557static int
James Smart2e0fef82007-06-17 19:56:36 -05005558lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5559 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005560{
James Smart2e0fef82007-06-17 19:56:36 -05005561 struct lpfc_hba *phba = vport->phba;
5562 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005563 RPL_RSP rpl_rsp;
5564 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005565 uint8_t *pcmd;
5566
James Smart2e0fef82007-06-17 19:56:36 -05005567 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5568 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005569
James Smart488d1462006-03-07 15:02:37 -05005570 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005571 return 1;
James Smart488d1462006-03-07 15:02:37 -05005572
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005573 icmd = &elsiocb->iocb;
5574 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005575 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5576 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005577
5578 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5579 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005580 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005581 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5582 pcmd += sizeof(uint16_t);
5583
5584 /* Setup the RPL ACC payload */
5585 rpl_rsp.listLen = be32_to_cpu(1);
5586 rpl_rsp.index = 0;
5587 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005588 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5589 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005590 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005591 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005592 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005593 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5594 "0120 Xmit ELS RPL ACC response tag x%x "
5595 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5596 "rpi x%x\n",
5597 elsiocb->iotag, elsiocb->iocb.ulpContext,
5598 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5599 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005600 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005601 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005602 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5603 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005604 lpfc_els_free_iocb(phba, elsiocb);
5605 return 1;
5606 }
5607 return 0;
5608}
5609
James Smarte59058c2008-08-24 21:49:00 -04005610/**
James Smart3621a712009-04-06 18:47:14 -04005611 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005612 * @vport: pointer to a host virtual N_Port data structure.
5613 * @cmdiocb: pointer to lpfc command iocb data structure.
5614 * @ndlp: pointer to a node-list data structure.
5615 *
5616 * This routine processes Read Port List (RPL) IOCB received as an ELS
5617 * unsolicited event. It first checks the remote port state. If the remote
5618 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5619 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5620 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5621 * to accept the RPL.
5622 *
5623 * Return code
5624 * 0 - Successfully processed rpl iocb (currently always return 0)
5625 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005626static int
James Smart2e0fef82007-06-17 19:56:36 -05005627lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5628 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005629{
5630 struct lpfc_dmabuf *pcmd;
5631 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005632 uint32_t maxsize;
5633 uint16_t cmdsize;
5634 RPL *rpl;
5635 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005636
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005637 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5638 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005639 /* 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,
5645 NULL);
James Smart90160e02008-08-24 21:49:45 -04005646 /* rejected the unsolicited RPL request and done with it */
5647 return 0;
dea31012005-04-17 16:05:31 -05005648 }
5649
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005650 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5651 lp = (uint32_t *) pcmd->virt;
5652 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005653 maxsize = be32_to_cpu(rpl->maxsize);
5654
5655 /* We support only one port */
5656 if ((rpl->index == 0) &&
5657 ((maxsize == 0) ||
5658 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5659 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005660 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005661 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5662 }
James Smart2e0fef82007-06-17 19:56:36 -05005663 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005664
5665 return 0;
5666}
5667
James Smarte59058c2008-08-24 21:49:00 -04005668/**
James Smart3621a712009-04-06 18:47:14 -04005669 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005670 * @vport: pointer to a virtual N_Port data structure.
5671 * @cmdiocb: pointer to lpfc command iocb data structure.
5672 * @ndlp: pointer to a node-list data structure.
5673 *
5674 * This routine processes Fibre Channel Address Resolution Protocol
5675 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5676 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5677 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5678 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5679 * remote PortName is compared against the FC PortName stored in the @vport
5680 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5681 * compared against the FC NodeName stored in the @vport data structure.
5682 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5683 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5684 * invoked to send out FARP Response to the remote node. Before sending the
5685 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5686 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5687 * routine is invoked to log into the remote port first.
5688 *
5689 * Return code
5690 * 0 - Either the FARP Match Mode not supported or successfully processed
5691 **/
dea31012005-04-17 16:05:31 -05005692static int
James Smart2e0fef82007-06-17 19:56:36 -05005693lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5694 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005695{
5696 struct lpfc_dmabuf *pcmd;
5697 uint32_t *lp;
5698 IOCB_t *icmd;
5699 FARP *fp;
5700 uint32_t cmd, cnt, did;
5701
5702 icmd = &cmdiocb->iocb;
5703 did = icmd->un.elsreq64.remoteID;
5704 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5705 lp = (uint32_t *) pcmd->virt;
5706
5707 cmd = *lp++;
5708 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005709 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005710 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5711 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005712 /* We will only support match on WWPN or WWNN */
5713 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005714 return 0;
dea31012005-04-17 16:05:31 -05005715 }
5716
5717 cnt = 0;
5718 /* If this FARP command is searching for my portname */
5719 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005720 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005721 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005722 cnt = 1;
5723 }
5724
5725 /* If this FARP command is searching for my nodename */
5726 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005727 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005728 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005729 cnt = 1;
5730 }
5731
5732 if (cnt) {
5733 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5734 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5735 /* Log back into the node before sending the FARP. */
5736 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005737 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005738 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005739 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005740 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005741 }
5742
5743 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005744 if (fp->Rflags & FARP_REQUEST_FARPR)
5745 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005746 }
5747 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005748 return 0;
dea31012005-04-17 16:05:31 -05005749}
5750
James Smarte59058c2008-08-24 21:49:00 -04005751/**
James Smart3621a712009-04-06 18:47:14 -04005752 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005753 * @vport: pointer to a host virtual N_Port data structure.
5754 * @cmdiocb: pointer to lpfc command iocb data structure.
5755 * @ndlp: pointer to a node-list data structure.
5756 *
5757 * This routine processes Fibre Channel Address Resolution Protocol
5758 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5759 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5760 * the FARP response request.
5761 *
5762 * Return code
5763 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5764 **/
dea31012005-04-17 16:05:31 -05005765static int
James Smart2e0fef82007-06-17 19:56:36 -05005766lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5767 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005768{
5769 struct lpfc_dmabuf *pcmd;
5770 uint32_t *lp;
5771 IOCB_t *icmd;
5772 uint32_t cmd, did;
5773
5774 icmd = &cmdiocb->iocb;
5775 did = icmd->un.elsreq64.remoteID;
5776 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5777 lp = (uint32_t *) pcmd->virt;
5778
5779 cmd = *lp++;
5780 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005781 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5782 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005783 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005784 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005785
5786 return 0;
5787}
5788
James Smarte59058c2008-08-24 21:49:00 -04005789/**
James Smart3621a712009-04-06 18:47:14 -04005790 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005791 * @vport: pointer to a host virtual N_Port data structure.
5792 * @cmdiocb: pointer to lpfc command iocb data structure.
5793 * @fan_ndlp: pointer to a node-list data structure.
5794 *
5795 * This routine processes a Fabric Address Notification (FAN) IOCB
5796 * command received as an ELS unsolicited event. The FAN ELS command will
5797 * only be processed on a physical port (i.e., the @vport represents the
5798 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5799 * compared against those in the phba data structure. If any of those is
5800 * different, the lpfc_initial_flogi() routine is invoked to initialize
5801 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5802 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5803 * is invoked to register login to the fabric.
5804 *
5805 * Return code
5806 * 0 - Successfully processed fan iocb (currently always return 0).
5807 **/
dea31012005-04-17 16:05:31 -05005808static int
James Smart2e0fef82007-06-17 19:56:36 -05005809lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5810 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005811{
James Smart2e0fef82007-06-17 19:56:36 -05005812 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005813 uint32_t *lp;
5814 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005815
James Smart0d2b6b82008-06-14 22:52:47 -04005816 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5817 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5818 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005819 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005820 if ((vport == phba->pport) &&
5821 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005822 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005823 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005824 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005825 sizeof(struct lpfc_name)))) {
5826 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05005827 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005828 } else {
5829 /* FAN verified - skip FLOGI */
5830 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005831 if (phba->sli_rev < LPFC_SLI_REV4)
5832 lpfc_issue_fabric_reglogin(vport);
5833 else
5834 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005835 }
dea31012005-04-17 16:05:31 -05005836 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005837 return 0;
dea31012005-04-17 16:05:31 -05005838}
5839
James Smarte59058c2008-08-24 21:49:00 -04005840/**
James Smart3621a712009-04-06 18:47:14 -04005841 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005842 * @ptr: holder for the timer function associated data.
5843 *
5844 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5845 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5846 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5847 * up the worker thread. It is for the worker thread to invoke the routine
5848 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5849 **/
dea31012005-04-17 16:05:31 -05005850void
5851lpfc_els_timeout(unsigned long ptr)
5852{
James Smart2e0fef82007-06-17 19:56:36 -05005853 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5854 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005855 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005856 unsigned long iflag;
5857
James Smart2e0fef82007-06-17 19:56:36 -05005858 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005859 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5860 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005861 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005862 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005863
James Smart5e9d9b82008-06-14 22:52:53 -04005864 if (!tmo_posted)
5865 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005866 return;
5867}
5868
James Smart2a9bf3d2010-06-07 15:24:45 -04005869
James Smarte59058c2008-08-24 21:49:00 -04005870/**
James Smart3621a712009-04-06 18:47:14 -04005871 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005872 * @vport: pointer to a virtual N_Port data structure.
5873 *
5874 * This routine is the actual handler function that processes an ELS timeout
5875 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5876 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5877 * invoking the lpfc_sli_issue_abort_iotag() routine.
5878 **/
dea31012005-04-17 16:05:31 -05005879void
James Smart2e0fef82007-06-17 19:56:36 -05005880lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005881{
James Smart2e0fef82007-06-17 19:56:36 -05005882 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005883 struct lpfc_sli_ring *pring;
5884 struct lpfc_iocbq *tmp_iocb, *piocb;
5885 IOCB_t *cmd = NULL;
5886 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005887 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005888 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005889 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005890 LIST_HEAD(txcmplq_completions);
5891 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005892
James Smart2a9bf3d2010-06-07 15:24:45 -04005893
dea31012005-04-17 16:05:31 -05005894 timeout = (uint32_t)(phba->fc_ratov << 1);
5895
5896 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005897
James Smart2a9bf3d2010-06-07 15:24:45 -04005898 spin_lock_irq(&phba->hbalock);
5899 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5900 spin_unlock_irq(&phba->hbalock);
5901
5902 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005903 cmd = &piocb->iocb;
5904
James Smart2e0fef82007-06-17 19:56:36 -05005905 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5906 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5907 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005908 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005909
5910 if (piocb->vport != vport)
5911 continue;
5912
dea31012005-04-17 16:05:31 -05005913 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005914 if (pcmd)
5915 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005916
James Smart92d7f7b2007-06-17 19:56:38 -05005917 if (els_command == ELS_CMD_FARP ||
5918 els_command == ELS_CMD_FARPR ||
5919 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005920 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005921
dea31012005-04-17 16:05:31 -05005922 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005923 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005924 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005925 else
dea31012005-04-17 16:05:31 -05005926 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005927 continue;
5928 }
5929
James Smart2e0fef82007-06-17 19:56:36 -05005930 remote_ID = 0xffffffff;
5931 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005932 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005933 else {
5934 struct lpfc_nodelist *ndlp;
5935 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005936 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005937 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005938 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005939 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05005940 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005941 spin_lock_irq(&phba->hbalock);
5942 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05005943 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005944
James Smart2a9bf3d2010-06-07 15:24:45 -04005945 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5946 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5947 "0127 ELS timeout Data: x%x x%x x%x "
5948 "x%x\n", els_command,
5949 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5950 spin_lock_irq(&phba->hbalock);
5951 list_del_init(&piocb->dlist);
5952 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5953 spin_unlock_irq(&phba->hbalock);
5954 }
5955
James Smart2e0fef82007-06-17 19:56:36 -05005956 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5957 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005958}
5959
James Smarte59058c2008-08-24 21:49:00 -04005960/**
James Smart3621a712009-04-06 18:47:14 -04005961 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005962 * @vport: pointer to a host virtual N_Port data structure.
5963 *
5964 * This routine is used to clean up all the outstanding ELS commands on a
5965 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5966 * routine. After that, it walks the ELS transmit queue to remove all the
5967 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5968 * the IOCBs with a non-NULL completion callback function, the callback
5969 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5970 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5971 * callback function, the IOCB will simply be released. Finally, it walks
5972 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5973 * completion queue IOCB that is associated with the @vport and is not
5974 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5975 * part of the discovery state machine) out to HBA by invoking the
5976 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5977 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5978 * the IOCBs are aborted when this function returns.
5979 **/
dea31012005-04-17 16:05:31 -05005980void
James Smart2e0fef82007-06-17 19:56:36 -05005981lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005982{
James Smart2534ba72007-04-25 09:52:20 -04005983 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005984 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005985 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005986 struct lpfc_iocbq *tmp_iocb, *piocb;
5987 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005988
5989 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005990
James Smart2e0fef82007-06-17 19:56:36 -05005991 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005992 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5993 cmd = &piocb->iocb;
5994
5995 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5996 continue;
5997 }
5998
5999 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04006000 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6001 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6002 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6003 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05006004 continue;
dea31012005-04-17 16:05:31 -05006005
James Smart2e0fef82007-06-17 19:56:36 -05006006 if (piocb->vport != vport)
6007 continue;
6008
James Smart2534ba72007-04-25 09:52:20 -04006009 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04006010 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05006011 }
6012
6013 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05006014 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6015 continue;
6016 }
dea31012005-04-17 16:05:31 -05006017
James Smart2e0fef82007-06-17 19:56:36 -05006018 if (piocb->vport != vport)
6019 continue;
6020
James Smart07951072007-04-25 09:51:38 -04006021 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05006022 }
James Smart2e0fef82007-06-17 19:56:36 -05006023 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04006024
James Smarta257bf92009-04-06 18:48:10 -04006025 /* Cancell all the IOCBs from the completions list */
6026 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6027 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04006028
dea31012005-04-17 16:05:31 -05006029 return;
6030}
6031
James Smarte59058c2008-08-24 21:49:00 -04006032/**
James Smart3621a712009-04-06 18:47:14 -04006033 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04006034 * @phba: pointer to lpfc hba data structure.
6035 *
6036 * This routine is used to clean up all the outstanding ELS commands on a
6037 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6038 * routine. After that, it walks the ELS transmit queue to remove all the
6039 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6040 * the IOCBs with the completion callback function associated, the callback
6041 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6042 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6043 * callback function associated, the IOCB will simply be released. Finally,
6044 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6045 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6046 * management plane IOCBs that are not part of the discovery state machine)
6047 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6048 **/
James Smart549e55c2007-08-02 11:09:51 -04006049void
6050lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6051{
6052 LIST_HEAD(completions);
6053 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6054 struct lpfc_iocbq *tmp_iocb, *piocb;
6055 IOCB_t *cmd = NULL;
6056
6057 lpfc_fabric_abort_hba(phba);
6058 spin_lock_irq(&phba->hbalock);
6059 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6060 cmd = &piocb->iocb;
6061 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6062 continue;
6063 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6064 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6065 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6066 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6067 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6068 continue;
6069 list_move_tail(&piocb->list, &completions);
6070 pring->txq_cnt--;
6071 }
6072 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6073 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6074 continue;
6075 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6076 }
6077 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04006078
6079 /* Cancel all the IOCBs from the completions list */
6080 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6081 IOERR_SLI_ABORTED);
6082
James Smart549e55c2007-08-02 11:09:51 -04006083 return;
6084}
6085
James Smarte59058c2008-08-24 21:49:00 -04006086/**
James Smart3621a712009-04-06 18:47:14 -04006087 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04006088 * @phba: Pointer to hba context object.
6089 * @cmdiocbp: Pointer to command iocb which reported error.
6090 * @rspiocbp: Pointer to response iocb which reported error.
6091 *
6092 * This function sends an event when there is an ELS command
6093 * failure.
6094 **/
6095void
6096lpfc_send_els_failure_event(struct lpfc_hba *phba,
6097 struct lpfc_iocbq *cmdiocbp,
6098 struct lpfc_iocbq *rspiocbp)
6099{
6100 struct lpfc_vport *vport = cmdiocbp->vport;
6101 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6102 struct lpfc_lsrjt_event lsrjt_event;
6103 struct lpfc_fabric_event_header fabric_event;
6104 struct ls_rjt stat;
6105 struct lpfc_nodelist *ndlp;
6106 uint32_t *pcmd;
6107
6108 ndlp = cmdiocbp->context1;
6109 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6110 return;
6111
6112 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6113 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6114 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6115 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6116 sizeof(struct lpfc_name));
6117 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6118 sizeof(struct lpfc_name));
6119 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6120 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006121 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006122 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6123 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6124 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6125 fc_host_post_vendor_event(shost,
6126 fc_get_event_number(),
6127 sizeof(lsrjt_event),
6128 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006129 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006130 return;
6131 }
6132 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6133 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6134 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6135 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6136 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6137 else
6138 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6139 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6140 sizeof(struct lpfc_name));
6141 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6142 sizeof(struct lpfc_name));
6143 fc_host_post_vendor_event(shost,
6144 fc_get_event_number(),
6145 sizeof(fabric_event),
6146 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006147 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006148 return;
6149 }
6150
6151}
6152
6153/**
James Smart3621a712009-04-06 18:47:14 -04006154 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006155 * @vport: Pointer to vport object.
6156 * @ndlp: Pointer FC node object.
6157 * @cmd: ELS command code.
6158 *
6159 * This function posts an event when there is an incoming
6160 * unsolicited ELS command.
6161 **/
6162static void
6163lpfc_send_els_event(struct lpfc_vport *vport,
6164 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006165 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006166{
James Smartddcc50f2008-12-04 22:38:46 -05006167 struct lpfc_els_event_header *els_data = NULL;
6168 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006169 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6170
James Smartddcc50f2008-12-04 22:38:46 -05006171 if (*payload == ELS_CMD_LOGO) {
6172 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6173 if (!logo_data) {
6174 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6175 "0148 Failed to allocate memory "
6176 "for LOGO event\n");
6177 return;
6178 }
6179 els_data = &logo_data->header;
6180 } else {
6181 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6182 GFP_KERNEL);
6183 if (!els_data) {
6184 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6185 "0149 Failed to allocate memory "
6186 "for ELS event\n");
6187 return;
6188 }
6189 }
6190 els_data->event_type = FC_REG_ELS_EVENT;
6191 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006192 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006193 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006194 break;
6195 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006196 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006197 break;
6198 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006199 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6200 break;
6201 case ELS_CMD_LOGO:
6202 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6203 /* Copy the WWPN in the LOGO payload */
6204 memcpy(logo_data->logo_wwpn, &payload[2],
6205 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006206 break;
6207 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006208 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006209 return;
6210 }
James Smartddcc50f2008-12-04 22:38:46 -05006211 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6212 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6213 if (*payload == ELS_CMD_LOGO) {
6214 fc_host_post_vendor_event(shost,
6215 fc_get_event_number(),
6216 sizeof(struct lpfc_logo_event),
6217 (char *)logo_data,
6218 LPFC_NL_VENDOR_ID);
6219 kfree(logo_data);
6220 } else {
6221 fc_host_post_vendor_event(shost,
6222 fc_get_event_number(),
6223 sizeof(struct lpfc_els_event_header),
6224 (char *)els_data,
6225 LPFC_NL_VENDOR_ID);
6226 kfree(els_data);
6227 }
James Smartea2151b2008-09-07 11:52:10 -04006228
6229 return;
6230}
6231
6232
6233/**
James Smart3621a712009-04-06 18:47:14 -04006234 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006235 * @phba: pointer to lpfc hba data structure.
6236 * @pring: pointer to a SLI ring.
6237 * @vport: pointer to a host virtual N_Port data structure.
6238 * @elsiocb: pointer to lpfc els command iocb data structure.
6239 *
6240 * This routine is used for processing the IOCB associated with a unsolicited
6241 * event. It first determines whether there is an existing ndlp that matches
6242 * the DID from the unsolicited IOCB. If not, it will create a new one with
6243 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6244 * IOCB is then used to invoke the proper routine and to set up proper state
6245 * of the discovery state machine.
6246 **/
James Smarted957682007-06-17 19:56:37 -05006247static void
6248lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006249 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006250{
James Smart87af33f2007-10-27 13:37:43 -04006251 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006252 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006253 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006254 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05006255 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006256 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006257
James Smarte47c9092008-02-08 18:49:26 -05006258 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006259 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006260
dea31012005-04-17 16:05:31 -05006261 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006262 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6263 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006264 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006265 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006266
James Smart858c9f62007-06-17 19:56:39 -05006267 did = icmd->un.rcvels.remoteID;
6268 if (icmd->ulpStatus) {
6269 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6270 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6271 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006272 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006273 }
dea31012005-04-17 16:05:31 -05006274
6275 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006276 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006277 goto dropit;
dea31012005-04-17 16:05:31 -05006278
James Smartc8685952009-11-18 15:39:16 -05006279 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006280 if (vport->load_flag & FC_UNLOADING)
6281 goto dropit;
6282
James Smart92494142011-02-16 12:39:44 -05006283 /* If NPort discovery is delayed drop incoming ELS */
6284 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6285 (cmd != ELS_CMD_PLOGI))
6286 goto dropit;
6287
James Smart2e0fef82007-06-17 19:56:36 -05006288 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006289 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006290 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006291 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006292 if (!ndlp)
dea31012005-04-17 16:05:31 -05006293 goto dropit;
dea31012005-04-17 16:05:31 -05006294
James Smart2e0fef82007-06-17 19:56:36 -05006295 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006296 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006297 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006298 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006299 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006300 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6301 ndlp = lpfc_enable_node(vport, ndlp,
6302 NLP_STE_UNUSED_NODE);
6303 if (!ndlp)
6304 goto dropit;
6305 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6306 newnode = 1;
6307 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6308 ndlp->nlp_type |= NLP_FABRIC;
6309 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6310 /* This is similar to the new node path */
6311 ndlp = lpfc_nlp_get(ndlp);
6312 if (!ndlp)
6313 goto dropit;
6314 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6315 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006316 }
dea31012005-04-17 16:05:31 -05006317
6318 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006319
James Smart329f9bc2007-04-25 09:53:01 -04006320 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006321 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006322
6323 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6324 cmd &= ELS_CMD_MASK;
6325 }
6326 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006327 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6328 "0112 ELS command x%x received from NPORT x%x "
6329 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006330 switch (cmd) {
6331 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006332 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6333 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6334 did, vport->port_state, ndlp->nlp_flag);
6335
dea31012005-04-17 16:05:31 -05006336 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006337 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6338
James Smartddcc50f2008-12-04 22:38:46 -05006339 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05006340
6341 /* If Nport discovery is delayed, reject PLOGIs */
6342 if (vport->fc_flag & FC_DISC_DELAYED) {
6343 rjt_err = LSRJT_UNABLE_TPC;
6344 break;
6345 }
James Smart858c9f62007-06-17 19:56:39 -05006346 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006347 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6348 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6349 rjt_err = LSRJT_UNABLE_TPC;
6350 break;
6351 }
6352 /* We get here, and drop thru, if we are PT2PT with
6353 * another NPort and the other side has initiated
6354 * the PLOGI before responding to our FLOGI.
6355 */
dea31012005-04-17 16:05:31 -05006356 }
James Smart87af33f2007-10-27 13:37:43 -04006357
6358 shost = lpfc_shost_from_vport(vport);
6359 spin_lock_irq(shost->host_lock);
6360 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6361 spin_unlock_irq(shost->host_lock);
6362
James Smart2e0fef82007-06-17 19:56:36 -05006363 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6364 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006365
dea31012005-04-17 16:05:31 -05006366 break;
6367 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006368 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6369 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6370 did, vport->port_state, ndlp->nlp_flag);
6371
dea31012005-04-17 16:05:31 -05006372 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006373 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006374 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006375 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006376 break;
6377 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006378 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6379 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6380 did, vport->port_state, ndlp->nlp_flag);
6381
dea31012005-04-17 16:05:31 -05006382 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006383 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006384 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006385 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006386 break;
6387 }
James Smart2e0fef82007-06-17 19:56:36 -05006388 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006389 break;
6390 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006391 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6392 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6393 did, vport->port_state, ndlp->nlp_flag);
6394
dea31012005-04-17 16:05:31 -05006395 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006396 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006397 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006398 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006399 break;
6400 }
James Smart2e0fef82007-06-17 19:56:36 -05006401 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006402 break;
6403 case ELS_CMD_RSCN:
6404 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006405 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006406 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006407 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006408 break;
6409 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006410 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6411 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6412 did, vport->port_state, ndlp->nlp_flag);
6413
James Smartddcc50f2008-12-04 22:38:46 -05006414 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006415 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006416 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006417 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006418 break;
6419 }
James Smart2e0fef82007-06-17 19:56:36 -05006420 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6421 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006422 break;
6423 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006424 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6425 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6426 did, vport->port_state, ndlp->nlp_flag);
6427
dea31012005-04-17 16:05:31 -05006428 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006429 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006430 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006431 break;
6432 }
James Smart2e0fef82007-06-17 19:56:36 -05006433 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6434 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006435 break;
6436 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006437 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6438 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6439 did, vport->port_state, ndlp->nlp_flag);
6440
dea31012005-04-17 16:05:31 -05006441 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006442 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006443 break;
6444 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006445 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6446 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6447 did, vport->port_state, ndlp->nlp_flag);
6448
dea31012005-04-17 16:05:31 -05006449 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006450 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006451 break;
6452 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006453 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6454 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6455 did, vport->port_state, ndlp->nlp_flag);
6456
dea31012005-04-17 16:05:31 -05006457 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006458 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006459 break;
dea31012005-04-17 16:05:31 -05006460 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006461 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6462 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6463 did, vport->port_state, ndlp->nlp_flag);
6464
dea31012005-04-17 16:05:31 -05006465 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006466 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006467 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006468 break;
6469 }
James Smart2e0fef82007-06-17 19:56:36 -05006470 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006471 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006472 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006473 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6474 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6475 did, vport->port_state, ndlp->nlp_flag);
6476
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006477 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006478 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006479 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006480 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006481 break;
James Smart12265f62010-10-22 11:05:53 -04006482 case ELS_CMD_RLS:
6483 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6484 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6485 did, vport->port_state, ndlp->nlp_flag);
6486
6487 phba->fc_stat.elsRcvRLS++;
6488 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6489 if (newnode)
6490 lpfc_nlp_put(ndlp);
6491 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006492 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006493 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6494 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6495 did, vport->port_state, ndlp->nlp_flag);
6496
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006497 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006498 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006499 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006500 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006501 break;
6502 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006503 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6504 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6505 did, vport->port_state, ndlp->nlp_flag);
6506
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006507 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006508 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006509 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006510 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006511 break;
dea31012005-04-17 16:05:31 -05006512 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006513 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6514 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6515 did, vport->port_state, ndlp->nlp_flag);
6516
dea31012005-04-17 16:05:31 -05006517 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006518 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006519 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006520 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006521 break;
James Smart12265f62010-10-22 11:05:53 -04006522 case ELS_CMD_RTV:
6523 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6524 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6525 did, vport->port_state, ndlp->nlp_flag);
6526 phba->fc_stat.elsRcvRTV++;
6527 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6528 if (newnode)
6529 lpfc_nlp_put(ndlp);
6530 break;
James Smart5ffc2662009-11-18 15:39:44 -05006531 case ELS_CMD_RRQ:
6532 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6533 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6534 did, vport->port_state, ndlp->nlp_flag);
6535
6536 phba->fc_stat.elsRcvRRQ++;
6537 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6538 if (newnode)
6539 lpfc_nlp_put(ndlp);
6540 break;
James Smart12265f62010-10-22 11:05:53 -04006541 case ELS_CMD_ECHO:
6542 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6543 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6544 did, vport->port_state, ndlp->nlp_flag);
6545
6546 phba->fc_stat.elsRcvECHO++;
6547 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6548 if (newnode)
6549 lpfc_nlp_put(ndlp);
6550 break;
dea31012005-04-17 16:05:31 -05006551 default:
James Smart858c9f62007-06-17 19:56:39 -05006552 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6553 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6554 cmd, did, vport->port_state);
6555
dea31012005-04-17 16:05:31 -05006556 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006557 rjt_err = LSRJT_CMD_UNSUPPORTED;
dea31012005-04-17 16:05:31 -05006558
6559 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006560 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6561 "0115 Unknown ELS command x%x "
6562 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006563 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006564 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006565 break;
6566 }
6567
6568 /* check if need to LS_RJT received ELS cmd */
6569 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006570 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006571 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006572 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006573 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6574 NULL);
dea31012005-04-17 16:05:31 -05006575 }
6576
James Smartd7c255b2008-08-24 21:50:00 -04006577 lpfc_nlp_put(elsiocb->context1);
6578 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006579 return;
6580
6581dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006582 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006583 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6584 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006585 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006586 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006587 phba->fc_stat.elsRcvDrop++;
6588}
6589
James Smarte59058c2008-08-24 21:49:00 -04006590/**
James Smart3621a712009-04-06 18:47:14 -04006591 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04006592 * @phba: pointer to lpfc hba data structure.
6593 * @vpi: host virtual N_Port identifier.
6594 *
6595 * This routine finds a vport on a HBA (referred by @phba) through a
6596 * @vpi. The function walks the HBA's vport list and returns the address
6597 * of the vport with the matching @vpi.
6598 *
6599 * Return code
6600 * NULL - No vport with the matching @vpi found
6601 * Otherwise - Address to the vport with the matching @vpi.
6602 **/
James Smart6669f9b2009-10-02 15:16:45 -04006603struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05006604lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6605{
6606 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04006607 unsigned long flags;
James Smart5248a742011-07-22 18:37:06 -04006608 int i = 0;
James Smart6d368e52011-05-24 11:44:12 -04006609
6610 /* The physical ports are always vpi 0 - translate is unnecessary. */
6611 if (vpi > 0) {
6612 /*
6613 * Translate the physical vpi to the logical vpi. The
6614 * vport stores the logical vpi.
6615 */
6616 for (i = 0; i < phba->max_vpi; i++) {
6617 if (vpi == phba->vpi_ids[i])
6618 break;
6619 }
6620
6621 if (i >= phba->max_vpi) {
6622 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
6623 "2936 Could not find Vport mapped "
6624 "to vpi %d\n", vpi);
6625 return NULL;
6626 }
6627 }
James Smart92d7f7b2007-06-17 19:56:38 -05006628
James Smart549e55c2007-08-02 11:09:51 -04006629 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006630 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart5248a742011-07-22 18:37:06 -04006631 if (vport->vpi == i) {
James Smart549e55c2007-08-02 11:09:51 -04006632 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006633 return vport;
James Smart549e55c2007-08-02 11:09:51 -04006634 }
James Smart92d7f7b2007-06-17 19:56:38 -05006635 }
James Smart549e55c2007-08-02 11:09:51 -04006636 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006637 return NULL;
6638}
James Smarted957682007-06-17 19:56:37 -05006639
James Smarte59058c2008-08-24 21:49:00 -04006640/**
James Smart3621a712009-04-06 18:47:14 -04006641 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006642 * @phba: pointer to lpfc hba data structure.
6643 * @pring: pointer to a SLI ring.
6644 * @elsiocb: pointer to lpfc els iocb data structure.
6645 *
6646 * This routine is used to process an unsolicited event received from a SLI
6647 * (Service Level Interface) ring. The actual processing of the data buffer
6648 * associated with the unsolicited event is done by invoking the routine
6649 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6650 * SLI ring on which the unsolicited event was received.
6651 **/
James Smarted957682007-06-17 19:56:37 -05006652void
6653lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6654 struct lpfc_iocbq *elsiocb)
6655{
6656 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006657 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006658 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006659 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6660 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006661
James Smartd7c255b2008-08-24 21:50:00 -04006662 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006663 elsiocb->context2 = NULL;
6664 elsiocb->context3 = NULL;
6665
6666 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6667 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6668 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6669 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006670 phba->fc_stat.NoRcvBuf++;
6671 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006672 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006673 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006674 return;
6675 }
6676
James Smart92d7f7b2007-06-17 19:56:38 -05006677 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6678 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6679 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6680 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6681 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006682 else
6683 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04006684 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05006685 }
James Smart6d368e52011-05-24 11:44:12 -04006686
James Smart7f5f3d02008-02-08 18:50:14 -05006687 /* If there are no BDEs associated
6688 * with this IOCB, there is nothing to do.
6689 */
James Smarted957682007-06-17 19:56:37 -05006690 if (icmd->ulpBdeCount == 0)
6691 return;
6692
James Smart7f5f3d02008-02-08 18:50:14 -05006693 /* type of ELS cmd is first 32bit word
6694 * in packet
6695 */
James Smarted957682007-06-17 19:56:37 -05006696 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006697 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006698 } else {
6699 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6700 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006701 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6702 paddr);
James Smarted957682007-06-17 19:56:37 -05006703 }
6704
James Smart92d7f7b2007-06-17 19:56:38 -05006705 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6706 /*
6707 * The different unsolicited event handlers would tell us
6708 * if they are done with "mp" by setting context2 to NULL.
6709 */
dea31012005-04-17 16:05:31 -05006710 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006711 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6712 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006713 }
James Smarted957682007-06-17 19:56:37 -05006714
6715 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006716 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006717 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006718 elsiocb->context2 = bdeBuf2;
6719 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006720 /* free mp if we are done with it */
6721 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006722 lpfc_in_buf_free(phba, elsiocb->context2);
6723 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006724 }
dea31012005-04-17 16:05:31 -05006725 }
dea31012005-04-17 16:05:31 -05006726}
James Smart92d7f7b2007-06-17 19:56:38 -05006727
James Smarte59058c2008-08-24 21:49:00 -04006728/**
James Smart3621a712009-04-06 18:47:14 -04006729 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006730 * @phba: pointer to lpfc hba data structure.
6731 * @vport: pointer to a virtual N_Port data structure.
6732 *
6733 * This routine issues a Port Login (PLOGI) to the Name Server with
6734 * State Change Request (SCR) for a @vport. This routine will create an
6735 * ndlp for the Name Server associated to the @vport if such node does
6736 * not already exist. The PLOGI to Name Server is issued by invoking the
6737 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6738 * (FDMI) is configured to the @vport, a FDMI node will be created and
6739 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6740 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006741void
6742lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6743{
6744 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05006745 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6746
6747 /*
6748 * If lpfc_delay_discovery parameter is set and the clean address
6749 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6750 * discovery.
6751 */
6752 spin_lock_irq(shost->host_lock);
6753 if (vport->fc_flag & FC_DISC_DELAYED) {
6754 spin_unlock_irq(shost->host_lock);
6755 mod_timer(&vport->delayed_disc_tmo,
6756 jiffies + HZ * phba->fc_ratov);
6757 return;
6758 }
6759 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006760
6761 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6762 if (!ndlp) {
6763 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6764 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006765 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05006766 lpfc_disc_start(vport);
6767 return;
6768 }
6769 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006770 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6771 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006772 return;
6773 }
6774 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006775 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6776 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6777 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006778 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05006779 lpfc_disc_start(vport);
6780 return;
6781 }
6782 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6783 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6784 "0348 NameServer login: node freed\n");
6785 return;
6786 }
James Smart92d7f7b2007-06-17 19:56:38 -05006787 }
James Smart58da1ff2008-04-07 10:15:56 -04006788 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006789
6790 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6791
6792 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6793 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006794 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6795 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006796 return;
6797 }
6798
James Smart3de2a652007-08-02 11:09:59 -04006799 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05006800 /* If this is the first time, allocate an ndlp and initialize
6801 * it. Otherwise, make sure the node is enabled and then do the
6802 * login.
6803 */
6804 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
6805 if (!ndlp_fdmi) {
6806 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6807 GFP_KERNEL);
6808 if (ndlp_fdmi) {
6809 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6810 ndlp_fdmi->nlp_type |= NLP_FABRIC;
6811 } else
6812 return;
6813 }
6814 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
6815 ndlp_fdmi = lpfc_enable_node(vport,
6816 ndlp_fdmi,
6817 NLP_STE_NPR_NODE);
6818
James Smart92d7f7b2007-06-17 19:56:38 -05006819 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04006820 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05006821 NLP_STE_PLOGI_ISSUE);
6822 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006823 }
6824 }
James Smart92d7f7b2007-06-17 19:56:38 -05006825}
6826
James Smarte59058c2008-08-24 21:49:00 -04006827/**
James Smart3621a712009-04-06 18:47:14 -04006828 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006829 * @phba: pointer to lpfc hba data structure.
6830 * @pmb: pointer to the driver internal queue element for mailbox command.
6831 *
6832 * This routine is the completion callback function to register new vport
6833 * mailbox command. If the new vport mailbox command completes successfully,
6834 * the fabric registration login shall be performed on physical port (the
6835 * new vport created is actually a physical port, with VPI 0) or the port
6836 * login to Name Server for State Change Request (SCR) will be performed
6837 * on virtual port (real virtual port, with VPI greater than 0).
6838 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006839static void
6840lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6841{
6842 struct lpfc_vport *vport = pmb->vport;
6843 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6844 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006845 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006846 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006847
James Smart09372822008-01-11 01:52:54 -05006848 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006849 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006850 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006851
6852 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006853 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006854 "0915 Register VPI failed : Status: x%x"
6855 " upd bit: x%x \n", mb->mbxStatus,
6856 mb->un.varRegVpi.upd);
6857 if (phba->sli_rev == LPFC_SLI_REV4 &&
6858 mb->un.varRegVpi.upd)
6859 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006860
6861 switch (mb->mbxStatus) {
6862 case 0x11: /* unsupported feature */
6863 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006864 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006865 /* giving up on vport registration */
6866 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6867 spin_lock_irq(shost->host_lock);
6868 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6869 spin_unlock_irq(shost->host_lock);
6870 lpfc_can_disctmo(vport);
6871 break;
James Smart695a8142010-01-26 23:08:03 -05006872 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6873 case 0x20:
6874 spin_lock_irq(shost->host_lock);
6875 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6876 spin_unlock_irq(shost->host_lock);
6877 lpfc_init_vpi(phba, pmb, vport->vpi);
6878 pmb->vport = vport;
6879 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6880 rc = lpfc_sli_issue_mbox(phba, pmb,
6881 MBX_NOWAIT);
6882 if (rc == MBX_NOT_FINISHED) {
6883 lpfc_printf_vlog(vport,
6884 KERN_ERR, LOG_MBOX,
6885 "2732 Failed to issue INIT_VPI"
6886 " mailbox command\n");
6887 } else {
6888 lpfc_nlp_put(ndlp);
6889 return;
6890 }
6891
James Smart92d7f7b2007-06-17 19:56:38 -05006892 default:
6893 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04006894 if (phba->sli_rev == LPFC_SLI_REV4)
6895 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006896 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006897 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006898 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006899 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006900 if (vport->port_type == LPFC_PHYSICAL_PORT
6901 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05006902 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05006903 else
6904 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006905 break;
6906 }
James Smart92d7f7b2007-06-17 19:56:38 -05006907 } else {
James Smart695a8142010-01-26 23:08:03 -05006908 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006909 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006910 spin_unlock_irq(shost->host_lock);
6911 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006912 if (phba->sli_rev < LPFC_SLI_REV4)
6913 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006914 else {
James Smartfc2b9892010-02-26 14:15:29 -05006915 /*
6916 * If the physical port is instantiated using
6917 * FDISC, do not start vport discovery.
6918 */
6919 if (vport->port_state != LPFC_FDISC)
6920 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006921 lpfc_do_scr_ns_plogi(phba, vport);
6922 }
6923 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006924 lpfc_do_scr_ns_plogi(phba, vport);
6925 }
James Smart38b92ef2010-08-04 16:11:39 -04006926mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05006927 /* Now, we decrement the ndlp reference count held for this
6928 * callback function
6929 */
6930 lpfc_nlp_put(ndlp);
6931
James Smart92d7f7b2007-06-17 19:56:38 -05006932 mempool_free(pmb, phba->mbox_mem_pool);
6933 return;
6934}
6935
James Smarte59058c2008-08-24 21:49:00 -04006936/**
James Smart3621a712009-04-06 18:47:14 -04006937 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006938 * @phba: pointer to lpfc hba data structure.
6939 * @vport: pointer to a host virtual N_Port data structure.
6940 * @ndlp: pointer to a node-list data structure.
6941 *
6942 * This routine registers the @vport as a new virtual port with a HBA.
6943 * It is done through a registering vpi mailbox command.
6944 **/
James Smart695a8142010-01-26 23:08:03 -05006945void
James Smart92d7f7b2007-06-17 19:56:38 -05006946lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6947 struct lpfc_nodelist *ndlp)
6948{
James Smart09372822008-01-11 01:52:54 -05006949 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006950 LPFC_MBOXQ_t *mbox;
6951
6952 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6953 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006954 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006955 mbox->vport = vport;
6956 mbox->context2 = lpfc_nlp_get(ndlp);
6957 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006958 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006959 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006960 /* mailbox command not success, decrement ndlp
6961 * reference count for this command
6962 */
6963 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006964 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006965
James Smarte8b62012007-08-02 11:10:09 -04006966 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6967 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006968 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006969 }
6970 } else {
James Smarte8b62012007-08-02 11:10:09 -04006971 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6972 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006973 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006974 }
James Smartfa4066b2008-01-11 01:53:27 -05006975 return;
6976
6977mbox_err_exit:
6978 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6979 spin_lock_irq(shost->host_lock);
6980 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6981 spin_unlock_irq(shost->host_lock);
6982 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006983}
6984
James Smarte59058c2008-08-24 21:49:00 -04006985/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006986 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006987 * @phba: pointer to lpfc hba data structure.
6988 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006989 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006990 **/
6991void
James Smart0c9ab6f2010-02-26 14:15:57 -05006992lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006993{
6994 struct lpfc_vport **vports;
6995 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006996 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006997 int i;
James Smart695a8142010-01-26 23:08:03 -05006998
6999 /* Treat this failure as linkdown for all vports */
7000 link_state = phba->link_state;
7001 lpfc_linkdown(phba);
7002 phba->link_state = link_state;
7003
7004 vports = lpfc_create_vport_work_array(phba);
7005
7006 if (vports) {
7007 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
7008 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
7009 if (ndlp)
7010 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
7011 lpfc_els_flush_cmd(vports[i]);
7012 }
7013 lpfc_destroy_vport_work_array(phba, vports);
7014 }
James Smart0c9ab6f2010-02-26 14:15:57 -05007015}
7016
7017/**
7018 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7019 * @phba: pointer to lpfc hba data structure.
7020 *
7021 * This routine abort all pending discovery commands and
7022 * start a timer to retry FLOGI for the physical port
7023 * discovery.
7024 **/
7025void
7026lpfc_retry_pport_discovery(struct lpfc_hba *phba)
7027{
7028 struct lpfc_nodelist *ndlp;
7029 struct Scsi_Host *shost;
7030
7031 /* Cancel the all vports retry delay retry timers */
7032 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05007033
7034 /* If fabric require FLOGI, then re-instantiate physical login */
7035 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
7036 if (!ndlp)
7037 return;
7038
James Smart695a8142010-01-26 23:08:03 -05007039 shost = lpfc_shost_from_vport(phba->pport);
7040 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
7041 spin_lock_irq(shost->host_lock);
7042 ndlp->nlp_flag |= NLP_DELAY_TMO;
7043 spin_unlock_irq(shost->host_lock);
7044 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7045 phba->pport->port_state = LPFC_FLOGI;
7046 return;
7047}
7048
7049/**
7050 * lpfc_fabric_login_reqd - Check if FLOGI required.
7051 * @phba: pointer to lpfc hba data structure.
7052 * @cmdiocb: pointer to FDISC command iocb.
7053 * @rspiocb: pointer to FDISC response iocb.
7054 *
7055 * This routine checks if a FLOGI is reguired for FDISC
7056 * to succeed.
7057 **/
7058static int
7059lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7060 struct lpfc_iocbq *cmdiocb,
7061 struct lpfc_iocbq *rspiocb)
7062{
7063
7064 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7065 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7066 return 0;
7067 else
7068 return 1;
7069}
7070
7071/**
James Smart3621a712009-04-06 18:47:14 -04007072 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007073 * @phba: pointer to lpfc hba data structure.
7074 * @cmdiocb: pointer to lpfc command iocb data structure.
7075 * @rspiocb: pointer to lpfc response iocb data structure.
7076 *
7077 * This routine is the completion callback function to a Fabric Discover
7078 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7079 * single threaded, each FDISC completion callback function will reset
7080 * the discovery timer for all vports such that the timers will not get
7081 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7082 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7083 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7084 * assigned to the vport has been changed with the completion of the FDISC
7085 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7086 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7087 * routine is invoked to register new vport with the HBA. Otherwise, the
7088 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7089 * Server for State Change Request (SCR).
7090 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007091static void
7092lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7093 struct lpfc_iocbq *rspiocb)
7094{
7095 struct lpfc_vport *vport = cmdiocb->vport;
7096 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7097 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7098 struct lpfc_nodelist *np;
7099 struct lpfc_nodelist *next_np;
7100 IOCB_t *irsp = &rspiocb->iocb;
7101 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05007102 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7103 struct serv_parm *sp;
7104 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05007105
James Smarte8b62012007-08-02 11:10:09 -04007106 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7107 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7108 irsp->ulpStatus, irsp->un.ulpWord[4],
7109 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05007110 /* Since all FDISCs are being single threaded, we
7111 * must reset the discovery timer for ALL vports
7112 * waiting to send FDISC when one completes.
7113 */
7114 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7115 lpfc_set_disctmo(piocb->vport);
7116 }
7117
James Smart858c9f62007-06-17 19:56:39 -05007118 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7119 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7120 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7121
James Smart92d7f7b2007-06-17 19:56:38 -05007122 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05007123
7124 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7125 lpfc_retry_pport_discovery(phba);
7126 goto out;
7127 }
7128
James Smart92d7f7b2007-06-17 19:56:38 -05007129 /* Check for retry */
7130 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7131 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007132 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04007133 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04007134 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04007135 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04007136 goto fdisc_failed;
7137 }
James Smartd7c255b2008-08-24 21:50:00 -04007138 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05007139 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04007140 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04007141 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05007142 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04007143 vport->fc_flag |= FC_PUBLIC_LOOP;
7144 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007145
James Smartd7c255b2008-08-24 21:50:00 -04007146 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7147 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05007148 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7149 sp = prsp->virt + sizeof(uint32_t);
7150 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7151 memcpy(&vport->fabric_portname, &sp->portName,
7152 sizeof(struct lpfc_name));
7153 memcpy(&vport->fabric_nodename, &sp->nodeName,
7154 sizeof(struct lpfc_name));
7155 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04007156 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7157 /* If our NportID changed, we need to ensure all
7158 * remaining NPORTs get unreg_login'ed so we can
7159 * issue unreg_vpi.
7160 */
7161 list_for_each_entry_safe(np, next_np,
7162 &vport->fc_nodes, nlp_listp) {
7163 if (!NLP_CHK_NODE_ACT(ndlp) ||
7164 (np->nlp_state != NLP_STE_NPR_NODE) ||
7165 !(np->nlp_flag & NLP_NPR_ADISC))
7166 continue;
James Smart09372822008-01-11 01:52:54 -05007167 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007168 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007169 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007170 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007171 }
James Smart78730cf2010-04-06 15:06:30 -04007172 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007173
7174 if (phba->sli_rev == LPFC_SLI_REV4)
7175 lpfc_sli4_unreg_all_rpis(vport);
7176
James Smartd7c255b2008-08-24 21:50:00 -04007177 lpfc_mbx_unreg_vpi(vport);
7178 spin_lock_irq(shost->host_lock);
7179 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007180 if (phba->sli_rev == LPFC_SLI_REV4)
7181 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007182 else
7183 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007184 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007185 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7186 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7187 /*
7188 * Driver needs to re-reg VPI in order for f/w
7189 * to update the MAC address.
7190 */
7191 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007192 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007193 }
7194
James Smartecfd03c2010-02-12 14:41:27 -05007195 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7196 lpfc_issue_init_vpi(vport);
7197 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007198 lpfc_register_new_vport(phba, vport, ndlp);
7199 else
7200 lpfc_do_scr_ns_plogi(phba, vport);
7201 goto out;
7202fdisc_failed:
7203 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7204 /* Cancel discovery timer */
7205 lpfc_can_disctmo(vport);
7206 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007207out:
7208 lpfc_els_free_iocb(phba, cmdiocb);
7209}
7210
James Smarte59058c2008-08-24 21:49:00 -04007211/**
James Smart3621a712009-04-06 18:47:14 -04007212 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007213 * @vport: pointer to a virtual N_Port data structure.
7214 * @ndlp: pointer to a node-list data structure.
7215 * @retry: number of retries to the command IOCB.
7216 *
7217 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7218 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7219 * routine to issue the IOCB, which makes sure only one outstanding fabric
7220 * IOCB will be sent off HBA at any given time.
7221 *
7222 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7223 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7224 * will be stored into the context1 field of the IOCB for the completion
7225 * callback function to the FDISC ELS command.
7226 *
7227 * Return code
7228 * 0 - Successfully issued fdisc iocb command
7229 * 1 - Failed to issue fdisc iocb command
7230 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007231static int
James Smart92d7f7b2007-06-17 19:56:38 -05007232lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7233 uint8_t retry)
7234{
7235 struct lpfc_hba *phba = vport->phba;
7236 IOCB_t *icmd;
7237 struct lpfc_iocbq *elsiocb;
7238 struct serv_parm *sp;
7239 uint8_t *pcmd;
7240 uint16_t cmdsize;
7241 int did = ndlp->nlp_DID;
7242 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007243
James Smart5ffc2662009-11-18 15:39:44 -05007244 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05007245 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7246 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7247 ELS_CMD_FDISC);
7248 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007249 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007250 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7251 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007252 return 1;
7253 }
7254
7255 icmd = &elsiocb->iocb;
7256 icmd->un.elsreq64.myID = 0;
7257 icmd->un.elsreq64.fl = 1;
7258
James Smart40426292010-12-15 17:58:10 -05007259 if ((phba->sli_rev == LPFC_SLI_REV4) &&
7260 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
7261 LPFC_SLI_INTF_IF_TYPE_0)) {
James Smartf1126682009-06-10 17:22:44 -04007262 /* FDISC needs to be 1 for WQE VPI */
7263 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
7264 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
7265 /* Set the ulpContext to the vpi */
James Smart6d368e52011-05-24 11:44:12 -04007266 elsiocb->iocb.ulpContext = phba->vpi_ids[vport->vpi];
James Smartf1126682009-06-10 17:22:44 -04007267 } else {
7268 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
7269 icmd->ulpCt_h = 1;
7270 icmd->ulpCt_l = 0;
7271 }
James Smart92d7f7b2007-06-17 19:56:38 -05007272
7273 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7274 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7275 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7276 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7277 sp = (struct serv_parm *) pcmd;
7278 /* Setup CSPs accordingly for Fabric */
7279 sp->cmn.e_d_tov = 0;
7280 sp->cmn.w2.r_a_tov = 0;
7281 sp->cls1.classValid = 0;
7282 sp->cls2.seqDelivery = 1;
7283 sp->cls3.seqDelivery = 1;
7284
7285 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7286 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7287 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7288 pcmd += sizeof(uint32_t); /* Port Name */
7289 memcpy(pcmd, &vport->fc_portname, 8);
7290 pcmd += sizeof(uint32_t); /* Node Name */
7291 pcmd += sizeof(uint32_t); /* Node Name */
7292 memcpy(pcmd, &vport->fc_nodename, 8);
7293
7294 lpfc_set_disctmo(vport);
7295
7296 phba->fc_stat.elsXmitFDISC++;
7297 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7298
James Smart858c9f62007-06-17 19:56:39 -05007299 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7300 "Issue FDISC: did:x%x",
7301 did, 0, 0);
7302
James Smart92d7f7b2007-06-17 19:56:38 -05007303 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7304 if (rc == IOCB_ERROR) {
7305 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007306 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007307 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7308 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007309 return 1;
7310 }
7311 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007312 return 0;
7313}
7314
James Smarte59058c2008-08-24 21:49:00 -04007315/**
James Smart3621a712009-04-06 18:47:14 -04007316 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007317 * @phba: pointer to lpfc hba data structure.
7318 * @cmdiocb: pointer to lpfc command iocb data structure.
7319 * @rspiocb: pointer to lpfc response iocb data structure.
7320 *
7321 * This routine is the completion callback function to the issuing of a LOGO
7322 * ELS command off a vport. It frees the command IOCB and then decrement the
7323 * reference count held on ndlp for this completion function, indicating that
7324 * the reference to the ndlp is no long needed. Note that the
7325 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7326 * callback function and an additional explicit ndlp reference decrementation
7327 * will trigger the actual release of the ndlp.
7328 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007329static void
7330lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7331 struct lpfc_iocbq *rspiocb)
7332{
7333 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007334 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007335 struct lpfc_nodelist *ndlp;
James Smart9589b062011-04-16 11:03:17 -04007336 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05007337
James Smart9589b062011-04-16 11:03:17 -04007338 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007339 irsp = &rspiocb->iocb;
7340 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7341 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7342 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007343
7344 lpfc_els_free_iocb(phba, cmdiocb);
7345 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007346
7347 /* Trigger the release of the ndlp after logo */
7348 lpfc_nlp_put(ndlp);
James Smart9589b062011-04-16 11:03:17 -04007349
7350 /* NPIV LOGO completes to NPort <nlp_DID> */
7351 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7352 "2928 NPIV LOGO completes to NPort x%x "
7353 "Data: x%x x%x x%x x%x\n",
7354 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
7355 irsp->ulpTimeout, vport->num_disc_nodes);
7356
7357 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
7358 spin_lock_irq(shost->host_lock);
7359 vport->fc_flag &= ~FC_FABRIC;
7360 spin_unlock_irq(shost->host_lock);
7361 }
James Smart92d7f7b2007-06-17 19:56:38 -05007362}
7363
James Smarte59058c2008-08-24 21:49:00 -04007364/**
James Smart3621a712009-04-06 18:47:14 -04007365 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007366 * @vport: pointer to a virtual N_Port data structure.
7367 * @ndlp: pointer to a node-list data structure.
7368 *
7369 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7370 *
7371 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7372 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7373 * will be stored into the context1 field of the IOCB for the completion
7374 * callback function to the LOGO ELS command.
7375 *
7376 * Return codes
7377 * 0 - Successfully issued logo off the @vport
7378 * 1 - Failed to issue logo off the @vport
7379 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007380int
7381lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7382{
7383 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7384 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007385 IOCB_t *icmd;
7386 struct lpfc_iocbq *elsiocb;
7387 uint8_t *pcmd;
7388 uint16_t cmdsize;
7389
7390 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7391 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7392 ELS_CMD_LOGO);
7393 if (!elsiocb)
7394 return 1;
7395
7396 icmd = &elsiocb->iocb;
7397 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7398 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7399 pcmd += sizeof(uint32_t);
7400
7401 /* Fill in LOGO payload */
7402 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7403 pcmd += sizeof(uint32_t);
7404 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7405
James Smart858c9f62007-06-17 19:56:39 -05007406 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7407 "Issue LOGO npiv did:x%x flg:x%x",
7408 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7409
James Smart92d7f7b2007-06-17 19:56:38 -05007410 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7411 spin_lock_irq(shost->host_lock);
7412 ndlp->nlp_flag |= NLP_LOGO_SND;
7413 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007414 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7415 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007416 spin_lock_irq(shost->host_lock);
7417 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7418 spin_unlock_irq(shost->host_lock);
7419 lpfc_els_free_iocb(phba, elsiocb);
7420 return 1;
7421 }
7422 return 0;
7423}
7424
James Smarte59058c2008-08-24 21:49:00 -04007425/**
James Smart3621a712009-04-06 18:47:14 -04007426 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007427 * @ptr: holder for the timer function associated data.
7428 *
7429 * This routine is invoked by the fabric iocb block timer after
7430 * timeout. It posts the fabric iocb block timeout event by setting the
7431 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7432 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7433 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7434 * posted event WORKER_FABRIC_BLOCK_TMO.
7435 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007436void
7437lpfc_fabric_block_timeout(unsigned long ptr)
7438{
7439 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7440 unsigned long iflags;
7441 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007442
James Smart92d7f7b2007-06-17 19:56:38 -05007443 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7444 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7445 if (!tmo_posted)
7446 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7447 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7448
James Smart5e9d9b82008-06-14 22:52:53 -04007449 if (!tmo_posted)
7450 lpfc_worker_wake_up(phba);
7451 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007452}
7453
James Smarte59058c2008-08-24 21:49:00 -04007454/**
James Smart3621a712009-04-06 18:47:14 -04007455 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007456 * @phba: pointer to lpfc hba data structure.
7457 *
7458 * This routine issues one fabric iocb from the driver internal list to
7459 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7460 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7461 * remove one pending fabric iocb from the driver internal list and invokes
7462 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7463 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007464static void
7465lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7466{
7467 struct lpfc_iocbq *iocb;
7468 unsigned long iflags;
7469 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007470 IOCB_t *cmd;
7471
7472repeat:
7473 iocb = NULL;
7474 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007475 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007476 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7477 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7478 list);
7479 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007480 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007481 atomic_inc(&phba->fabric_iocb_count);
7482 }
7483 spin_unlock_irqrestore(&phba->hbalock, iflags);
7484 if (iocb) {
7485 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7486 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7487 iocb->iocb_flag |= LPFC_IO_FABRIC;
7488
James Smart858c9f62007-06-17 19:56:39 -05007489 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7490 "Fabric sched1: ste:x%x",
7491 iocb->vport->port_state, 0, 0);
7492
James Smart3772a992009-05-22 14:50:54 -04007493 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007494
7495 if (ret == IOCB_ERROR) {
7496 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7497 iocb->fabric_iocb_cmpl = NULL;
7498 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7499 cmd = &iocb->iocb;
7500 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7501 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7502 iocb->iocb_cmpl(phba, iocb, iocb);
7503
7504 atomic_dec(&phba->fabric_iocb_count);
7505 goto repeat;
7506 }
7507 }
7508
7509 return;
7510}
7511
James Smarte59058c2008-08-24 21:49:00 -04007512/**
James Smart3621a712009-04-06 18:47:14 -04007513 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007514 * @phba: pointer to lpfc hba data structure.
7515 *
7516 * This routine unblocks the issuing fabric iocb command. The function
7517 * will clear the fabric iocb block bit and then invoke the routine
7518 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7519 * from the driver internal fabric iocb list.
7520 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007521void
7522lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7523{
7524 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7525
7526 lpfc_resume_fabric_iocbs(phba);
7527 return;
7528}
7529
James Smarte59058c2008-08-24 21:49:00 -04007530/**
James Smart3621a712009-04-06 18:47:14 -04007531 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007532 * @phba: pointer to lpfc hba data structure.
7533 *
7534 * This routine blocks the issuing fabric iocb for a specified amount of
7535 * time (currently 100 ms). This is done by set the fabric iocb block bit
7536 * and set up a timeout timer for 100ms. When the block bit is set, no more
7537 * fabric iocb will be issued out of the HBA.
7538 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007539static void
7540lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7541{
7542 int blocked;
7543
7544 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007545 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007546 if (!blocked)
7547 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7548
7549 return;
7550}
7551
James Smarte59058c2008-08-24 21:49:00 -04007552/**
James Smart3621a712009-04-06 18:47:14 -04007553 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007554 * @phba: pointer to lpfc hba data structure.
7555 * @cmdiocb: pointer to lpfc command iocb data structure.
7556 * @rspiocb: pointer to lpfc response iocb data structure.
7557 *
7558 * This routine is the callback function that is put to the fabric iocb's
7559 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7560 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7561 * function first restores and invokes the original iocb's callback function
7562 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7563 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7564 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007565static void
7566lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7567 struct lpfc_iocbq *rspiocb)
7568{
7569 struct ls_rjt stat;
7570
7571 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7572 BUG();
7573
7574 switch (rspiocb->iocb.ulpStatus) {
7575 case IOSTAT_NPORT_RJT:
7576 case IOSTAT_FABRIC_RJT:
7577 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7578 lpfc_block_fabric_iocbs(phba);
7579 }
7580 break;
7581
7582 case IOSTAT_NPORT_BSY:
7583 case IOSTAT_FABRIC_BSY:
7584 lpfc_block_fabric_iocbs(phba);
7585 break;
7586
7587 case IOSTAT_LS_RJT:
7588 stat.un.lsRjtError =
7589 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7590 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7591 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7592 lpfc_block_fabric_iocbs(phba);
7593 break;
7594 }
7595
7596 if (atomic_read(&phba->fabric_iocb_count) == 0)
7597 BUG();
7598
7599 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7600 cmdiocb->fabric_iocb_cmpl = NULL;
7601 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7602 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7603
7604 atomic_dec(&phba->fabric_iocb_count);
7605 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007606 /* Post any pending iocbs to HBA */
7607 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007608 }
7609}
7610
James Smarte59058c2008-08-24 21:49:00 -04007611/**
James Smart3621a712009-04-06 18:47:14 -04007612 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007613 * @phba: pointer to lpfc hba data structure.
7614 * @iocb: pointer to lpfc command iocb data structure.
7615 *
7616 * This routine is used as the top-level API for issuing a fabric iocb command
7617 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7618 * function makes sure that only one fabric bound iocb will be outstanding at
7619 * any given time. As such, this function will first check to see whether there
7620 * is already an outstanding fabric iocb on the wire. If so, it will put the
7621 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7622 * issued later. Otherwise, it will issue the iocb on the wire and update the
7623 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7624 *
7625 * Note, this implementation has a potential sending out fabric IOCBs out of
7626 * order. The problem is caused by the construction of the "ready" boolen does
7627 * not include the condition that the internal fabric IOCB list is empty. As
7628 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7629 * ahead of the fabric IOCBs in the internal list.
7630 *
7631 * Return code
7632 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7633 * IOCB_ERROR - failed to issue fabric iocb
7634 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007635static int
James Smart92d7f7b2007-06-17 19:56:38 -05007636lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7637{
7638 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007639 int ready;
7640 int ret;
7641
7642 if (atomic_read(&phba->fabric_iocb_count) > 1)
7643 BUG();
7644
7645 spin_lock_irqsave(&phba->hbalock, iflags);
7646 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7647 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7648
James Smart7f5f3d02008-02-08 18:50:14 -05007649 if (ready)
7650 /* Increment fabric iocb count to hold the position */
7651 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007652 spin_unlock_irqrestore(&phba->hbalock, iflags);
7653 if (ready) {
7654 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7655 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7656 iocb->iocb_flag |= LPFC_IO_FABRIC;
7657
James Smart858c9f62007-06-17 19:56:39 -05007658 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7659 "Fabric sched2: ste:x%x",
7660 iocb->vport->port_state, 0, 0);
7661
James Smart3772a992009-05-22 14:50:54 -04007662 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007663
7664 if (ret == IOCB_ERROR) {
7665 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7666 iocb->fabric_iocb_cmpl = NULL;
7667 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7668 atomic_dec(&phba->fabric_iocb_count);
7669 }
7670 } else {
7671 spin_lock_irqsave(&phba->hbalock, iflags);
7672 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7673 spin_unlock_irqrestore(&phba->hbalock, iflags);
7674 ret = IOCB_SUCCESS;
7675 }
7676 return ret;
7677}
7678
James Smarte59058c2008-08-24 21:49:00 -04007679/**
James Smart3621a712009-04-06 18:47:14 -04007680 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007681 * @vport: pointer to a virtual N_Port data structure.
7682 *
7683 * This routine aborts all the IOCBs associated with a @vport from the
7684 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7685 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7686 * list, removes each IOCB associated with the @vport off the list, set the
7687 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7688 * associated with the IOCB.
7689 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007690static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007691{
7692 LIST_HEAD(completions);
7693 struct lpfc_hba *phba = vport->phba;
7694 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007695
7696 spin_lock_irq(&phba->hbalock);
7697 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7698 list) {
7699
7700 if (piocb->vport != vport)
7701 continue;
7702
7703 list_move_tail(&piocb->list, &completions);
7704 }
7705 spin_unlock_irq(&phba->hbalock);
7706
James Smarta257bf92009-04-06 18:48:10 -04007707 /* Cancel all the IOCBs from the completions list */
7708 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7709 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007710}
7711
James Smarte59058c2008-08-24 21:49:00 -04007712/**
James Smart3621a712009-04-06 18:47:14 -04007713 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007714 * @ndlp: pointer to a node-list data structure.
7715 *
7716 * This routine aborts all the IOCBs associated with an @ndlp from the
7717 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7718 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7719 * list, removes each IOCB associated with the @ndlp off the list, set the
7720 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7721 * associated with the IOCB.
7722 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007723void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7724{
7725 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007726 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007727 struct lpfc_iocbq *tmp_iocb, *piocb;
7728 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007729
7730 spin_lock_irq(&phba->hbalock);
7731 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7732 list) {
7733 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7734
7735 list_move_tail(&piocb->list, &completions);
7736 }
7737 }
7738 spin_unlock_irq(&phba->hbalock);
7739
James Smarta257bf92009-04-06 18:48:10 -04007740 /* Cancel all the IOCBs from the completions list */
7741 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7742 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007743}
7744
James Smarte59058c2008-08-24 21:49:00 -04007745/**
James Smart3621a712009-04-06 18:47:14 -04007746 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007747 * @phba: pointer to lpfc hba data structure.
7748 *
7749 * This routine aborts all the IOCBs currently on the driver internal
7750 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7751 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7752 * list, removes IOCBs off the list, set the status feild to
7753 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7754 * the IOCB.
7755 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007756void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7757{
7758 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007759
7760 spin_lock_irq(&phba->hbalock);
7761 list_splice_init(&phba->fabric_iocb_list, &completions);
7762 spin_unlock_irq(&phba->hbalock);
7763
James Smarta257bf92009-04-06 18:48:10 -04007764 /* Cancel all the IOCBs from the completions list */
7765 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7766 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007767}
James Smart6fb120a2009-05-22 14:52:59 -04007768
7769/**
James Smart1151e3e2011-02-16 12:39:35 -05007770 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7771 * @vport: pointer to lpfc vport data structure.
7772 *
7773 * This routine is invoked by the vport cleanup for deletions and the cleanup
7774 * for an ndlp on removal.
7775 **/
7776void
7777lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
7778{
7779 struct lpfc_hba *phba = vport->phba;
7780 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7781 unsigned long iflag = 0;
7782
7783 spin_lock_irqsave(&phba->hbalock, iflag);
7784 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7785 list_for_each_entry_safe(sglq_entry, sglq_next,
7786 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7787 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
7788 sglq_entry->ndlp = NULL;
7789 }
7790 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7791 spin_unlock_irqrestore(&phba->hbalock, iflag);
7792 return;
7793}
7794
7795/**
James Smart6fb120a2009-05-22 14:52:59 -04007796 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7797 * @phba: pointer to lpfc hba data structure.
7798 * @axri: pointer to the els xri abort wcqe structure.
7799 *
7800 * This routine is invoked by the worker thread to process a SLI4 slow-path
7801 * ELS aborted xri.
7802 **/
7803void
7804lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7805 struct sli4_wcqe_xri_aborted *axri)
7806{
7807 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05007808 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04007809 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05007810
James Smart6fb120a2009-05-22 14:52:59 -04007811 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7812 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05007813 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04007814 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007815
James Smart0f65ff62010-02-26 14:14:23 -05007816 spin_lock_irqsave(&phba->hbalock, iflag);
7817 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007818 list_for_each_entry_safe(sglq_entry, sglq_next,
7819 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7820 if (sglq_entry->sli4_xritag == xri) {
7821 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05007822 ndlp = sglq_entry->ndlp;
7823 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04007824 list_add_tail(&sglq_entry->list,
7825 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007826 sglq_entry->state = SGL_FREED;
7827 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007828 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart19ca7602010-11-20 23:11:55 -05007829 lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04007830
7831 /* Check if TXQ queue needs to be serviced */
7832 if (pring->txq_cnt)
7833 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007834 return;
7835 }
7836 }
James Smart0f65ff62010-02-26 14:14:23 -05007837 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04007838 lxri = lpfc_sli4_xri_inrange(phba, xri);
7839 if (lxri == NO_XRI) {
7840 spin_unlock_irqrestore(&phba->hbalock, iflag);
7841 return;
7842 }
7843 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05007844 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7845 spin_unlock_irqrestore(&phba->hbalock, iflag);
7846 return;
7847 }
7848 sglq_entry->state = SGL_XRI_ABORTED;
7849 spin_unlock_irqrestore(&phba->hbalock, iflag);
7850 return;
James Smart6fb120a2009-05-22 14:52:59 -04007851}