blob: d3a712a27e3183a3004d9ecf62457b0487677439 [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
650 if (phba->sli_rev == LPFC_SLI_REV4)
651 lpfc_sli4_unreg_all_rpis(vport);
652
James Smart92d7f7b2007-06-17 19:56:38 -0500653 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
654 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500655 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500656 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500657 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500658 }
James Smartecfd03c2010-02-12 14:41:27 -0500659 /*
660 * If VPI is unreged, driver need to do INIT_VPI
661 * before re-registering
662 */
663 if (phba->sli_rev == LPFC_SLI_REV4) {
664 spin_lock_irq(shost->host_lock);
665 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
666 spin_unlock_irq(shost->host_lock);
667 }
James Smart38b92ef2010-08-04 16:11:39 -0400668 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
669 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
670 /*
671 * Driver needs to re-reg VPI in order for f/w
672 * to update the MAC address.
673 */
James Smart9589b062011-04-16 11:03:17 -0400674 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400675 lpfc_register_new_vport(phba, vport, ndlp);
676 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500677 }
678
James Smart6fb120a2009-05-22 14:52:59 -0400679 if (phba->sli_rev < LPFC_SLI_REV4) {
680 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
681 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
682 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
683 lpfc_register_new_vport(phba, vport, ndlp);
684 else
685 lpfc_issue_fabric_reglogin(vport);
686 } else {
687 ndlp->nlp_type |= NLP_FABRIC;
688 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500689 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
690 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400691 lpfc_start_fdiscs(phba);
692 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500693 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500694 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500695 else
James Smart6fb120a2009-05-22 14:52:59 -0400696 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500697 }
dea31012005-04-17 16:05:31 -0500698 return 0;
dea31012005-04-17 16:05:31 -0500699}
James Smarte59058c2008-08-24 21:49:00 -0400700/**
James Smart3621a712009-04-06 18:47:14 -0400701 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400702 * @vport: pointer to a host virtual N_Port data structure.
703 * @ndlp: pointer to a node-list data structure.
704 * @sp: pointer to service parameter data structure.
705 *
706 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
707 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
708 * in a point-to-point topology. First, the @vport's N_Port Name is compared
709 * with the received N_Port Name: if the @vport's N_Port Name is greater than
710 * the received N_Port Name lexicographically, this node shall assign local
711 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
712 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
713 * this node shall just wait for the remote node to issue PLOGI and assign
714 * N_Port IDs.
715 *
716 * Return code
717 * 0 - Success
718 * -ENXIO - Fail
719 **/
dea31012005-04-17 16:05:31 -0500720static int
James Smart2e0fef82007-06-17 19:56:36 -0500721lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
722 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500723{
James Smart2e0fef82007-06-17 19:56:36 -0500724 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
725 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500726 LPFC_MBOXQ_t *mbox;
727 int rc;
728
James Smart2e0fef82007-06-17 19:56:36 -0500729 spin_lock_irq(shost->host_lock);
730 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
731 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500732
733 phba->fc_edtov = FF_DEF_EDTOV;
734 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500735 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500736 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500737 if (rc >= 0) {
738 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500739 spin_lock_irq(shost->host_lock);
740 vport->fc_flag |= FC_PT2PT_PLOGI;
741 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500742
743 /*
744 * N_Port ID cannot be 0, set our to LocalID the other
745 * side will be RemoteID.
746 */
747
748 /* not equal */
749 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500750 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500751
752 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
753 if (!mbox)
754 goto fail;
755
756 lpfc_config_link(phba, mbox);
757
758 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500759 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400760 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500761 if (rc == MBX_NOT_FINISHED) {
762 mempool_free(mbox, phba->mbox_mem_pool);
763 goto fail;
764 }
James Smarte47c9092008-02-08 18:49:26 -0500765 /* Decrement ndlp reference count indicating that ndlp can be
766 * safely released when other references to it are done.
767 */
James Smart329f9bc2007-04-25 09:53:01 -0400768 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500769
James Smart2e0fef82007-06-17 19:56:36 -0500770 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500771 if (!ndlp) {
772 /*
773 * Cannot find existing Fabric ndlp, so allocate a
774 * new one
775 */
776 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
777 if (!ndlp)
778 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500779 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500780 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
781 ndlp = lpfc_enable_node(vport, ndlp,
782 NLP_STE_UNUSED_NODE);
783 if(!ndlp)
784 goto fail;
dea31012005-04-17 16:05:31 -0500785 }
786
787 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500788 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500789 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500790 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500791 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500792 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
793 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500794 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500795 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500796 } else
797 /* This side will wait for the PLOGI, decrement ndlp reference
798 * count indicating that ndlp can be released when other
799 * references to it are done.
800 */
James Smart329f9bc2007-04-25 09:53:01 -0400801 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500802
James Smart09372822008-01-11 01:52:54 -0500803 /* If we are pt2pt with another NPort, force NPIV off! */
804 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
805
James Smart2e0fef82007-06-17 19:56:36 -0500806 spin_lock_irq(shost->host_lock);
807 vport->fc_flag |= FC_PT2PT;
808 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500809
810 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500811 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500812 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500813fail:
dea31012005-04-17 16:05:31 -0500814 return -ENXIO;
815}
816
James Smarte59058c2008-08-24 21:49:00 -0400817/**
James Smart3621a712009-04-06 18:47:14 -0400818 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400819 * @phba: pointer to lpfc hba data structure.
820 * @cmdiocb: pointer to lpfc command iocb data structure.
821 * @rspiocb: pointer to lpfc response iocb data structure.
822 *
823 * This routine is the top-level completion callback function for issuing
824 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
825 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
826 * retry has been made (either immediately or delayed with lpfc_els_retry()
827 * returning 1), the command IOCB will be released and function returned.
828 * If the retry attempt has been given up (possibly reach the maximum
829 * number of retries), one additional decrement of ndlp reference shall be
830 * invoked before going out after releasing the command IOCB. This will
831 * actually release the remote node (Note, lpfc_els_free_iocb() will also
832 * invoke one decrement of ndlp reference count). If no error reported in
833 * the IOCB status, the command Port ID field is used to determine whether
834 * this is a point-to-point topology or a fabric topology: if the Port ID
835 * field is assigned, it is a fabric topology; otherwise, it is a
836 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
837 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
838 * specific topology completion conditions.
839 **/
dea31012005-04-17 16:05:31 -0500840static void
James Smart329f9bc2007-04-25 09:53:01 -0400841lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
842 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500843{
James Smart2e0fef82007-06-17 19:56:36 -0500844 struct lpfc_vport *vport = cmdiocb->vport;
845 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500846 IOCB_t *irsp = &rspiocb->iocb;
847 struct lpfc_nodelist *ndlp = cmdiocb->context1;
848 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
849 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500850 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500851 int rc;
852
853 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500854 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500855 /* One additional decrement on node reference count to
856 * trigger the release of the node
857 */
James Smart329f9bc2007-04-25 09:53:01 -0400858 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500859 goto out;
860 }
861
James Smart858c9f62007-06-17 19:56:39 -0500862 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
863 "FLOGI cmpl: status:x%x/x%x state:x%x",
864 irsp->ulpStatus, irsp->un.ulpWord[4],
865 vport->port_state);
866
dea31012005-04-17 16:05:31 -0500867 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500868 /*
James Smarta93ff372010-10-22 11:06:08 -0400869 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500870 * due to new FCF discovery
871 */
872 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smartdbb6b3a2010-06-08 18:31:37 -0400873 (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
James Smart9589b062011-04-16 11:03:17 -0400874 !((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
875 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500876 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400877 "2611 FLOGI failed on FCF (x%x), "
878 "status:x%x/x%x, tmo:x%x, perform "
879 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -0400880 phba->fcf.current_rec.fcf_indx,
881 irsp->ulpStatus, irsp->un.ulpWord[4],
882 irsp->ulpTimeout);
James Smart0c9ab6f2010-02-26 14:15:57 -0500883 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -0400884 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
885 if (rc)
886 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500887 }
888
James Smart38b92ef2010-08-04 16:11:39 -0400889 /* FLOGI failure */
890 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
891 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
892 irsp->ulpStatus, irsp->un.ulpWord[4],
893 irsp->ulpTimeout);
894
dea31012005-04-17 16:05:31 -0500895 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500896 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500897 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500898
James Smart76a95d72010-11-20 23:11:48 -0500899 /* FLOGI failure */
900 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
901 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
902 irsp->ulpStatus, irsp->un.ulpWord[4],
903 irsp->ulpTimeout);
904
dea31012005-04-17 16:05:31 -0500905 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500906 spin_lock_irq(shost->host_lock);
907 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
908 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500909
James Smart329f9bc2007-04-25 09:53:01 -0400910 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500911 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
912 * alpa map would take too long otherwise.
913 */
914 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400915 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smart76a95d72010-11-20 23:11:48 -0500916 if ((phba->sli_rev == LPFC_SLI_REV4) &&
917 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
918 (vport->fc_prevDID != vport->fc_myDID))) {
919 if (vport->fc_flag & FC_VFI_REGISTERED)
920 lpfc_sli4_unreg_all_rpis(vport);
921 lpfc_issue_reg_vfi(vport);
922 lpfc_nlp_put(ndlp);
923 goto out;
924 }
dea31012005-04-17 16:05:31 -0500925 }
dea31012005-04-17 16:05:31 -0500926 goto flogifail;
927 }
James Smart695a8142010-01-26 23:08:03 -0500928 spin_lock_irq(shost->host_lock);
929 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400930 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500931 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500932
933 /*
934 * The FLogI succeeded. Sync the data for the CPU before
935 * accessing it.
936 */
937 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
938
939 sp = prsp->virt + sizeof(uint32_t);
940
941 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400942 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200943 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400944 "Data: x%x x%x x%x x%x\n",
945 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
946 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500947
James Smart2e0fef82007-06-17 19:56:36 -0500948 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500949 /*
950 * If Common Service Parameters indicate Nport
951 * we are point to point, if Fport we are Fabric.
952 */
953 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500954 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -0500955 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -0500956 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400957 else {
958 lpfc_printf_vlog(vport, KERN_ERR,
959 LOG_FIP | LOG_ELS,
960 "2831 FLOGI response with cleared Fabric "
961 "bit fcf_index 0x%x "
962 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
963 "Fabric Name "
964 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
965 phba->fcf.current_rec.fcf_indx,
966 phba->fcf.current_rec.switch_name[0],
967 phba->fcf.current_rec.switch_name[1],
968 phba->fcf.current_rec.switch_name[2],
969 phba->fcf.current_rec.switch_name[3],
970 phba->fcf.current_rec.switch_name[4],
971 phba->fcf.current_rec.switch_name[5],
972 phba->fcf.current_rec.switch_name[6],
973 phba->fcf.current_rec.switch_name[7],
974 phba->fcf.current_rec.fabric_name[0],
975 phba->fcf.current_rec.fabric_name[1],
976 phba->fcf.current_rec.fabric_name[2],
977 phba->fcf.current_rec.fabric_name[3],
978 phba->fcf.current_rec.fabric_name[4],
979 phba->fcf.current_rec.fabric_name[5],
980 phba->fcf.current_rec.fabric_name[6],
981 phba->fcf.current_rec.fabric_name[7]);
982 lpfc_nlp_put(ndlp);
983 spin_lock_irq(&phba->hbalock);
984 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400985 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -0400986 spin_unlock_irq(&phba->hbalock);
987 goto out;
988 }
James Smart0c9ab6f2010-02-26 14:15:57 -0500989 if (!rc) {
990 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400991 if (phba->hba_flag & HBA_FIP_SUPPORT)
992 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
993 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400994 "2769 FLOGI to FCF (x%x) "
995 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -0400996 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500997 spin_lock_irq(&phba->hbalock);
998 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400999 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -05001000 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001001 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001002 }
dea31012005-04-17 16:05:31 -05001003 }
1004
1005flogifail:
James Smart329f9bc2007-04-25 09:53:01 -04001006 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001007
James Smart858c9f62007-06-17 19:56:39 -05001008 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001009 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001010 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001011
1012 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001013 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001014 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1015 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
1016 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
1017 (phba->link_state != LPFC_CLEAR_LA)) {
1018 /* If FLOGI failed enable link interrupt. */
1019 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001020 }
dea31012005-04-17 16:05:31 -05001021out:
1022 lpfc_els_free_iocb(phba, cmdiocb);
1023}
1024
James Smarte59058c2008-08-24 21:49:00 -04001025/**
James Smart3621a712009-04-06 18:47:14 -04001026 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001027 * @vport: pointer to a host virtual N_Port data structure.
1028 * @ndlp: pointer to a node-list data structure.
1029 * @retry: number of retries to the command IOCB.
1030 *
1031 * This routine issues a Fabric Login (FLOGI) Request ELS command
1032 * for a @vport. The initiator service parameters are put into the payload
1033 * of the FLOGI Request IOCB and the top-level callback function pointer
1034 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1035 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1036 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1037 *
1038 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1039 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1040 * will be stored into the context1 field of the IOCB for the completion
1041 * callback function to the FLOGI ELS command.
1042 *
1043 * Return code
1044 * 0 - successfully issued flogi iocb for @vport
1045 * 1 - failed to issue flogi iocb for @vport
1046 **/
dea31012005-04-17 16:05:31 -05001047static int
James Smart2e0fef82007-06-17 19:56:36 -05001048lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001049 uint8_t retry)
1050{
James Smart2e0fef82007-06-17 19:56:36 -05001051 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001052 struct serv_parm *sp;
1053 IOCB_t *icmd;
1054 struct lpfc_iocbq *elsiocb;
1055 struct lpfc_sli_ring *pring;
1056 uint8_t *pcmd;
1057 uint16_t cmdsize;
1058 uint32_t tmo;
1059 int rc;
1060
1061 pring = &phba->sli.ring[LPFC_ELS_RING];
1062
James Smart92d7f7b2007-06-17 19:56:38 -05001063 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001064 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1065 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001066
James Smart488d1462006-03-07 15:02:37 -05001067 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001068 return 1;
dea31012005-04-17 16:05:31 -05001069
1070 icmd = &elsiocb->iocb;
1071 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1072
1073 /* For FLOGI request, remainder of payload is service parameters */
1074 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001075 pcmd += sizeof(uint32_t);
1076 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001077 sp = (struct serv_parm *) pcmd;
1078
1079 /* Setup CSPs accordingly for Fabric */
1080 sp->cmn.e_d_tov = 0;
1081 sp->cmn.w2.r_a_tov = 0;
1082 sp->cls1.classValid = 0;
1083 sp->cls2.seqDelivery = 1;
1084 sp->cls3.seqDelivery = 1;
1085 if (sp->cmn.fcphLow < FC_PH3)
1086 sp->cmn.fcphLow = FC_PH3;
1087 if (sp->cmn.fcphHigh < FC_PH3)
1088 sp->cmn.fcphHigh = FC_PH3;
1089
James Smartc31098c2011-04-16 11:03:33 -04001090 if (phba->sli_rev == LPFC_SLI_REV4) {
1091 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1092 LPFC_SLI_INTF_IF_TYPE_0) {
1093 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1094 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1095 /* FLOGI needs to be 3 for WQE FCFI */
1096 /* Set the fcfi to the fcfi we registered with */
1097 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1098 }
James Smart6fb120a2009-05-22 14:52:59 -04001099 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001100 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001101 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1102 icmd->ulpCt_h = 1;
1103 icmd->ulpCt_l = 0;
1104 }
1105
James Smart76a95d72010-11-20 23:11:48 -05001106 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001107 icmd->un.elsreq64.myID = 0;
1108 icmd->un.elsreq64.fl = 1;
1109 }
1110
dea31012005-04-17 16:05:31 -05001111 tmo = phba->fc_ratov;
1112 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001113 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001114 phba->fc_ratov = tmo;
1115
1116 phba->fc_stat.elsXmitFLOGI++;
1117 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001118
1119 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1120 "Issue FLOGI: opt:x%x",
1121 phba->sli3_options, 0, 0);
1122
James Smart92d7f7b2007-06-17 19:56:38 -05001123 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001124 if (rc == IOCB_ERROR) {
1125 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001126 return 1;
dea31012005-04-17 16:05:31 -05001127 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001128 return 0;
dea31012005-04-17 16:05:31 -05001129}
1130
James Smarte59058c2008-08-24 21:49:00 -04001131/**
James Smart3621a712009-04-06 18:47:14 -04001132 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001133 * @phba: pointer to lpfc hba data structure.
1134 *
1135 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1136 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1137 * list and issues an abort IOCB commond on each outstanding IOCB that
1138 * contains a active Fabric_DID ndlp. Note that this function is to issue
1139 * the abort IOCB command on all the outstanding IOCBs, thus when this
1140 * function returns, it does not guarantee all the IOCBs are actually aborted.
1141 *
1142 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001143 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001144 **/
dea31012005-04-17 16:05:31 -05001145int
James Smart2e0fef82007-06-17 19:56:36 -05001146lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001147{
1148 struct lpfc_sli_ring *pring;
1149 struct lpfc_iocbq *iocb, *next_iocb;
1150 struct lpfc_nodelist *ndlp;
1151 IOCB_t *icmd;
1152
1153 /* Abort outstanding I/O on NPort <nlp_DID> */
1154 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001155 "0201 Abort outstanding I/O on NPort x%x\n",
1156 Fabric_DID);
dea31012005-04-17 16:05:31 -05001157
1158 pring = &phba->sli.ring[LPFC_ELS_RING];
1159
1160 /*
1161 * Check the txcmplq for an iocb that matches the nport the driver is
1162 * searching for.
1163 */
James Smart2e0fef82007-06-17 19:56:36 -05001164 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001165 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1166 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001167 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1168 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001169 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001170 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1171 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001172 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001173 }
1174 }
James Smart2e0fef82007-06-17 19:56:36 -05001175 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001176
1177 return 0;
1178}
1179
James Smarte59058c2008-08-24 21:49:00 -04001180/**
James Smart3621a712009-04-06 18:47:14 -04001181 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001182 * @vport: pointer to a host virtual N_Port data structure.
1183 *
1184 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1185 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1186 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1187 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1188 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1189 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1190 * @vport.
1191 *
1192 * Return code
1193 * 0 - failed to issue initial flogi for @vport
1194 * 1 - successfully issued initial flogi for @vport
1195 **/
dea31012005-04-17 16:05:31 -05001196int
James Smart2e0fef82007-06-17 19:56:36 -05001197lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001198{
James Smart2e0fef82007-06-17 19:56:36 -05001199 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001200 struct lpfc_nodelist *ndlp;
1201
James Smart98c9ea52007-10-27 13:37:33 -04001202 vport->port_state = LPFC_FLOGI;
1203 lpfc_set_disctmo(vport);
1204
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001205 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001206 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001207 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001208 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001209 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1210 if (!ndlp)
1211 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001212 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001213 /* Set the node type */
1214 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001215 /* Put ndlp onto node list */
1216 lpfc_enqueue_node(vport, ndlp);
1217 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1218 /* re-setup ndlp without removing from node list */
1219 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1220 if (!ndlp)
1221 return 0;
dea31012005-04-17 16:05:31 -05001222 }
James Smart87af33f2007-10-27 13:37:43 -04001223
James Smart5ac6b302010-10-22 11:05:36 -04001224 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001225 /* This decrement of reference count to node shall kick off
1226 * the release of the node.
1227 */
James Smart329f9bc2007-04-25 09:53:01 -04001228 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001229 return 0;
1230 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001231 return 1;
dea31012005-04-17 16:05:31 -05001232}
1233
James Smarte59058c2008-08-24 21:49:00 -04001234/**
James Smart3621a712009-04-06 18:47:14 -04001235 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001236 * @vport: pointer to a host virtual N_Port data structure.
1237 *
1238 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1239 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1240 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1241 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1242 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1243 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1244 * @vport.
1245 *
1246 * Return code
1247 * 0 - failed to issue initial fdisc for @vport
1248 * 1 - successfully issued initial fdisc for @vport
1249 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001250int
1251lpfc_initial_fdisc(struct lpfc_vport *vport)
1252{
1253 struct lpfc_hba *phba = vport->phba;
1254 struct lpfc_nodelist *ndlp;
1255
1256 /* First look for the Fabric ndlp */
1257 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1258 if (!ndlp) {
1259 /* Cannot find existing Fabric ndlp, so allocate a new one */
1260 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1261 if (!ndlp)
1262 return 0;
1263 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001264 /* Put ndlp onto node list */
1265 lpfc_enqueue_node(vport, ndlp);
1266 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1267 /* re-setup ndlp without removing from node list */
1268 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1269 if (!ndlp)
1270 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001271 }
James Smarte47c9092008-02-08 18:49:26 -05001272
James Smart92d7f7b2007-06-17 19:56:38 -05001273 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001274 /* decrement node reference count to trigger the release of
1275 * the node.
1276 */
James Smart92d7f7b2007-06-17 19:56:38 -05001277 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001278 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001279 }
1280 return 1;
1281}
James Smart87af33f2007-10-27 13:37:43 -04001282
James Smarte59058c2008-08-24 21:49:00 -04001283/**
James Smart3621a712009-04-06 18:47:14 -04001284 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001285 * @vport: pointer to a host virtual N_Port data structure.
1286 *
1287 * This routine checks whether there are more remaining Port Logins
1288 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1289 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1290 * to issue ELS PLOGIs up to the configured discover threads with the
1291 * @vport (@vport->cfg_discovery_threads). The function also decrement
1292 * the @vport's num_disc_node by 1 if it is not already 0.
1293 **/
James Smart87af33f2007-10-27 13:37:43 -04001294void
James Smart2e0fef82007-06-17 19:56:36 -05001295lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001296{
1297 int sentplogi;
1298
James Smart2e0fef82007-06-17 19:56:36 -05001299 if (vport->num_disc_nodes)
1300 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001301
1302 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001303 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1304 "0232 Continue discovery with %d PLOGIs to go "
1305 "Data: x%x x%x x%x\n",
1306 vport->num_disc_nodes, vport->fc_plogi_cnt,
1307 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001308 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001309 if (vport->fc_flag & FC_NLP_MORE)
1310 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1311 sentplogi = lpfc_els_disc_plogi(vport);
1312
dea31012005-04-17 16:05:31 -05001313 return;
1314}
1315
James Smarte59058c2008-08-24 21:49:00 -04001316/**
James Smart3621a712009-04-06 18:47:14 -04001317 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001318 * @phba: pointer to lpfc hba data structure.
1319 * @prsp: pointer to response IOCB payload.
1320 * @ndlp: pointer to a node-list data structure.
1321 *
1322 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1323 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1324 * The following cases are considered N_Port confirmed:
1325 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1326 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1327 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1328 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1329 * 1) if there is a node on vport list other than the @ndlp with the same
1330 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1331 * on that node to release the RPI associated with the node; 2) if there is
1332 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1333 * into, a new node shall be allocated (or activated). In either case, the
1334 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1335 * be released and the new_ndlp shall be put on to the vport node list and
1336 * its pointer returned as the confirmed node.
1337 *
1338 * Note that before the @ndlp got "released", the keepDID from not-matching
1339 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1340 * of the @ndlp. This is because the release of @ndlp is actually to put it
1341 * into an inactive state on the vport node list and the vport node list
1342 * management algorithm does not allow two node with a same DID.
1343 *
1344 * Return code
1345 * pointer to the PLOGI N_Port @ndlp
1346 **/
James Smart488d1462006-03-07 15:02:37 -05001347static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001348lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001349 struct lpfc_nodelist *ndlp)
1350{
James Smart2e0fef82007-06-17 19:56:36 -05001351 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001352 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001353 struct lpfc_rport_data *rdata;
1354 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001355 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001356 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001357 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001358 int put_node;
1359 int put_rport;
James Smart19ca7602010-11-20 23:11:55 -05001360 struct lpfc_node_rrqs rrq;
James Smart488d1462006-03-07 15:02:37 -05001361
James Smart2fb9bd82006-12-02 13:33:57 -05001362 /* Fabric nodes can have the same WWPN so we don't bother searching
1363 * by WWPN. Just return the ndlp that was given to us.
1364 */
1365 if (ndlp->nlp_type & NLP_FABRIC)
1366 return ndlp;
1367
James Smart92d7f7b2007-06-17 19:56:38 -05001368 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001369 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001370
James Smart685f0bf2007-04-25 09:53:08 -04001371 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001372 * we have for that ndlp. If not, we have some work to do.
1373 */
James Smart2e0fef82007-06-17 19:56:36 -05001374 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001375
James Smarte47c9092008-02-08 18:49:26 -05001376 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001377 return ndlp;
James Smart19ca7602010-11-20 23:11:55 -05001378 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
James Smart488d1462006-03-07 15:02:37 -05001379
1380 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001381 rc = memcmp(&ndlp->nlp_portname, name,
1382 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001383 if (!rc)
1384 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001385 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1386 if (!new_ndlp)
1387 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001388 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001389 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001390 rc = memcmp(&ndlp->nlp_portname, name,
1391 sizeof(struct lpfc_name));
1392 if (!rc)
1393 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001394 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1395 NLP_STE_UNUSED_NODE);
1396 if (!new_ndlp)
1397 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001398 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001399 if (phba->sli_rev == LPFC_SLI_REV4)
1400 memcpy(&rrq.xri_bitmap,
1401 &new_ndlp->active_rrqs.xri_bitmap,
1402 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1403 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001404 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001405 if (phba->sli_rev == LPFC_SLI_REV4)
1406 memcpy(&rrq.xri_bitmap,
1407 &new_ndlp->active_rrqs.xri_bitmap,
1408 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1409 }
James Smart488d1462006-03-07 15:02:37 -05001410
James Smart2e0fef82007-06-17 19:56:36 -05001411 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001412 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001413 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001414 if (phba->sli_rev == LPFC_SLI_REV4)
1415 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1416 &ndlp->active_rrqs.xri_bitmap,
1417 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart0ff10d42008-01-11 01:52:36 -05001418
1419 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1420 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1421 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1422
James Smarte47c9092008-02-08 18:49:26 -05001423 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001424 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001425
James Smart2e0fef82007-06-17 19:56:36 -05001426 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001427 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1428 /* The new_ndlp is replacing ndlp totally, so we need
1429 * to put ndlp on UNUSED list and try to free it.
1430 */
James Smart0ff10d42008-01-11 01:52:36 -05001431
1432 /* Fix up the rport accordingly */
1433 rport = ndlp->rport;
1434 if (rport) {
1435 rdata = rport->dd_data;
1436 if (rdata->pnode == ndlp) {
1437 lpfc_nlp_put(ndlp);
1438 ndlp->rport = NULL;
1439 rdata->pnode = lpfc_nlp_get(new_ndlp);
1440 new_ndlp->rport = rport;
1441 }
1442 new_ndlp->nlp_type = ndlp->nlp_type;
1443 }
James Smart58da1ff2008-04-07 10:15:56 -04001444 /* We shall actually free the ndlp with both nlp_DID and
1445 * nlp_portname fields equals 0 to avoid any ndlp on the
1446 * nodelist never to be used.
1447 */
1448 if (ndlp->nlp_DID == 0) {
1449 spin_lock_irq(&phba->ndlp_lock);
1450 NLP_SET_FREE_REQ(ndlp);
1451 spin_unlock_irq(&phba->ndlp_lock);
1452 }
James Smart0ff10d42008-01-11 01:52:36 -05001453
James Smart58da1ff2008-04-07 10:15:56 -04001454 /* Two ndlps cannot have the same did on the nodelist */
1455 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001456 if (phba->sli_rev == LPFC_SLI_REV4)
1457 memcpy(&ndlp->active_rrqs.xri_bitmap,
1458 &rrq.xri_bitmap,
1459 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001460 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001461 }
James Smart92795652006-07-06 15:50:02 -04001462 else {
James Smart2e0fef82007-06-17 19:56:36 -05001463 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001464 /* Two ndlps cannot have the same did */
1465 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001466 if (phba->sli_rev == LPFC_SLI_REV4)
1467 memcpy(&ndlp->active_rrqs.xri_bitmap,
1468 &rrq.xri_bitmap,
1469 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001470 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart38b92ef2010-08-04 16:11:39 -04001471 /* Since we are swapping the ndlp passed in with the new one
1472 * and the did has already been swapped, copy over the
1473 * state and names.
1474 */
1475 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1476 sizeof(struct lpfc_name));
1477 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1478 sizeof(struct lpfc_name));
1479 new_ndlp->nlp_state = ndlp->nlp_state;
1480 /* Fix up the rport accordingly */
1481 rport = ndlp->rport;
1482 if (rport) {
1483 rdata = rport->dd_data;
1484 put_node = rdata->pnode != NULL;
1485 put_rport = ndlp->rport != NULL;
1486 rdata->pnode = NULL;
1487 ndlp->rport = NULL;
1488 if (put_node)
1489 lpfc_nlp_put(ndlp);
1490 if (put_rport)
1491 put_device(&rport->dev);
1492 }
James Smart92795652006-07-06 15:50:02 -04001493 }
James Smart488d1462006-03-07 15:02:37 -05001494 return new_ndlp;
1495}
1496
James Smarte59058c2008-08-24 21:49:00 -04001497/**
James Smart3621a712009-04-06 18:47:14 -04001498 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001499 * @vport: pointer to a host virtual N_Port data structure.
1500 *
1501 * This routine checks whether more Registration State Change
1502 * Notifications (RSCNs) came in while the discovery state machine was in
1503 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1504 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1505 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1506 * handling the RSCNs.
1507 **/
James Smart87af33f2007-10-27 13:37:43 -04001508void
1509lpfc_end_rscn(struct lpfc_vport *vport)
1510{
1511 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1512
1513 if (vport->fc_flag & FC_RSCN_MODE) {
1514 /*
1515 * Check to see if more RSCNs came in while we were
1516 * processing this one.
1517 */
1518 if (vport->fc_rscn_id_cnt ||
1519 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1520 lpfc_els_handle_rscn(vport);
1521 else {
1522 spin_lock_irq(shost->host_lock);
1523 vport->fc_flag &= ~FC_RSCN_MODE;
1524 spin_unlock_irq(shost->host_lock);
1525 }
1526 }
1527}
1528
James Smarte59058c2008-08-24 21:49:00 -04001529/**
James Smart19ca7602010-11-20 23:11:55 -05001530 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1531 * @phba: pointer to lpfc hba data structure.
1532 * @cmdiocb: pointer to lpfc command iocb data structure.
1533 * @rspiocb: pointer to lpfc response iocb data structure.
1534 *
1535 * This routine will call the clear rrq function to free the rrq and
1536 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1537 * exist then the clear_rrq is still called because the rrq needs to
1538 * be freed.
1539 **/
1540
1541static void
1542lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1543 struct lpfc_iocbq *rspiocb)
1544{
1545 struct lpfc_vport *vport = cmdiocb->vport;
1546 IOCB_t *irsp;
1547 struct lpfc_nodelist *ndlp;
1548 struct lpfc_node_rrq *rrq;
1549
1550 /* we pass cmdiocb to state machine which needs rspiocb as well */
1551 rrq = cmdiocb->context_un.rrq;
1552 cmdiocb->context_un.rsp_iocb = rspiocb;
1553
1554 irsp = &rspiocb->iocb;
1555 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1556 "RRQ cmpl: status:x%x/x%x did:x%x",
1557 irsp->ulpStatus, irsp->un.ulpWord[4],
1558 irsp->un.elsreq64.remoteID);
1559
1560 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1561 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1562 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1563 "2882 RRQ completes to NPort x%x "
1564 "with no ndlp. Data: x%x x%x x%x\n",
1565 irsp->un.elsreq64.remoteID,
1566 irsp->ulpStatus, irsp->un.ulpWord[4],
1567 irsp->ulpIoTag);
1568 goto out;
1569 }
1570
1571 /* rrq completes to NPort <nlp_DID> */
1572 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1573 "2880 RRQ completes to NPort x%x "
1574 "Data: x%x x%x x%x x%x x%x\n",
1575 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1576 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1577
1578 if (irsp->ulpStatus) {
1579 /* Check for retry */
1580 /* RRQ failed Don't print the vport to vport rjts */
1581 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1582 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1583 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1584 (phba)->pport->cfg_log_verbose & LOG_ELS)
1585 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1586 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1587 ndlp->nlp_DID, irsp->ulpStatus,
1588 irsp->un.ulpWord[4]);
1589 }
1590out:
1591 if (rrq)
1592 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1593 lpfc_els_free_iocb(phba, cmdiocb);
1594 return;
1595}
1596/**
James Smart3621a712009-04-06 18:47:14 -04001597 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001598 * @phba: pointer to lpfc hba data structure.
1599 * @cmdiocb: pointer to lpfc command iocb data structure.
1600 * @rspiocb: pointer to lpfc response iocb data structure.
1601 *
1602 * This routine is the completion callback function for issuing the Port
1603 * Login (PLOGI) command. For PLOGI completion, there must be an active
1604 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001605 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001606 * ignored and command IOCB released. The PLOGI response IOCB status is
1607 * checked for error conditons. If there is error status reported, PLOGI
1608 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1609 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1610 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1611 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1612 * there are additional N_Port nodes with the vport that need to perform
1613 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1614 * PLOGIs.
1615 **/
dea31012005-04-17 16:05:31 -05001616static void
James Smart2e0fef82007-06-17 19:56:36 -05001617lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1618 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001619{
James Smart2e0fef82007-06-17 19:56:36 -05001620 struct lpfc_vport *vport = cmdiocb->vport;
1621 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001622 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001623 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001624 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001625 int disc, rc, did, type;
1626
dea31012005-04-17 16:05:31 -05001627 /* we pass cmdiocb to state machine which needs rspiocb as well */
1628 cmdiocb->context_un.rsp_iocb = rspiocb;
1629
1630 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001631 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1632 "PLOGI cmpl: status:x%x/x%x did:x%x",
1633 irsp->ulpStatus, irsp->un.ulpWord[4],
1634 irsp->un.elsreq64.remoteID);
1635
James Smart2e0fef82007-06-17 19:56:36 -05001636 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001637 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001638 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1639 "0136 PLOGI completes to NPort x%x "
1640 "with no ndlp. Data: x%x x%x x%x\n",
1641 irsp->un.elsreq64.remoteID,
1642 irsp->ulpStatus, irsp->un.ulpWord[4],
1643 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001644 goto out;
James Smarted957682007-06-17 19:56:37 -05001645 }
dea31012005-04-17 16:05:31 -05001646
1647 /* Since ndlp can be freed in the disc state machine, note if this node
1648 * is being used during discovery.
1649 */
James Smart2e0fef82007-06-17 19:56:36 -05001650 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001651 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001652 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001653 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001654 rc = 0;
1655
1656 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001657 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1658 "0102 PLOGI completes to NPort x%x "
1659 "Data: x%x x%x x%x x%x x%x\n",
1660 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1661 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001662 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001663 if (lpfc_els_chk_latt(vport)) {
1664 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001665 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001666 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001667 goto out;
1668 }
1669
1670 /* ndlp could be freed in DSM, save these values now */
1671 type = ndlp->nlp_type;
1672 did = ndlp->nlp_DID;
1673
1674 if (irsp->ulpStatus) {
1675 /* Check for retry */
1676 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1677 /* ELS command is being retried */
1678 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001679 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001680 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001681 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001682 }
1683 goto out;
1684 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001685 /* PLOGI failed Don't print the vport to vport rjts */
1686 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1687 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1688 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1689 (phba)->pport->cfg_log_verbose & LOG_ELS)
1690 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001691 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1692 ndlp->nlp_DID, irsp->ulpStatus,
1693 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001694 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001695 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001696 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001697 else
James Smart2e0fef82007-06-17 19:56:36 -05001698 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001699 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001700 } else {
1701 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001702 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001703 cmdiocb->context2)->list.next,
1704 struct lpfc_dmabuf, list);
1705 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001706 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001707 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001708 }
1709
James Smart2e0fef82007-06-17 19:56:36 -05001710 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001711 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001712 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001713
James Smart2e0fef82007-06-17 19:56:36 -05001714 if (vport->num_disc_nodes == 0) {
1715 spin_lock_irq(shost->host_lock);
1716 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1717 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001718
James Smart2e0fef82007-06-17 19:56:36 -05001719 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001720 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001721 }
1722 }
1723
1724out:
1725 lpfc_els_free_iocb(phba, cmdiocb);
1726 return;
1727}
1728
James Smarte59058c2008-08-24 21:49:00 -04001729/**
James Smart3621a712009-04-06 18:47:14 -04001730 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001731 * @vport: pointer to a host virtual N_Port data structure.
1732 * @did: destination port identifier.
1733 * @retry: number of retries to the command IOCB.
1734 *
1735 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1736 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1737 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1738 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1739 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1740 *
1741 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1742 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1743 * will be stored into the context1 field of the IOCB for the completion
1744 * callback function to the PLOGI ELS command.
1745 *
1746 * Return code
1747 * 0 - Successfully issued a plogi for @vport
1748 * 1 - failed to issue a plogi for @vport
1749 **/
dea31012005-04-17 16:05:31 -05001750int
James Smart2e0fef82007-06-17 19:56:36 -05001751lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001752{
James Smart2e0fef82007-06-17 19:56:36 -05001753 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001754 struct serv_parm *sp;
1755 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001756 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001757 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001758 struct lpfc_sli *psli;
1759 uint8_t *pcmd;
1760 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001761 int ret;
dea31012005-04-17 16:05:31 -05001762
1763 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001764
James Smart98c9ea52007-10-27 13:37:33 -04001765 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001766 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1767 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001768
James Smarte47c9092008-02-08 18:49:26 -05001769 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001770 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001771 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001772 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001773 if (!elsiocb)
1774 return 1;
dea31012005-04-17 16:05:31 -05001775
1776 icmd = &elsiocb->iocb;
1777 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1778
1779 /* For PLOGI request, remainder of payload is service parameters */
1780 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001781 pcmd += sizeof(uint32_t);
1782 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001783 sp = (struct serv_parm *) pcmd;
1784
James Smart5ac6b302010-10-22 11:05:36 -04001785 /*
1786 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1787 * to device on remote loops work.
1788 */
1789 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1790 sp->cmn.altBbCredit = 1;
1791
dea31012005-04-17 16:05:31 -05001792 if (sp->cmn.fcphLow < FC_PH_4_3)
1793 sp->cmn.fcphLow = FC_PH_4_3;
1794
1795 if (sp->cmn.fcphHigh < FC_PH3)
1796 sp->cmn.fcphHigh = FC_PH3;
1797
James Smart858c9f62007-06-17 19:56:39 -05001798 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1799 "Issue PLOGI: did:x%x",
1800 did, 0, 0);
1801
dea31012005-04-17 16:05:31 -05001802 phba->fc_stat.elsXmitPLOGI++;
1803 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001804 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001805
1806 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001807 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001808 return 1;
dea31012005-04-17 16:05:31 -05001809 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001810 return 0;
dea31012005-04-17 16:05:31 -05001811}
1812
James Smarte59058c2008-08-24 21:49:00 -04001813/**
James Smart3621a712009-04-06 18:47:14 -04001814 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001815 * @phba: pointer to lpfc hba data structure.
1816 * @cmdiocb: pointer to lpfc command iocb data structure.
1817 * @rspiocb: pointer to lpfc response iocb data structure.
1818 *
1819 * This routine is the completion callback function for a Process Login
1820 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1821 * status. If there is error status reported, PRLI retry shall be attempted
1822 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1823 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1824 * ndlp to mark the PRLI completion.
1825 **/
dea31012005-04-17 16:05:31 -05001826static void
James Smart2e0fef82007-06-17 19:56:36 -05001827lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1828 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001829{
James Smart2e0fef82007-06-17 19:56:36 -05001830 struct lpfc_vport *vport = cmdiocb->vport;
1831 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001832 IOCB_t *irsp;
1833 struct lpfc_sli *psli;
1834 struct lpfc_nodelist *ndlp;
1835
1836 psli = &phba->sli;
1837 /* we pass cmdiocb to state machine which needs rspiocb as well */
1838 cmdiocb->context_un.rsp_iocb = rspiocb;
1839
1840 irsp = &(rspiocb->iocb);
1841 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001842 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001843 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001844 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001845
James Smart858c9f62007-06-17 19:56:39 -05001846 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1847 "PRLI cmpl: status:x%x/x%x did:x%x",
1848 irsp->ulpStatus, irsp->un.ulpWord[4],
1849 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001850 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001851 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1852 "0103 PRLI completes to NPort x%x "
1853 "Data: x%x x%x x%x x%x\n",
1854 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1855 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001856
James Smart2e0fef82007-06-17 19:56:36 -05001857 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001858 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001859 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001860 goto out;
1861
1862 if (irsp->ulpStatus) {
1863 /* Check for retry */
1864 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1865 /* ELS command is being retried */
1866 goto out;
1867 }
1868 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001869 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1870 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1871 ndlp->nlp_DID, irsp->ulpStatus,
1872 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001873 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001874 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001875 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001876 else
James Smart2e0fef82007-06-17 19:56:36 -05001877 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001878 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001879 } else
dea31012005-04-17 16:05:31 -05001880 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001881 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001882 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001883out:
1884 lpfc_els_free_iocb(phba, cmdiocb);
1885 return;
1886}
1887
James Smarte59058c2008-08-24 21:49:00 -04001888/**
James Smart3621a712009-04-06 18:47:14 -04001889 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001890 * @vport: pointer to a host virtual N_Port data structure.
1891 * @ndlp: pointer to a node-list data structure.
1892 * @retry: number of retries to the command IOCB.
1893 *
1894 * This routine issues a Process Login (PRLI) ELS command for the
1895 * @vport. The PRLI service parameters are set up in the payload of the
1896 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1897 * is put to the IOCB completion callback func field before invoking the
1898 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1899 *
1900 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1901 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1902 * will be stored into the context1 field of the IOCB for the completion
1903 * callback function to the PRLI ELS command.
1904 *
1905 * Return code
1906 * 0 - successfully issued prli iocb command for @vport
1907 * 1 - failed to issue prli iocb command for @vport
1908 **/
dea31012005-04-17 16:05:31 -05001909int
James Smart2e0fef82007-06-17 19:56:36 -05001910lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001911 uint8_t retry)
1912{
James Smart2e0fef82007-06-17 19:56:36 -05001913 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1914 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001915 PRLI *npr;
1916 IOCB_t *icmd;
1917 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001918 uint8_t *pcmd;
1919 uint16_t cmdsize;
1920
James Smart92d7f7b2007-06-17 19:56:38 -05001921 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001922 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1923 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001924 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001925 return 1;
dea31012005-04-17 16:05:31 -05001926
1927 icmd = &elsiocb->iocb;
1928 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1929
1930 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001931 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001932 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001933 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001934
1935 /* For PRLI, remainder of payload is PRLI parameter page */
1936 npr = (PRLI *) pcmd;
1937 /*
1938 * If our firmware version is 3.20 or later,
1939 * set the following bits for FC-TAPE support.
1940 */
1941 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1942 npr->ConfmComplAllowed = 1;
1943 npr->Retry = 1;
1944 npr->TaskRetryIdReq = 1;
1945 }
1946 npr->estabImagePair = 1;
1947 npr->readXferRdyDis = 1;
1948
1949 /* For FCP support */
1950 npr->prliType = PRLI_FCP_TYPE;
1951 npr->initiatorFunc = 1;
1952
James Smart858c9f62007-06-17 19:56:39 -05001953 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1954 "Issue PRLI: did:x%x",
1955 ndlp->nlp_DID, 0, 0);
1956
dea31012005-04-17 16:05:31 -05001957 phba->fc_stat.elsXmitPRLI++;
1958 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001959 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001960 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001961 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001962 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1963 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001964 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001965 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001966 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001967 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001968 return 1;
dea31012005-04-17 16:05:31 -05001969 }
James Smart2e0fef82007-06-17 19:56:36 -05001970 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001971 return 0;
dea31012005-04-17 16:05:31 -05001972}
1973
James Smarte59058c2008-08-24 21:49:00 -04001974/**
James Smart3621a712009-04-06 18:47:14 -04001975 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001976 * @vport: pointer to a host virtual N_Port data structure.
1977 *
1978 * This routine performs Registration State Change Notification (RSCN)
1979 * discovery for a @vport. If the @vport's node port recovery count is not
1980 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1981 * the nodes that need recovery. If none of the PLOGI were needed through
1982 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1983 * invoked to check and handle possible more RSCN came in during the period
1984 * of processing the current ones.
1985 **/
1986static void
1987lpfc_rscn_disc(struct lpfc_vport *vport)
1988{
1989 lpfc_can_disctmo(vport);
1990
1991 /* RSCN discovery */
1992 /* go thru NPR nodes and issue ELS PLOGIs */
1993 if (vport->fc_npr_cnt)
1994 if (lpfc_els_disc_plogi(vport))
1995 return;
1996
1997 lpfc_end_rscn(vport);
1998}
1999
2000/**
James Smart3621a712009-04-06 18:47:14 -04002001 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002002 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2003 *
2004 * This function is called when the final ADISC is completed during discovery.
2005 * This function handles clearing link attention or issuing reg_vpi depending
2006 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2007 * discovery.
2008 * This function is called with no locks held.
2009 **/
2010static void
2011lpfc_adisc_done(struct lpfc_vport *vport)
2012{
2013 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2014 struct lpfc_hba *phba = vport->phba;
2015
2016 /*
2017 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2018 * and continue discovery.
2019 */
2020 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002021 !(vport->fc_flag & FC_RSCN_MODE) &&
2022 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04002023 lpfc_issue_reg_vpi(phba, vport);
2024 return;
2025 }
2026 /*
2027 * For SLI2, we need to set port_state to READY
2028 * and continue discovery.
2029 */
2030 if (vport->port_state < LPFC_VPORT_READY) {
2031 /* If we get here, there is nothing to ADISC */
2032 if (vport->port_type == LPFC_PHYSICAL_PORT)
2033 lpfc_issue_clear_la(phba, vport);
2034 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2035 vport->num_disc_nodes = 0;
2036 /* go thru NPR list, issue ELS PLOGIs */
2037 if (vport->fc_npr_cnt)
2038 lpfc_els_disc_plogi(vport);
2039 if (!vport->num_disc_nodes) {
2040 spin_lock_irq(shost->host_lock);
2041 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2042 spin_unlock_irq(shost->host_lock);
2043 lpfc_can_disctmo(vport);
2044 lpfc_end_rscn(vport);
2045 }
2046 }
2047 vport->port_state = LPFC_VPORT_READY;
2048 } else
2049 lpfc_rscn_disc(vport);
2050}
2051
2052/**
James Smart3621a712009-04-06 18:47:14 -04002053 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002054 * @vport: pointer to a host virtual N_Port data structure.
2055 *
2056 * This routine determines whether there are more ndlps on a @vport
2057 * node list need to have Address Discover (ADISC) issued. If so, it will
2058 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2059 * remaining nodes which need to have ADISC sent.
2060 **/
James Smart0ff10d42008-01-11 01:52:36 -05002061void
James Smart2e0fef82007-06-17 19:56:36 -05002062lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002063{
2064 int sentadisc;
2065
James Smart2e0fef82007-06-17 19:56:36 -05002066 if (vport->num_disc_nodes)
2067 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002068 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002069 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2070 "0210 Continue discovery with %d ADISCs to go "
2071 "Data: x%x x%x x%x\n",
2072 vport->num_disc_nodes, vport->fc_adisc_cnt,
2073 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002074 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002075 if (vport->fc_flag & FC_NLP_MORE) {
2076 lpfc_set_disctmo(vport);
2077 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2078 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002079 }
James Smart90160e02008-08-24 21:49:45 -04002080 if (!vport->num_disc_nodes)
2081 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002082 return;
2083}
2084
James Smarte59058c2008-08-24 21:49:00 -04002085/**
James Smart3621a712009-04-06 18:47:14 -04002086 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002087 * @phba: pointer to lpfc hba data structure.
2088 * @cmdiocb: pointer to lpfc command iocb data structure.
2089 * @rspiocb: pointer to lpfc response iocb data structure.
2090 *
2091 * This routine is the completion function for issuing the Address Discover
2092 * (ADISC) command. It first checks to see whether link went down during
2093 * the discovery process. If so, the node will be marked as node port
2094 * recovery for issuing discover IOCB by the link attention handler and
2095 * exit. Otherwise, the response status is checked. If error was reported
2096 * in the response status, the ADISC command shall be retried by invoking
2097 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2098 * the response status, the state machine is invoked to set transition
2099 * with respect to NLP_EVT_CMPL_ADISC event.
2100 **/
dea31012005-04-17 16:05:31 -05002101static void
James Smart2e0fef82007-06-17 19:56:36 -05002102lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2103 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002104{
James Smart2e0fef82007-06-17 19:56:36 -05002105 struct lpfc_vport *vport = cmdiocb->vport;
2106 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002107 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002108 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002109 int disc;
dea31012005-04-17 16:05:31 -05002110
2111 /* we pass cmdiocb to state machine which needs rspiocb as well */
2112 cmdiocb->context_un.rsp_iocb = rspiocb;
2113
2114 irsp = &(rspiocb->iocb);
2115 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002116
James Smart858c9f62007-06-17 19:56:39 -05002117 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2118 "ADISC cmpl: status:x%x/x%x did:x%x",
2119 irsp->ulpStatus, irsp->un.ulpWord[4],
2120 ndlp->nlp_DID);
2121
dea31012005-04-17 16:05:31 -05002122 /* Since ndlp can be freed in the disc state machine, note if this node
2123 * is being used during discovery.
2124 */
James Smart2e0fef82007-06-17 19:56:36 -05002125 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002126 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002127 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002128 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002129 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002130 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2131 "0104 ADISC completes to NPort x%x "
2132 "Data: x%x x%x x%x x%x x%x\n",
2133 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2134 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002135 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002136 if (lpfc_els_chk_latt(vport)) {
2137 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002138 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002139 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002140 goto out;
2141 }
2142
2143 if (irsp->ulpStatus) {
2144 /* Check for retry */
2145 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2146 /* ELS command is being retried */
2147 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002148 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002149 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002150 spin_unlock_irq(shost->host_lock);
2151 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002152 }
2153 goto out;
2154 }
2155 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002156 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2157 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2158 ndlp->nlp_DID, irsp->ulpStatus,
2159 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002160 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002161 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002162 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002163 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002164 } else
dea31012005-04-17 16:05:31 -05002165 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002166 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002167 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002168
James Smart90160e02008-08-24 21:49:45 -04002169 /* Check to see if there are more ADISCs to be sent */
2170 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002171 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002172out:
2173 lpfc_els_free_iocb(phba, cmdiocb);
2174 return;
2175}
2176
James Smarte59058c2008-08-24 21:49:00 -04002177/**
James Smart3621a712009-04-06 18:47:14 -04002178 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002179 * @vport: pointer to a virtual N_Port data structure.
2180 * @ndlp: pointer to a node-list data structure.
2181 * @retry: number of retries to the command IOCB.
2182 *
2183 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2184 * @vport. It prepares the payload of the ADISC ELS command, updates the
2185 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2186 * to issue the ADISC ELS command.
2187 *
2188 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2189 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2190 * will be stored into the context1 field of the IOCB for the completion
2191 * callback function to the ADISC ELS command.
2192 *
2193 * Return code
2194 * 0 - successfully issued adisc
2195 * 1 - failed to issue adisc
2196 **/
dea31012005-04-17 16:05:31 -05002197int
James Smart2e0fef82007-06-17 19:56:36 -05002198lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002199 uint8_t retry)
2200{
James Smart2e0fef82007-06-17 19:56:36 -05002201 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2202 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002203 ADISC *ap;
2204 IOCB_t *icmd;
2205 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002206 uint8_t *pcmd;
2207 uint16_t cmdsize;
2208
James Smart92d7f7b2007-06-17 19:56:38 -05002209 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002210 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2211 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002212 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002213 return 1;
dea31012005-04-17 16:05:31 -05002214
2215 icmd = &elsiocb->iocb;
2216 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2217
2218 /* For ADISC request, remainder of payload is service parameters */
2219 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002220 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002221
2222 /* Fill in ADISC payload */
2223 ap = (ADISC *) pcmd;
2224 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002225 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2226 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002227 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002228
James Smart858c9f62007-06-17 19:56:39 -05002229 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2230 "Issue ADISC: did:x%x",
2231 ndlp->nlp_DID, 0, 0);
2232
dea31012005-04-17 16:05:31 -05002233 phba->fc_stat.elsXmitADISC++;
2234 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002235 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002236 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002237 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002238 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2239 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002240 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002241 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002242 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002243 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002244 return 1;
dea31012005-04-17 16:05:31 -05002245 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002246 return 0;
dea31012005-04-17 16:05:31 -05002247}
2248
James Smarte59058c2008-08-24 21:49:00 -04002249/**
James Smart3621a712009-04-06 18:47:14 -04002250 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002251 * @phba: pointer to lpfc hba data structure.
2252 * @cmdiocb: pointer to lpfc command iocb data structure.
2253 * @rspiocb: pointer to lpfc response iocb data structure.
2254 *
2255 * This routine is the completion function for issuing the ELS Logout (LOGO)
2256 * command. If no error status was reported from the LOGO response, the
2257 * state machine of the associated ndlp shall be invoked for transition with
2258 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2259 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2260 **/
dea31012005-04-17 16:05:31 -05002261static void
James Smart2e0fef82007-06-17 19:56:36 -05002262lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2263 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002264{
James Smart2e0fef82007-06-17 19:56:36 -05002265 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2266 struct lpfc_vport *vport = ndlp->vport;
2267 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002268 IOCB_t *irsp;
2269 struct lpfc_sli *psli;
James Smart92494142011-02-16 12:39:44 -05002270 struct lpfcMboxq *mbox;
dea31012005-04-17 16:05:31 -05002271
2272 psli = &phba->sli;
2273 /* we pass cmdiocb to state machine which needs rspiocb as well */
2274 cmdiocb->context_un.rsp_iocb = rspiocb;
2275
2276 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002277 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002278 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002279 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002280
James Smart858c9f62007-06-17 19:56:39 -05002281 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2282 "LOGO cmpl: status:x%x/x%x did:x%x",
2283 irsp->ulpStatus, irsp->un.ulpWord[4],
2284 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002285 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002286 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2287 "0105 LOGO completes to NPort x%x "
2288 "Data: x%x x%x x%x x%x\n",
2289 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2290 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002291 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002292 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002293 goto out;
2294
James Smart92d7f7b2007-06-17 19:56:38 -05002295 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2296 /* NLP_EVT_DEVICE_RM should unregister the RPI
2297 * which should abort all outstanding IOs.
2298 */
2299 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2300 NLP_EVT_DEVICE_RM);
2301 goto out;
2302 }
2303
dea31012005-04-17 16:05:31 -05002304 if (irsp->ulpStatus) {
2305 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002306 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002307 /* ELS command is being retried */
2308 goto out;
dea31012005-04-17 16:05:31 -05002309 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002310 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2311 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2312 ndlp->nlp_DID, irsp->ulpStatus,
2313 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002314 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002315 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002316 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002317 else
James Smart2e0fef82007-06-17 19:56:36 -05002318 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002319 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002320 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002321 /* Good status, call state machine.
2322 * This will unregister the rpi if needed.
2323 */
James Smart2e0fef82007-06-17 19:56:36 -05002324 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002325 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002326out:
2327 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002328 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2329 if ((vport->fc_flag & FC_PT2PT) &&
2330 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2331 phba->pport->fc_myDID = 0;
2332 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2333 if (mbox) {
2334 lpfc_config_link(phba, mbox);
2335 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2336 mbox->vport = vport;
2337 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2338 MBX_NOT_FINISHED) {
2339 mempool_free(mbox, phba->mbox_mem_pool);
2340 }
2341 }
2342 }
dea31012005-04-17 16:05:31 -05002343 return;
2344}
2345
James Smarte59058c2008-08-24 21:49:00 -04002346/**
James Smart3621a712009-04-06 18:47:14 -04002347 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002348 * @vport: pointer to a virtual N_Port data structure.
2349 * @ndlp: pointer to a node-list data structure.
2350 * @retry: number of retries to the command IOCB.
2351 *
2352 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2353 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2354 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2355 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2356 *
2357 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2358 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2359 * will be stored into the context1 field of the IOCB for the completion
2360 * callback function to the LOGO ELS command.
2361 *
2362 * Return code
2363 * 0 - successfully issued logo
2364 * 1 - failed to issue logo
2365 **/
dea31012005-04-17 16:05:31 -05002366int
James Smart2e0fef82007-06-17 19:56:36 -05002367lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002368 uint8_t retry)
2369{
James Smart2e0fef82007-06-17 19:56:36 -05002370 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2371 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002372 IOCB_t *icmd;
2373 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002374 uint8_t *pcmd;
2375 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002376 int rc;
dea31012005-04-17 16:05:31 -05002377
James Smart98c9ea52007-10-27 13:37:33 -04002378 spin_lock_irq(shost->host_lock);
2379 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2380 spin_unlock_irq(shost->host_lock);
2381 return 0;
2382 }
2383 spin_unlock_irq(shost->host_lock);
2384
James Smart92d7f7b2007-06-17 19:56:38 -05002385 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002386 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2387 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002388 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002389 return 1;
dea31012005-04-17 16:05:31 -05002390
2391 icmd = &elsiocb->iocb;
2392 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2393 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002394 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002395
2396 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002397 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002398 pcmd += sizeof(uint32_t);
2399 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002400
James Smart858c9f62007-06-17 19:56:39 -05002401 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2402 "Issue LOGO: did:x%x",
2403 ndlp->nlp_DID, 0, 0);
2404
dea31012005-04-17 16:05:31 -05002405 phba->fc_stat.elsXmitLOGO++;
2406 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002407 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002408 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002409 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002410 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002411
2412 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002413 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002414 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002415 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002416 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002417 return 1;
dea31012005-04-17 16:05:31 -05002418 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002419 return 0;
dea31012005-04-17 16:05:31 -05002420}
2421
James Smarte59058c2008-08-24 21:49:00 -04002422/**
James Smart3621a712009-04-06 18:47:14 -04002423 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002424 * @phba: pointer to lpfc hba data structure.
2425 * @cmdiocb: pointer to lpfc command iocb data structure.
2426 * @rspiocb: pointer to lpfc response iocb data structure.
2427 *
2428 * This routine is a generic completion callback function for ELS commands.
2429 * Specifically, it is the callback function which does not need to perform
2430 * any command specific operations. It is currently used by the ELS command
2431 * issuing routines for the ELS State Change Request (SCR),
2432 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2433 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2434 * certain debug loggings, this callback function simply invokes the
2435 * lpfc_els_chk_latt() routine to check whether link went down during the
2436 * discovery process.
2437 **/
dea31012005-04-17 16:05:31 -05002438static void
James Smart2e0fef82007-06-17 19:56:36 -05002439lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2440 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002441{
James Smart2e0fef82007-06-17 19:56:36 -05002442 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002443 IOCB_t *irsp;
2444
2445 irsp = &rspiocb->iocb;
2446
James Smart858c9f62007-06-17 19:56:39 -05002447 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2448 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2449 irsp->ulpStatus, irsp->un.ulpWord[4],
2450 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002451 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002452 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2453 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2454 irsp->ulpIoTag, irsp->ulpStatus,
2455 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002456 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002457 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002458 lpfc_els_free_iocb(phba, cmdiocb);
2459 return;
2460}
2461
James Smarte59058c2008-08-24 21:49:00 -04002462/**
James Smart3621a712009-04-06 18:47:14 -04002463 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002464 * @vport: pointer to a host virtual N_Port data structure.
2465 * @nportid: N_Port identifier to the remote node.
2466 * @retry: number of retries to the command IOCB.
2467 *
2468 * This routine issues a State Change Request (SCR) to a fabric node
2469 * on a @vport. The remote node @nportid is passed into the function. It
2470 * first search the @vport node list to find the matching ndlp. If no such
2471 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2472 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2473 * routine is invoked to send the SCR IOCB.
2474 *
2475 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2476 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2477 * will be stored into the context1 field of the IOCB for the completion
2478 * callback function to the SCR ELS command.
2479 *
2480 * Return code
2481 * 0 - Successfully issued scr command
2482 * 1 - Failed to issue scr command
2483 **/
dea31012005-04-17 16:05:31 -05002484int
James Smart2e0fef82007-06-17 19:56:36 -05002485lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002486{
James Smart2e0fef82007-06-17 19:56:36 -05002487 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002488 IOCB_t *icmd;
2489 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002490 struct lpfc_sli *psli;
2491 uint8_t *pcmd;
2492 uint16_t cmdsize;
2493 struct lpfc_nodelist *ndlp;
2494
2495 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002496 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002497
James Smarte47c9092008-02-08 18:49:26 -05002498 ndlp = lpfc_findnode_did(vport, nportid);
2499 if (!ndlp) {
2500 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2501 if (!ndlp)
2502 return 1;
2503 lpfc_nlp_init(vport, ndlp, nportid);
2504 lpfc_enqueue_node(vport, ndlp);
2505 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2506 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2507 if (!ndlp)
2508 return 1;
2509 }
dea31012005-04-17 16:05:31 -05002510
James Smart2e0fef82007-06-17 19:56:36 -05002511 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2512 ndlp->nlp_DID, ELS_CMD_SCR);
2513
James Smart488d1462006-03-07 15:02:37 -05002514 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002515 /* This will trigger the release of the node just
2516 * allocated
2517 */
James Smart329f9bc2007-04-25 09:53:01 -04002518 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002519 return 1;
dea31012005-04-17 16:05:31 -05002520 }
2521
2522 icmd = &elsiocb->iocb;
2523 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2524
2525 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002526 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002527
2528 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002529 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002530 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2531
James Smart858c9f62007-06-17 19:56:39 -05002532 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2533 "Issue SCR: did:x%x",
2534 ndlp->nlp_DID, 0, 0);
2535
dea31012005-04-17 16:05:31 -05002536 phba->fc_stat.elsXmitSCR++;
2537 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002538 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2539 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002540 /* The additional lpfc_nlp_put will cause the following
2541 * lpfc_els_free_iocb routine to trigger the rlease of
2542 * the node.
2543 */
James Smart329f9bc2007-04-25 09:53:01 -04002544 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002545 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002546 return 1;
dea31012005-04-17 16:05:31 -05002547 }
James Smartfa4066b2008-01-11 01:53:27 -05002548 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2549 * trigger the release of node.
2550 */
James Smart329f9bc2007-04-25 09:53:01 -04002551 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002552 return 0;
dea31012005-04-17 16:05:31 -05002553}
2554
James Smarte59058c2008-08-24 21:49:00 -04002555/**
James Smart3621a712009-04-06 18:47:14 -04002556 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002557 * @vport: pointer to a host virtual N_Port data structure.
2558 * @nportid: N_Port identifier to the remote node.
2559 * @retry: number of retries to the command IOCB.
2560 *
2561 * This routine issues a Fibre Channel Address Resolution Response
2562 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2563 * is passed into the function. It first search the @vport node list to find
2564 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2565 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2566 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2567 *
2568 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2569 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2570 * will be stored into the context1 field of the IOCB for the completion
2571 * callback function to the PARPR ELS command.
2572 *
2573 * Return code
2574 * 0 - Successfully issued farpr command
2575 * 1 - Failed to issue farpr command
2576 **/
dea31012005-04-17 16:05:31 -05002577static int
James Smart2e0fef82007-06-17 19:56:36 -05002578lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002579{
James Smart2e0fef82007-06-17 19:56:36 -05002580 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002581 IOCB_t *icmd;
2582 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002583 struct lpfc_sli *psli;
2584 FARP *fp;
2585 uint8_t *pcmd;
2586 uint32_t *lp;
2587 uint16_t cmdsize;
2588 struct lpfc_nodelist *ondlp;
2589 struct lpfc_nodelist *ndlp;
2590
2591 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002592 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002593
James Smarte47c9092008-02-08 18:49:26 -05002594 ndlp = lpfc_findnode_did(vport, nportid);
2595 if (!ndlp) {
2596 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2597 if (!ndlp)
2598 return 1;
2599 lpfc_nlp_init(vport, ndlp, nportid);
2600 lpfc_enqueue_node(vport, ndlp);
2601 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2602 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2603 if (!ndlp)
2604 return 1;
2605 }
James Smart2e0fef82007-06-17 19:56:36 -05002606
2607 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2608 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002609 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002610 /* This will trigger the release of the node just
2611 * allocated
2612 */
James Smart329f9bc2007-04-25 09:53:01 -04002613 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002614 return 1;
dea31012005-04-17 16:05:31 -05002615 }
2616
2617 icmd = &elsiocb->iocb;
2618 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2619
2620 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002621 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002622
2623 /* Fill in FARPR payload */
2624 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002625 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002626 lp = (uint32_t *) pcmd;
2627 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002628 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002629 fp->Rflags = 0;
2630 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2631
James Smart92d7f7b2007-06-17 19:56:38 -05002632 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2633 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002634 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002635 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002636 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002637 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002638 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002639 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002640 }
2641
James Smart858c9f62007-06-17 19:56:39 -05002642 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2643 "Issue FARPR: did:x%x",
2644 ndlp->nlp_DID, 0, 0);
2645
dea31012005-04-17 16:05:31 -05002646 phba->fc_stat.elsXmitFARPR++;
2647 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002648 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2649 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002650 /* The additional lpfc_nlp_put will cause the following
2651 * lpfc_els_free_iocb routine to trigger the release of
2652 * the node.
2653 */
James Smart329f9bc2007-04-25 09:53:01 -04002654 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002655 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002656 return 1;
dea31012005-04-17 16:05:31 -05002657 }
James Smartfa4066b2008-01-11 01:53:27 -05002658 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2659 * trigger the release of the node.
2660 */
James Smart329f9bc2007-04-25 09:53:01 -04002661 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002662 return 0;
dea31012005-04-17 16:05:31 -05002663}
2664
James Smarte59058c2008-08-24 21:49:00 -04002665/**
James Smart3621a712009-04-06 18:47:14 -04002666 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002667 * @vport: pointer to a host virtual N_Port data structure.
2668 * @nlp: pointer to a node-list data structure.
2669 *
2670 * This routine cancels the timer with a delayed IOCB-command retry for
2671 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2672 * removes the ELS retry event if it presents. In addition, if the
2673 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2674 * commands are sent for the @vport's nodes that require issuing discovery
2675 * ADISC.
2676 **/
dea31012005-04-17 16:05:31 -05002677void
James Smart2e0fef82007-06-17 19:56:36 -05002678lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002679{
James Smart2e0fef82007-06-17 19:56:36 -05002680 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002681 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002682
James Smart0d2b6b82008-06-14 22:52:47 -04002683 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2684 return;
James Smart2e0fef82007-06-17 19:56:36 -05002685 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002686 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002687 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002688 del_timer_sync(&nlp->nlp_delayfunc);
2689 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002690 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002691 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002692 /* Decrement nlp reference count held for the delayed retry */
2693 evtp = &nlp->els_retry_evt;
2694 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2695 }
James Smartfdcebe22006-03-07 15:04:01 -05002696 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002697 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002698 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002699 spin_unlock_irq(shost->host_lock);
2700 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002701 if (vport->port_state < LPFC_VPORT_READY) {
2702 /* Check if there are more ADISCs to be sent */
2703 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002704 } else {
2705 /* Check if there are more PLOGIs to be sent */
2706 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002707 if (vport->num_disc_nodes == 0) {
2708 spin_lock_irq(shost->host_lock);
2709 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2710 spin_unlock_irq(shost->host_lock);
2711 lpfc_can_disctmo(vport);
2712 lpfc_end_rscn(vport);
2713 }
James Smartfdcebe22006-03-07 15:04:01 -05002714 }
2715 }
2716 }
2717 return;
2718}
2719
James Smarte59058c2008-08-24 21:49:00 -04002720/**
James Smart3621a712009-04-06 18:47:14 -04002721 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002722 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2723 *
2724 * This routine is invoked by the ndlp delayed-function timer to check
2725 * whether there is any pending ELS retry event(s) with the node. If not, it
2726 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2727 * adds the delayed events to the HBA work list and invokes the
2728 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2729 * event. Note that lpfc_nlp_get() is called before posting the event to
2730 * the work list to hold reference count of ndlp so that it guarantees the
2731 * reference to ndlp will still be available when the worker thread gets
2732 * to the event associated with the ndlp.
2733 **/
James Smartfdcebe22006-03-07 15:04:01 -05002734void
dea31012005-04-17 16:05:31 -05002735lpfc_els_retry_delay(unsigned long ptr)
2736{
James Smart2e0fef82007-06-17 19:56:36 -05002737 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2738 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002739 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002740 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002741 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002742
James Smart92d7f7b2007-06-17 19:56:38 -05002743 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002744 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002745 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002746 return;
2747 }
2748
James Smartfa4066b2008-01-11 01:53:27 -05002749 /* We need to hold the node by incrementing the reference
2750 * count until the queued work is done
2751 */
2752 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002753 if (evtp->evt_arg1) {
2754 evtp->evt = LPFC_EVT_ELS_RETRY;
2755 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002756 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002757 }
James Smart92d7f7b2007-06-17 19:56:38 -05002758 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002759 return;
2760}
2761
James Smarte59058c2008-08-24 21:49:00 -04002762/**
James Smart3621a712009-04-06 18:47:14 -04002763 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002764 * @ndlp: pointer to a node-list data structure.
2765 *
2766 * This routine is the worker-thread handler for processing the @ndlp delayed
2767 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2768 * the last ELS command from the associated ndlp and invokes the proper ELS
2769 * function according to the delayed ELS command to retry the command.
2770 **/
dea31012005-04-17 16:05:31 -05002771void
2772lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2773{
James Smart2e0fef82007-06-17 19:56:36 -05002774 struct lpfc_vport *vport = ndlp->vport;
2775 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2776 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002777
James Smart2e0fef82007-06-17 19:56:36 -05002778 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002779 did = ndlp->nlp_DID;
2780 cmd = ndlp->nlp_last_elscmd;
2781 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002782
2783 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002784 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002785 return;
2786 }
2787
2788 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002789 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002790 /*
2791 * If a discovery event readded nlp_delayfunc after timer
2792 * firing and before processing the timer, cancel the
2793 * nlp_delayfunc.
2794 */
2795 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002796 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002797 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002798
2799 switch (cmd) {
2800 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002801 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002802 break;
2803 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002804 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002805 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002806 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002807 }
dea31012005-04-17 16:05:31 -05002808 break;
2809 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002810 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002811 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002812 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002813 }
dea31012005-04-17 16:05:31 -05002814 break;
2815 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002816 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002817 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002818 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002819 }
dea31012005-04-17 16:05:31 -05002820 break;
2821 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002822 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002823 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002824 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002825 }
dea31012005-04-17 16:05:31 -05002826 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002827 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05002828 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
2829 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05002830 break;
dea31012005-04-17 16:05:31 -05002831 }
2832 return;
2833}
2834
James Smarte59058c2008-08-24 21:49:00 -04002835/**
James Smart3621a712009-04-06 18:47:14 -04002836 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002837 * @phba: pointer to lpfc hba data structure.
2838 * @cmdiocb: pointer to lpfc command iocb data structure.
2839 * @rspiocb: pointer to lpfc response iocb data structure.
2840 *
2841 * This routine makes a retry decision on an ELS command IOCB, which has
2842 * failed. The following ELS IOCBs use this function for retrying the command
2843 * when previously issued command responsed with error status: FLOGI, PLOGI,
2844 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2845 * returned error status, it makes the decision whether a retry shall be
2846 * issued for the command, and whether a retry shall be made immediately or
2847 * delayed. In the former case, the corresponding ELS command issuing-function
2848 * is called to retry the command. In the later case, the ELS command shall
2849 * be posted to the ndlp delayed event and delayed function timer set to the
2850 * ndlp for the delayed command issusing.
2851 *
2852 * Return code
2853 * 0 - No retry of els command is made
2854 * 1 - Immediate or delayed retry of els command is made
2855 **/
dea31012005-04-17 16:05:31 -05002856static int
James Smart2e0fef82007-06-17 19:56:36 -05002857lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2858 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002859{
James Smart2e0fef82007-06-17 19:56:36 -05002860 struct lpfc_vport *vport = cmdiocb->vport;
2861 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2862 IOCB_t *irsp = &rspiocb->iocb;
2863 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2864 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002865 uint32_t *elscmd;
2866 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002867 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002868 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002869 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002870 uint32_t did;
dea31012005-04-17 16:05:31 -05002871
James Smart488d1462006-03-07 15:02:37 -05002872
dea31012005-04-17 16:05:31 -05002873 /* Note: context2 may be 0 for internal driver abort
2874 * of delays ELS command.
2875 */
2876
2877 if (pcmd && pcmd->virt) {
2878 elscmd = (uint32_t *) (pcmd->virt);
2879 cmd = *elscmd++;
2880 }
2881
James Smarte47c9092008-02-08 18:49:26 -05002882 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002883 did = ndlp->nlp_DID;
2884 else {
2885 /* We should only hit this case for retrying PLOGI */
2886 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002887 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002888 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2889 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002890 return 1;
2891 }
2892
James Smart858c9f62007-06-17 19:56:39 -05002893 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2894 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2895 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2896
dea31012005-04-17 16:05:31 -05002897 switch (irsp->ulpStatus) {
2898 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05002899 break;
James Smart1151e3e2011-02-16 12:39:35 -05002900 case IOSTAT_REMOTE_STOP:
2901 if (phba->sli_rev == LPFC_SLI_REV4) {
2902 /* This IO was aborted by the target, we don't
2903 * know the rxid and because we did not send the
2904 * ABTS we cannot generate and RRQ.
2905 */
2906 lpfc_set_rrq_active(phba, ndlp,
2907 cmdiocb->sli4_xritag, 0, 0);
2908 }
2909 break;
dea31012005-04-17 16:05:31 -05002910 case IOSTAT_LOCAL_REJECT:
2911 switch ((irsp->un.ulpWord[4] & 0xff)) {
2912 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002913 if (cmd == ELS_CMD_FLOGI) {
2914 if (PCI_DEVICE_ID_HORNET ==
2915 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05002916 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05002917 phba->pport->fc_myDID = 0;
2918 phba->alpa_map[0] = 0;
2919 phba->alpa_map[1] = 0;
2920 }
2921 }
James Smart2e0fef82007-06-17 19:56:36 -05002922 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002923 delay = 1000;
dea31012005-04-17 16:05:31 -05002924 retry = 1;
2925 break;
2926
James Smart92d7f7b2007-06-17 19:56:38 -05002927 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002928 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2929 "0124 Retry illegal cmd x%x "
2930 "retry:x%x delay:x%x\n",
2931 cmd, cmdiocb->retry, delay);
2932 retry = 1;
2933 /* All command's retry policy */
2934 maxretry = 8;
2935 if (cmdiocb->retry > 2)
2936 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002937 break;
2938
dea31012005-04-17 16:05:31 -05002939 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002940 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002941 retry = 1;
2942 if (cmdiocb->retry > 100)
2943 delay = 100;
2944 maxretry = 250;
2945 break;
2946
2947 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002948 delay = 100;
dea31012005-04-17 16:05:31 -05002949 retry = 1;
2950 break;
2951
James Smart858c9f62007-06-17 19:56:39 -05002952 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002953 case IOERR_INVALID_RPI:
2954 retry = 1;
2955 break;
2956 }
2957 break;
2958
2959 case IOSTAT_NPORT_RJT:
2960 case IOSTAT_FABRIC_RJT:
2961 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2962 retry = 1;
2963 break;
2964 }
2965 break;
2966
2967 case IOSTAT_NPORT_BSY:
2968 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002969 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002970 retry = 1;
2971 break;
2972
2973 case IOSTAT_LS_RJT:
2974 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2975 /* Added for Vendor specifc support
2976 * Just keep retrying for these Rsn / Exp codes
2977 */
2978 switch (stat.un.b.lsRjtRsnCode) {
2979 case LSRJT_UNABLE_TPC:
2980 if (stat.un.b.lsRjtRsnCodeExp ==
2981 LSEXP_CMD_IN_PROGRESS) {
2982 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002983 delay = 1000;
dea31012005-04-17 16:05:31 -05002984 maxretry = 48;
2985 }
2986 retry = 1;
2987 break;
2988 }
James Smartffc95492010-06-07 15:23:17 -04002989 if (stat.un.b.lsRjtRsnCodeExp ==
2990 LSEXP_CANT_GIVE_DATA) {
2991 if (cmd == ELS_CMD_PLOGI) {
2992 delay = 1000;
2993 maxretry = 48;
2994 }
2995 retry = 1;
2996 break;
2997 }
dea31012005-04-17 16:05:31 -05002998 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002999 delay = 1000;
dea31012005-04-17 16:05:31 -05003000 maxretry = lpfc_max_els_tries + 1;
3001 retry = 1;
3002 break;
3003 }
James Smart92d7f7b2007-06-17 19:56:38 -05003004 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3005 (cmd == ELS_CMD_FDISC) &&
3006 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003007 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3008 "0125 FDISC Failed (x%x). "
3009 "Fabric out of resources\n",
3010 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003011 lpfc_vport_set_state(vport,
3012 FC_VPORT_NO_FABRIC_RSCS);
3013 }
dea31012005-04-17 16:05:31 -05003014 break;
3015
3016 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003017 if ((cmd == ELS_CMD_PLOGI) ||
3018 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003019 delay = 1000;
dea31012005-04-17 16:05:31 -05003020 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003021 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003022 /* FDISC retry policy */
3023 maxretry = 48;
3024 if (cmdiocb->retry >= 32)
3025 delay = 1000;
dea31012005-04-17 16:05:31 -05003026 }
3027 retry = 1;
3028 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003029
3030 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003031 /* There are some cases where switches return this
3032 * error when they are not ready and should be returning
3033 * Logical Busy. We should delay every time.
3034 */
3035 if (cmd == ELS_CMD_FDISC &&
3036 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3037 maxretry = 3;
3038 delay = 1000;
3039 retry = 1;
3040 break;
3041 }
James Smart92d7f7b2007-06-17 19:56:38 -05003042 case LSRJT_PROTOCOL_ERR:
3043 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3044 (cmd == ELS_CMD_FDISC) &&
3045 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3046 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3047 ) {
James Smarte8b62012007-08-02 11:10:09 -04003048 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003049 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003050 "Fabric Detected Bad WWN\n",
3051 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003052 lpfc_vport_set_state(vport,
3053 FC_VPORT_FABRIC_REJ_WWN);
3054 }
3055 break;
dea31012005-04-17 16:05:31 -05003056 }
3057 break;
3058
3059 case IOSTAT_INTERMED_RSP:
3060 case IOSTAT_BA_RJT:
3061 break;
3062
3063 default:
3064 break;
3065 }
3066
James Smart488d1462006-03-07 15:02:37 -05003067 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003068 retry = 1;
dea31012005-04-17 16:05:31 -05003069
James Smart695a8142010-01-26 23:08:03 -05003070 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart76a95d72010-11-20 23:11:48 -05003071 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003072 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003073 /* FLOGI retry policy */
3074 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04003075 /* retry forever */
3076 maxretry = 0;
3077 if (cmdiocb->retry >= 100)
3078 delay = 5000;
3079 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003080 delay = 1000;
3081 }
3082
James Smart6669f9b2009-10-02 15:16:45 -04003083 cmdiocb->retry++;
3084 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003085 phba->fc_stat.elsRetryExceeded++;
3086 retry = 0;
3087 }
3088
James Smarted957682007-06-17 19:56:37 -05003089 if ((vport->load_flag & FC_UNLOADING) != 0)
3090 retry = 0;
3091
dea31012005-04-17 16:05:31 -05003092 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003093 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3094 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3095 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3096 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3097 "2849 Stop retry ELS command "
3098 "x%x to remote NPORT x%x, "
3099 "Data: x%x x%x\n", cmd, did,
3100 cmdiocb->retry, delay);
3101 return 0;
3102 }
3103 }
dea31012005-04-17 16:05:31 -05003104
3105 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003106 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3107 "0107 Retry ELS command x%x to remote "
3108 "NPORT x%x Data: x%x x%x\n",
3109 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003110
James Smart858c9f62007-06-17 19:56:39 -05003111 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3112 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3113 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
3114 /* Don't reset timer for no resources */
3115
dea31012005-04-17 16:05:31 -05003116 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003117 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003118 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003119 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003120 }
3121
3122 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003123 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003124 phba->fc_stat.elsDelayRetry++;
3125 ndlp->nlp_retry = cmdiocb->retry;
3126
James Smart92d7f7b2007-06-17 19:56:38 -05003127 /* delay is specified in milliseconds */
3128 mod_timer(&ndlp->nlp_delayfunc,
3129 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003130 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003131 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003132 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003133
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003134 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003135 if (cmd == ELS_CMD_PRLI)
3136 lpfc_nlp_set_state(vport, ndlp,
3137 NLP_STE_REG_LOGIN_ISSUE);
3138 else
3139 lpfc_nlp_set_state(vport, ndlp,
3140 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003141 ndlp->nlp_last_elscmd = cmd;
3142
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003143 return 1;
dea31012005-04-17 16:05:31 -05003144 }
3145 switch (cmd) {
3146 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003147 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003148 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003149 case ELS_CMD_FDISC:
3150 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3151 return 1;
dea31012005-04-17 16:05:31 -05003152 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003153 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003154 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003155 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003156 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003157 }
James Smart2e0fef82007-06-17 19:56:36 -05003158 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003159 return 1;
dea31012005-04-17 16:05:31 -05003160 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003161 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003162 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3163 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003164 return 1;
dea31012005-04-17 16:05:31 -05003165 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003166 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003167 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3168 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003169 return 1;
dea31012005-04-17 16:05:31 -05003170 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003171 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003172 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3173 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003174 return 1;
dea31012005-04-17 16:05:31 -05003175 }
3176 }
dea31012005-04-17 16:05:31 -05003177 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003178 if (logerr) {
3179 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3180 "0137 No retry ELS command x%x to remote "
3181 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3182 cmd, did, irsp->ulpStatus,
3183 irsp->un.ulpWord[4]);
3184 }
3185 else {
3186 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003187 "0108 No retry ELS command x%x to remote "
3188 "NPORT x%x Retried:%d Error:x%x/%x\n",
3189 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3190 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003191 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003192 return 0;
dea31012005-04-17 16:05:31 -05003193}
3194
James Smarte59058c2008-08-24 21:49:00 -04003195/**
James Smart3621a712009-04-06 18:47:14 -04003196 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003197 * @phba: pointer to lpfc hba data structure.
3198 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3199 *
3200 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3201 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3202 * checks to see whether there is a lpfc DMA buffer associated with the
3203 * response of the command IOCB. If so, it will be released before releasing
3204 * the lpfc DMA buffer associated with the IOCB itself.
3205 *
3206 * Return code
3207 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3208 **/
James Smart09372822008-01-11 01:52:54 -05003209static int
James Smart87af33f2007-10-27 13:37:43 -04003210lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3211{
3212 struct lpfc_dmabuf *buf_ptr;
3213
James Smarte59058c2008-08-24 21:49:00 -04003214 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003215 if (!list_empty(&buf_ptr1->list)) {
3216 list_remove_head(&buf_ptr1->list, buf_ptr,
3217 struct lpfc_dmabuf,
3218 list);
3219 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3220 kfree(buf_ptr);
3221 }
3222 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3223 kfree(buf_ptr1);
3224 return 0;
3225}
3226
James Smarte59058c2008-08-24 21:49:00 -04003227/**
James Smart3621a712009-04-06 18:47:14 -04003228 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003229 * @phba: pointer to lpfc hba data structure.
3230 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3231 *
3232 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3233 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3234 * pool.
3235 *
3236 * Return code
3237 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3238 **/
James Smart09372822008-01-11 01:52:54 -05003239static int
James Smart87af33f2007-10-27 13:37:43 -04003240lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3241{
3242 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3243 kfree(buf_ptr);
3244 return 0;
3245}
3246
James Smarte59058c2008-08-24 21:49:00 -04003247/**
James Smart3621a712009-04-06 18:47:14 -04003248 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003249 * @phba: pointer to lpfc hba data structure.
3250 * @elsiocb: pointer to lpfc els command iocb data structure.
3251 *
3252 * This routine frees a command IOCB and its associated resources. The
3253 * command IOCB data structure contains the reference to various associated
3254 * resources, these fields must be set to NULL if the associated reference
3255 * not present:
3256 * context1 - reference to ndlp
3257 * context2 - reference to cmd
3258 * context2->next - reference to rsp
3259 * context3 - reference to bpl
3260 *
3261 * It first properly decrements the reference count held on ndlp for the
3262 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3263 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3264 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3265 * adds the DMA buffer the @phba data structure for the delayed release.
3266 * If reference to the Buffer Pointer List (BPL) is present, the
3267 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3268 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3269 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3270 *
3271 * Return code
3272 * 0 - Success (currently, always return 0)
3273 **/
James Smart87af33f2007-10-27 13:37:43 -04003274int
James Smart329f9bc2007-04-25 09:53:01 -04003275lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003276{
3277 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003278 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003279
James Smarta8adb832007-10-27 13:37:53 -04003280 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3281 if (ndlp) {
3282 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3283 lpfc_nlp_put(ndlp);
3284
3285 /* If the ndlp is not being used by another discovery
3286 * thread, free it.
3287 */
3288 if (!lpfc_nlp_not_used(ndlp)) {
3289 /* If ndlp is being used by another discovery
3290 * thread, just clear NLP_DEFER_RM
3291 */
3292 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3293 }
3294 }
3295 else
3296 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003297 elsiocb->context1 = NULL;
3298 }
dea31012005-04-17 16:05:31 -05003299 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3300 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003301 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3302 /* Firmware could still be in progress of DMAing
3303 * payload, so don't free data buffer till after
3304 * a hbeat.
3305 */
3306 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3307 buf_ptr = elsiocb->context2;
3308 elsiocb->context2 = NULL;
3309 if (buf_ptr) {
3310 buf_ptr1 = NULL;
3311 spin_lock_irq(&phba->hbalock);
3312 if (!list_empty(&buf_ptr->list)) {
3313 list_remove_head(&buf_ptr->list,
3314 buf_ptr1, struct lpfc_dmabuf,
3315 list);
3316 INIT_LIST_HEAD(&buf_ptr1->list);
3317 list_add_tail(&buf_ptr1->list,
3318 &phba->elsbuf);
3319 phba->elsbuf_cnt++;
3320 }
3321 INIT_LIST_HEAD(&buf_ptr->list);
3322 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3323 phba->elsbuf_cnt++;
3324 spin_unlock_irq(&phba->hbalock);
3325 }
3326 } else {
3327 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3328 lpfc_els_free_data(phba, buf_ptr1);
3329 }
dea31012005-04-17 16:05:31 -05003330 }
3331
3332 if (elsiocb->context3) {
3333 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003334 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003335 }
James Bottomley604a3e32005-10-29 10:28:33 -05003336 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003337 return 0;
3338}
3339
James Smarte59058c2008-08-24 21:49:00 -04003340/**
James Smart3621a712009-04-06 18:47:14 -04003341 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003342 * @phba: pointer to lpfc hba data structure.
3343 * @cmdiocb: pointer to lpfc command iocb data structure.
3344 * @rspiocb: pointer to lpfc response iocb data structure.
3345 *
3346 * This routine is the completion callback function to the Logout (LOGO)
3347 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3348 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3349 * release the ndlp if it has the last reference remaining (reference count
3350 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3351 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3352 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3353 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3354 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3355 * IOCB data structure.
3356 **/
dea31012005-04-17 16:05:31 -05003357static void
James Smart2e0fef82007-06-17 19:56:36 -05003358lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3359 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003360{
James Smart2e0fef82007-06-17 19:56:36 -05003361 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3362 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003363 IOCB_t *irsp;
3364
3365 irsp = &rspiocb->iocb;
3366 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3367 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3368 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003369 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003370 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3371 "0109 ACC to LOGO completes to NPort x%x "
3372 "Data: x%x x%x x%x\n",
3373 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3374 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003375
3376 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3377 /* NPort Recovery mode or node is just allocated */
3378 if (!lpfc_nlp_not_used(ndlp)) {
3379 /* If the ndlp is being used by another discovery
3380 * thread, just unregister the RPI.
3381 */
3382 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003383 } else {
3384 /* Indicate the node has already released, should
3385 * not reference to it from within lpfc_els_free_iocb.
3386 */
3387 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003388 }
dea31012005-04-17 16:05:31 -05003389 }
3390 lpfc_els_free_iocb(phba, cmdiocb);
3391 return;
3392}
3393
James Smarte59058c2008-08-24 21:49:00 -04003394/**
James Smart3621a712009-04-06 18:47:14 -04003395 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003396 * @phba: pointer to lpfc hba data structure.
3397 * @pmb: pointer to the driver internal queue element for mailbox command.
3398 *
3399 * This routine is the completion callback function for unregister default
3400 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3401 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3402 * decrements the ndlp reference count held for this completion callback
3403 * function. After that, it invokes the lpfc_nlp_not_used() to check
3404 * whether there is only one reference left on the ndlp. If so, it will
3405 * perform one more decrement and trigger the release of the ndlp.
3406 **/
James Smart858c9f62007-06-17 19:56:39 -05003407void
3408lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3409{
3410 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3411 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3412
3413 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003414 pmb->context2 = NULL;
3415
James Smart858c9f62007-06-17 19:56:39 -05003416 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3417 kfree(mp);
3418 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003419 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003420 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003421 /* This is the end of the default RPI cleanup logic for this
3422 * ndlp. If no other discovery threads are using this ndlp.
3423 * we should free all resources associated with it.
3424 */
3425 lpfc_nlp_not_used(ndlp);
3426 }
James Smart3772a992009-05-22 14:50:54 -04003427
James Smart858c9f62007-06-17 19:56:39 -05003428 return;
3429}
3430
James Smarte59058c2008-08-24 21:49:00 -04003431/**
James Smart3621a712009-04-06 18:47:14 -04003432 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003433 * @phba: pointer to lpfc hba data structure.
3434 * @cmdiocb: pointer to lpfc command iocb data structure.
3435 * @rspiocb: pointer to lpfc response iocb data structure.
3436 *
3437 * This routine is the completion callback function for ELS Response IOCB
3438 * command. In normal case, this callback function just properly sets the
3439 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3440 * field in the command IOCB is not NULL, the referred mailbox command will
3441 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3442 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3443 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3444 * routine shall be invoked trying to release the ndlp if no other threads
3445 * are currently referring it.
3446 **/
dea31012005-04-17 16:05:31 -05003447static void
James Smart858c9f62007-06-17 19:56:39 -05003448lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003449 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003450{
James Smart2e0fef82007-06-17 19:56:36 -05003451 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3452 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3453 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003454 IOCB_t *irsp;
3455 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003456 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003457 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003458 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003459
James Smart33ccf8d2006-08-17 11:57:58 -04003460 irsp = &rspiocb->iocb;
3461
dea31012005-04-17 16:05:31 -05003462 if (cmdiocb->context_un.mbox)
3463 mbox = cmdiocb->context_un.mbox;
3464
James Smartfa4066b2008-01-11 01:53:27 -05003465 /* First determine if this is a LS_RJT cmpl. Note, this callback
3466 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3467 */
James Smart87af33f2007-10-27 13:37:43 -04003468 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003469 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3470 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003471 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003472 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003473 */
3474 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3475 ls_rjt = 1;
3476 }
3477
dea31012005-04-17 16:05:31 -05003478 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003479 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003480 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003481 mp = (struct lpfc_dmabuf *) mbox->context1;
3482 if (mp) {
3483 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3484 kfree(mp);
3485 }
James Smart329f9bc2007-04-25 09:53:01 -04003486 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003487 }
James Smart58da1ff2008-04-07 10:15:56 -04003488 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3489 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003490 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003491 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003492 /* Indicate the node has already released,
3493 * should not reference to it from within
3494 * the routine lpfc_els_free_iocb.
3495 */
3496 cmdiocb->context1 = NULL;
3497 }
dea31012005-04-17 16:05:31 -05003498 goto out;
3499 }
3500
James Smart858c9f62007-06-17 19:56:39 -05003501 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003502 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003503 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003504 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003505 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003506 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3507 "0110 ELS response tag x%x completes "
3508 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3509 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3510 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3511 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3512 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003513 if (mbox) {
3514 if ((rspiocb->iocb.ulpStatus == 0)
3515 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003516 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003517 /* Increment reference count to ndlp to hold the
3518 * reference to ndlp for the callback function.
3519 */
James Smart329f9bc2007-04-25 09:53:01 -04003520 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003521 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003522 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3523 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3524 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3525 }
3526 else {
3527 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3528 ndlp->nlp_prev_state = ndlp->nlp_state;
3529 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003530 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003531 }
James Smart0b727fe2007-10-27 13:37:25 -04003532 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003533 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003534 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003535 else
3536 /* Decrement the ndlp reference count we
3537 * set for this failed mailbox command.
3538 */
3539 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003540
3541 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3542 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3543 "0138 ELS rsp: Cannot issue reg_login for x%x "
3544 "Data: x%x x%x x%x\n",
3545 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3546 ndlp->nlp_rpi);
3547
James Smartfa4066b2008-01-11 01:53:27 -05003548 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003549 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003550 /* Indicate node has already been released,
3551 * should not reference to it from within
3552 * the routine lpfc_els_free_iocb.
3553 */
3554 cmdiocb->context1 = NULL;
3555 }
dea31012005-04-17 16:05:31 -05003556 } else {
James Smart858c9f62007-06-17 19:56:39 -05003557 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3558 if (!lpfc_error_lost_link(irsp) &&
3559 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003560 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003561 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003562 /* Indicate node has already been
3563 * released, should not reference
3564 * to it from within the routine
3565 * lpfc_els_free_iocb.
3566 */
3567 cmdiocb->context1 = NULL;
3568 }
dea31012005-04-17 16:05:31 -05003569 }
3570 }
James Smart14691152006-12-02 13:34:28 -05003571 mp = (struct lpfc_dmabuf *) mbox->context1;
3572 if (mp) {
3573 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3574 kfree(mp);
3575 }
3576 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003577 }
3578out:
James Smart58da1ff2008-04-07 10:15:56 -04003579 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003580 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003581 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003582 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003583
3584 /* If the node is not being used by another discovery thread,
3585 * and we are sending a reject, we are done with it.
3586 * Release driver reference count here and free associated
3587 * resources.
3588 */
3589 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003590 if (lpfc_nlp_not_used(ndlp))
3591 /* Indicate node has already been released,
3592 * should not reference to it from within
3593 * the routine lpfc_els_free_iocb.
3594 */
3595 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003596 }
James Smart87af33f2007-10-27 13:37:43 -04003597
dea31012005-04-17 16:05:31 -05003598 lpfc_els_free_iocb(phba, cmdiocb);
3599 return;
3600}
3601
James Smarte59058c2008-08-24 21:49:00 -04003602/**
James Smart3621a712009-04-06 18:47:14 -04003603 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003604 * @vport: pointer to a host virtual N_Port data structure.
3605 * @flag: the els command code to be accepted.
3606 * @oldiocb: pointer to the original lpfc command iocb data structure.
3607 * @ndlp: pointer to a node-list data structure.
3608 * @mbox: pointer to the driver internal queue element for mailbox command.
3609 *
3610 * This routine prepares and issues an Accept (ACC) response IOCB
3611 * command. It uses the @flag to properly set up the IOCB field for the
3612 * specific ACC response command to be issued and invokes the
3613 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3614 * @mbox pointer is passed in, it will be put into the context_un.mbox
3615 * field of the IOCB for the completion callback function to issue the
3616 * mailbox command to the HBA later when callback is invoked.
3617 *
3618 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3619 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3620 * will be stored into the context1 field of the IOCB for the completion
3621 * callback function to the corresponding response ELS IOCB command.
3622 *
3623 * Return code
3624 * 0 - Successfully issued acc response
3625 * 1 - Failed to issue acc response
3626 **/
dea31012005-04-17 16:05:31 -05003627int
James Smart2e0fef82007-06-17 19:56:36 -05003628lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3629 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003630 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003631{
James Smart2e0fef82007-06-17 19:56:36 -05003632 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3633 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003634 IOCB_t *icmd;
3635 IOCB_t *oldcmd;
3636 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003637 struct lpfc_sli *psli;
3638 uint8_t *pcmd;
3639 uint16_t cmdsize;
3640 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003641 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003642
3643 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003644 oldcmd = &oldiocb->iocb;
3645
3646 switch (flag) {
3647 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003648 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003649 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3650 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003651 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003652 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003653 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003654 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003655 return 1;
dea31012005-04-17 16:05:31 -05003656 }
James Smart2e0fef82007-06-17 19:56:36 -05003657
dea31012005-04-17 16:05:31 -05003658 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003659 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3660 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003661 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3662 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003663 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003664
3665 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3666 "Issue ACC: did:x%x flg:x%x",
3667 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003668 break;
3669 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003670 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003671 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3672 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003673 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003674 return 1;
James Smart488d1462006-03-07 15:02:37 -05003675
dea31012005-04-17 16:05:31 -05003676 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003677 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3678 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003679 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3680
3681 if (mbox)
3682 elsiocb->context_un.mbox = mbox;
3683
3684 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003685 pcmd += sizeof(uint32_t);
3686 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003687
3688 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3689 "Issue ACC PLOGI: did:x%x flg:x%x",
3690 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003691 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003692 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003693 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003694 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003695 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3696 if (!elsiocb)
3697 return 1;
3698
3699 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003700 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3701 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04003702 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3703
3704 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003705 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003706 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3707 els_pkt_ptr = (ELS_PKT *) pcmd;
3708 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003709
3710 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3711 "Issue ACC PRLO: did:x%x flg:x%x",
3712 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003713 break;
dea31012005-04-17 16:05:31 -05003714 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003715 return 1;
dea31012005-04-17 16:05:31 -05003716 }
dea31012005-04-17 16:05:31 -05003717 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003718 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3719 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3720 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3721 elsiocb->iotag, elsiocb->iocb.ulpContext,
3722 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3723 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003724 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003725 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003726 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003727 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003728 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3729 } else {
James Smart858c9f62007-06-17 19:56:39 -05003730 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003731 }
3732
3733 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003734 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003735 if (rc == IOCB_ERROR) {
3736 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003737 return 1;
dea31012005-04-17 16:05:31 -05003738 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003739 return 0;
dea31012005-04-17 16:05:31 -05003740}
3741
James Smarte59058c2008-08-24 21:49:00 -04003742/**
James Smart3621a712009-04-06 18:47:14 -04003743 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003744 * @vport: pointer to a virtual N_Port data structure.
3745 * @rejectError:
3746 * @oldiocb: pointer to the original lpfc command iocb data structure.
3747 * @ndlp: pointer to a node-list data structure.
3748 * @mbox: pointer to the driver internal queue element for mailbox command.
3749 *
3750 * This routine prepares and issue an Reject (RJT) response IOCB
3751 * command. If a @mbox pointer is passed in, it will be put into the
3752 * context_un.mbox field of the IOCB for the completion callback function
3753 * to issue to the HBA later.
3754 *
3755 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3756 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3757 * will be stored into the context1 field of the IOCB for the completion
3758 * callback function to the reject response ELS IOCB command.
3759 *
3760 * Return code
3761 * 0 - Successfully issued reject response
3762 * 1 - Failed to issue reject response
3763 **/
dea31012005-04-17 16:05:31 -05003764int
James Smart2e0fef82007-06-17 19:56:36 -05003765lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003766 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3767 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003768{
James Smart2e0fef82007-06-17 19:56:36 -05003769 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003770 IOCB_t *icmd;
3771 IOCB_t *oldcmd;
3772 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003773 struct lpfc_sli *psli;
3774 uint8_t *pcmd;
3775 uint16_t cmdsize;
3776 int rc;
3777
3778 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003779 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003780 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3781 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003782 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003783 return 1;
dea31012005-04-17 16:05:31 -05003784
3785 icmd = &elsiocb->iocb;
3786 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003787 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3788 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003789 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3790
3791 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003792 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003793 *((uint32_t *) (pcmd)) = rejectError;
3794
James Smart51ef4c22007-08-02 11:10:31 -04003795 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003796 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003797
dea31012005-04-17 16:05:31 -05003798 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003799 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3800 "0129 Xmit ELS RJT x%x response tag x%x "
3801 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3802 "rpi x%x\n",
3803 rejectError, elsiocb->iotag,
3804 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3805 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003806 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3807 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3808 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3809
dea31012005-04-17 16:05:31 -05003810 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003811 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003812 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003813
dea31012005-04-17 16:05:31 -05003814 if (rc == IOCB_ERROR) {
3815 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003816 return 1;
dea31012005-04-17 16:05:31 -05003817 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003818 return 0;
dea31012005-04-17 16:05:31 -05003819}
3820
James Smarte59058c2008-08-24 21:49:00 -04003821/**
James Smart3621a712009-04-06 18:47:14 -04003822 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003823 * @vport: pointer to a virtual N_Port data structure.
3824 * @oldiocb: pointer to the original lpfc command iocb data structure.
3825 * @ndlp: pointer to a node-list data structure.
3826 *
3827 * This routine prepares and issues an Accept (ACC) response to Address
3828 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3829 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3830 *
3831 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3832 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3833 * will be stored into the context1 field of the IOCB for the completion
3834 * callback function to the ADISC Accept response ELS IOCB command.
3835 *
3836 * Return code
3837 * 0 - Successfully issued acc adisc response
3838 * 1 - Failed to issue adisc acc response
3839 **/
dea31012005-04-17 16:05:31 -05003840int
James Smart2e0fef82007-06-17 19:56:36 -05003841lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3842 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003843{
James Smart2e0fef82007-06-17 19:56:36 -05003844 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003845 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003846 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003847 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003848 uint8_t *pcmd;
3849 uint16_t cmdsize;
3850 int rc;
3851
James Smart92d7f7b2007-06-17 19:56:38 -05003852 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003853 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3854 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003855 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003856 return 1;
dea31012005-04-17 16:05:31 -05003857
dea31012005-04-17 16:05:31 -05003858 icmd = &elsiocb->iocb;
3859 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003860 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3861 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04003862
3863 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003864 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3865 "0130 Xmit ADISC ACC response iotag x%x xri: "
3866 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3867 elsiocb->iotag, elsiocb->iocb.ulpContext,
3868 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3869 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003870 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3871
3872 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003873 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003874
3875 ap = (ADISC *) (pcmd);
3876 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003877 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3878 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003879 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003880
James Smart858c9f62007-06-17 19:56:39 -05003881 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3882 "Issue ACC ADISC: did:x%x flg:x%x",
3883 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3884
dea31012005-04-17 16:05:31 -05003885 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003886 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003887 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003888 if (rc == IOCB_ERROR) {
3889 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003890 return 1;
dea31012005-04-17 16:05:31 -05003891 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003892 return 0;
dea31012005-04-17 16:05:31 -05003893}
3894
James Smarte59058c2008-08-24 21:49:00 -04003895/**
James Smart3621a712009-04-06 18:47:14 -04003896 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003897 * @vport: pointer to a virtual N_Port data structure.
3898 * @oldiocb: pointer to the original lpfc command iocb data structure.
3899 * @ndlp: pointer to a node-list data structure.
3900 *
3901 * This routine prepares and issues an Accept (ACC) response to Process
3902 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3903 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3904 *
3905 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3906 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3907 * will be stored into the context1 field of the IOCB for the completion
3908 * callback function to the PRLI Accept response ELS IOCB command.
3909 *
3910 * Return code
3911 * 0 - Successfully issued acc prli response
3912 * 1 - Failed to issue acc prli response
3913 **/
dea31012005-04-17 16:05:31 -05003914int
James Smart2e0fef82007-06-17 19:56:36 -05003915lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003916 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003917{
James Smart2e0fef82007-06-17 19:56:36 -05003918 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003919 PRLI *npr;
3920 lpfc_vpd_t *vpd;
3921 IOCB_t *icmd;
3922 IOCB_t *oldcmd;
3923 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003924 struct lpfc_sli *psli;
3925 uint8_t *pcmd;
3926 uint16_t cmdsize;
3927 int rc;
3928
3929 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003930
James Smart92d7f7b2007-06-17 19:56:38 -05003931 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003932 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003933 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003934 if (!elsiocb)
3935 return 1;
dea31012005-04-17 16:05:31 -05003936
dea31012005-04-17 16:05:31 -05003937 icmd = &elsiocb->iocb;
3938 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003939 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3940 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
3941
James Smart5b8bd0c2007-04-25 09:52:49 -04003942 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003943 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3944 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3945 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3946 elsiocb->iotag, elsiocb->iocb.ulpContext,
3947 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3948 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003949 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3950
3951 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003952 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003953
3954 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003955 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003956
3957 npr = (PRLI *) pcmd;
3958 vpd = &phba->vpd;
3959 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003960 * If the remote port is a target and our firmware version is 3.20 or
3961 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003962 */
James Smart0d2b6b82008-06-14 22:52:47 -04003963 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3964 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003965 npr->ConfmComplAllowed = 1;
3966 npr->Retry = 1;
3967 npr->TaskRetryIdReq = 1;
3968 }
3969
3970 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3971 npr->estabImagePair = 1;
3972 npr->readXferRdyDis = 1;
3973 npr->ConfmComplAllowed = 1;
3974
3975 npr->prliType = PRLI_FCP_TYPE;
3976 npr->initiatorFunc = 1;
3977
James Smart858c9f62007-06-17 19:56:39 -05003978 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3979 "Issue ACC PRLI: did:x%x flg:x%x",
3980 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3981
dea31012005-04-17 16:05:31 -05003982 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003983 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003984
James Smart3772a992009-05-22 14:50:54 -04003985 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003986 if (rc == IOCB_ERROR) {
3987 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003988 return 1;
dea31012005-04-17 16:05:31 -05003989 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003990 return 0;
dea31012005-04-17 16:05:31 -05003991}
3992
James Smarte59058c2008-08-24 21:49:00 -04003993/**
James Smart3621a712009-04-06 18:47:14 -04003994 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003995 * @vport: pointer to a virtual N_Port data structure.
3996 * @format: rnid command format.
3997 * @oldiocb: pointer to the original lpfc command iocb data structure.
3998 * @ndlp: pointer to a node-list data structure.
3999 *
4000 * This routine issues a Request Node Identification Data (RNID) Accept
4001 * (ACC) response. It constructs the RNID ACC response command according to
4002 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4003 * issue the response. Note that this command does not need to hold the ndlp
4004 * reference count for the callback. So, the ndlp reference count taken by
4005 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4006 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4007 * there is no ndlp reference available.
4008 *
4009 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4010 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4011 * will be stored into the context1 field of the IOCB for the completion
4012 * callback function. However, for the RNID Accept Response ELS command,
4013 * this is undone later by this routine after the IOCB is allocated.
4014 *
4015 * Return code
4016 * 0 - Successfully issued acc rnid response
4017 * 1 - Failed to issue acc rnid response
4018 **/
dea31012005-04-17 16:05:31 -05004019static int
James Smart2e0fef82007-06-17 19:56:36 -05004020lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004021 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004022{
James Smart2e0fef82007-06-17 19:56:36 -05004023 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004024 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004025 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004026 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004027 struct lpfc_sli *psli;
4028 uint8_t *pcmd;
4029 uint16_t cmdsize;
4030 int rc;
4031
4032 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004033 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4034 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004035 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004036 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004037
James Smart2e0fef82007-06-17 19:56:36 -05004038 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4039 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004040 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004041 return 1;
dea31012005-04-17 16:05:31 -05004042
dea31012005-04-17 16:05:31 -05004043 icmd = &elsiocb->iocb;
4044 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004045 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4046 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4047
James Smart5b8bd0c2007-04-25 09:52:49 -04004048 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004049 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4050 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4051 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004052 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004053 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004054 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004055
James Smart92d7f7b2007-06-17 19:56:38 -05004056 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004057 rn = (RNID *) (pcmd);
4058 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004059 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4060 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4061 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004062 switch (format) {
4063 case 0:
4064 rn->SpecificLen = 0;
4065 break;
4066 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004067 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004068 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004069 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004070 rn->un.topologyDisc.unitType = RNID_HBA;
4071 rn->un.topologyDisc.physPort = 0;
4072 rn->un.topologyDisc.attachedNodes = 0;
4073 break;
4074 default:
4075 rn->CommonLen = 0;
4076 rn->SpecificLen = 0;
4077 break;
4078 }
4079
James Smart858c9f62007-06-17 19:56:39 -05004080 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4081 "Issue ACC RNID: did:x%x flg:x%x",
4082 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4083
dea31012005-04-17 16:05:31 -05004084 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004085 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04004086 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004087 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
4088 * it could be freed */
4089
James Smart3772a992009-05-22 14:50:54 -04004090 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004091 if (rc == IOCB_ERROR) {
4092 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004093 return 1;
dea31012005-04-17 16:05:31 -05004094 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004095 return 0;
dea31012005-04-17 16:05:31 -05004096}
4097
James Smarte59058c2008-08-24 21:49:00 -04004098/**
James Smart19ca7602010-11-20 23:11:55 -05004099 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4100 * @vport: pointer to a virtual N_Port data structure.
4101 * @iocb: pointer to the lpfc command iocb data structure.
4102 * @ndlp: pointer to a node-list data structure.
4103 *
4104 * Return
4105 **/
4106static void
4107lpfc_els_clear_rrq(struct lpfc_vport *vport,
4108 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4109{
4110 struct lpfc_hba *phba = vport->phba;
4111 uint8_t *pcmd;
4112 struct RRQ *rrq;
4113 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004114 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004115 struct lpfc_node_rrq *prrq;
4116
4117
4118 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4119 pcmd += sizeof(uint32_t);
4120 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004121 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b062011-04-16 11:03:17 -04004122 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004123
4124 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4125 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4126 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004127 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b062011-04-16 11:03:17 -04004128 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004129 rxid,
4130 iocb->iotag, iocb->iocb.ulpContext);
4131
4132 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4133 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4134 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004135 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b062011-04-16 11:03:17 -04004136 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004137 else
4138 xri = rxid;
4139 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004140 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004141 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004142 return;
4143}
4144
4145/**
James Smart12265f62010-10-22 11:05:53 -04004146 * lpfc_els_rsp_echo_acc - Issue echo acc response
4147 * @vport: pointer to a virtual N_Port data structure.
4148 * @data: pointer to echo data to return in the accept.
4149 * @oldiocb: pointer to the original lpfc command iocb data structure.
4150 * @ndlp: pointer to a node-list data structure.
4151 *
4152 * Return code
4153 * 0 - Successfully issued acc echo response
4154 * 1 - Failed to issue acc echo response
4155 **/
4156static int
4157lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4158 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4159{
4160 struct lpfc_hba *phba = vport->phba;
4161 struct lpfc_iocbq *elsiocb;
4162 struct lpfc_sli *psli;
4163 uint8_t *pcmd;
4164 uint16_t cmdsize;
4165 int rc;
4166
4167 psli = &phba->sli;
4168 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4169
4170 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4171 ndlp->nlp_DID, ELS_CMD_ACC);
4172 if (!elsiocb)
4173 return 1;
4174
James Smart7851fe22011-07-22 18:36:52 -04004175 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4176 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4177
James Smart12265f62010-10-22 11:05:53 -04004178 /* Xmit ECHO ACC response tag <ulpIoTag> */
4179 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4180 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4181 elsiocb->iotag, elsiocb->iocb.ulpContext);
4182 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4183 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4184 pcmd += sizeof(uint32_t);
4185 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4186
4187 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4188 "Issue ACC ECHO: did:x%x flg:x%x",
4189 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4190
4191 phba->fc_stat.elsXmitACC++;
4192 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4193 lpfc_nlp_put(ndlp);
4194 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
4195 * it could be freed */
4196
4197 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4198 if (rc == IOCB_ERROR) {
4199 lpfc_els_free_iocb(phba, elsiocb);
4200 return 1;
4201 }
4202 return 0;
4203}
4204
4205/**
James Smart3621a712009-04-06 18:47:14 -04004206 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004207 * @vport: pointer to a host virtual N_Port data structure.
4208 *
4209 * This routine issues Address Discover (ADISC) ELS commands to those
4210 * N_Ports which are in node port recovery state and ADISC has not been issued
4211 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4212 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4213 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4214 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4215 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4216 * IOCBs quit for later pick up. On the other hand, after walking through
4217 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4218 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4219 * no more ADISC need to be sent.
4220 *
4221 * Return code
4222 * The number of N_Ports with adisc issued.
4223 **/
dea31012005-04-17 16:05:31 -05004224int
James Smart2e0fef82007-06-17 19:56:36 -05004225lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004226{
James Smart2e0fef82007-06-17 19:56:36 -05004227 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004228 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004229 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004230
James Smart685f0bf2007-04-25 09:53:08 -04004231 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004232 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004233 if (!NLP_CHK_NODE_ACT(ndlp))
4234 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004235 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4236 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4237 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004238 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004239 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004240 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004241 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004242 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4243 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004244 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004245 vport->num_disc_nodes++;
4246 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004247 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004248 spin_lock_irq(shost->host_lock);
4249 vport->fc_flag |= FC_NLP_MORE;
4250 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004251 break;
dea31012005-04-17 16:05:31 -05004252 }
4253 }
4254 }
4255 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004256 spin_lock_irq(shost->host_lock);
4257 vport->fc_flag &= ~FC_NLP_MORE;
4258 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004259 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004260 return sentadisc;
dea31012005-04-17 16:05:31 -05004261}
4262
James Smarte59058c2008-08-24 21:49:00 -04004263/**
James Smart3621a712009-04-06 18:47:14 -04004264 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004265 * @vport: pointer to a host virtual N_Port data structure.
4266 *
4267 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4268 * which are in node port recovery state, with a @vport. Each time an ELS
4269 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4270 * the per @vport number of discover count (num_disc_nodes) shall be
4271 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4272 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4273 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4274 * later pick up. On the other hand, after walking through all the ndlps with
4275 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4276 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4277 * PLOGI need to be sent.
4278 *
4279 * Return code
4280 * The number of N_Ports with plogi issued.
4281 **/
dea31012005-04-17 16:05:31 -05004282int
James Smart2e0fef82007-06-17 19:56:36 -05004283lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004284{
James Smart2e0fef82007-06-17 19:56:36 -05004285 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004286 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004287 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004288
James Smart2e0fef82007-06-17 19:56:36 -05004289 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4290 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004291 if (!NLP_CHK_NODE_ACT(ndlp))
4292 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004293 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4294 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4295 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4296 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4297 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004298 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4299 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004300 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004301 vport->num_disc_nodes++;
4302 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004303 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004304 spin_lock_irq(shost->host_lock);
4305 vport->fc_flag |= FC_NLP_MORE;
4306 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004307 break;
dea31012005-04-17 16:05:31 -05004308 }
4309 }
4310 }
James Smart87af33f2007-10-27 13:37:43 -04004311 if (sentplogi) {
4312 lpfc_set_disctmo(vport);
4313 }
4314 else {
James Smart2e0fef82007-06-17 19:56:36 -05004315 spin_lock_irq(shost->host_lock);
4316 vport->fc_flag &= ~FC_NLP_MORE;
4317 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004318 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004319 return sentplogi;
dea31012005-04-17 16:05:31 -05004320}
4321
James Smarte59058c2008-08-24 21:49:00 -04004322/**
James Smart3621a712009-04-06 18:47:14 -04004323 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004324 * @vport: pointer to a host virtual N_Port data structure.
4325 *
4326 * This routine cleans up any Registration State Change Notification
4327 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4328 * @vport together with the host_lock is used to prevent multiple thread
4329 * trying to access the RSCN array on a same @vport at the same time.
4330 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004331void
James Smart2e0fef82007-06-17 19:56:36 -05004332lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004333{
James Smart2e0fef82007-06-17 19:56:36 -05004334 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4335 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004336 int i;
4337
James Smart7f5f3d02008-02-08 18:50:14 -05004338 spin_lock_irq(shost->host_lock);
4339 if (vport->fc_rscn_flush) {
4340 /* Another thread is walking fc_rscn_id_list on this vport */
4341 spin_unlock_irq(shost->host_lock);
4342 return;
4343 }
4344 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4345 vport->fc_rscn_flush = 1;
4346 spin_unlock_irq(shost->host_lock);
4347
James Smart2e0fef82007-06-17 19:56:36 -05004348 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004349 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004350 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004351 }
James Smart2e0fef82007-06-17 19:56:36 -05004352 spin_lock_irq(shost->host_lock);
4353 vport->fc_rscn_id_cnt = 0;
4354 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4355 spin_unlock_irq(shost->host_lock);
4356 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004357 /* Indicate we are done walking this fc_rscn_id_list */
4358 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004359}
4360
James Smarte59058c2008-08-24 21:49:00 -04004361/**
James Smart3621a712009-04-06 18:47:14 -04004362 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004363 * @vport: pointer to a host virtual N_Port data structure.
4364 * @did: remote destination port identifier.
4365 *
4366 * This routine checks whether there is any pending Registration State
4367 * Configuration Notification (RSCN) to a @did on @vport.
4368 *
4369 * Return code
4370 * None zero - The @did matched with a pending rscn
4371 * 0 - not able to match @did with a pending rscn
4372 **/
dea31012005-04-17 16:05:31 -05004373int
James Smart2e0fef82007-06-17 19:56:36 -05004374lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004375{
4376 D_ID ns_did;
4377 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004378 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004379 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004380 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004381
4382 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004383
4384 /* Never match fabric nodes for RSCNs */
4385 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004386 return 0;
dea31012005-04-17 16:05:31 -05004387
4388 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004389 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004390 return did;
dea31012005-04-17 16:05:31 -05004391
James Smart7f5f3d02008-02-08 18:50:14 -05004392 spin_lock_irq(shost->host_lock);
4393 if (vport->fc_rscn_flush) {
4394 /* Another thread is walking fc_rscn_id_list on this vport */
4395 spin_unlock_irq(shost->host_lock);
4396 return 0;
4397 }
4398 /* Indicate we are walking fc_rscn_id_list on this vport */
4399 vport->fc_rscn_flush = 1;
4400 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004401 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004402 lp = vport->fc_rscn_id_list[i]->virt;
4403 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4404 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004405 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004406 rscn_did.un.word = be32_to_cpu(*lp++);
4407 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004408 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4409 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004410 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4411 && (ns_did.un.b.area == rscn_did.un.b.area)
4412 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004413 goto return_did_out;
dea31012005-04-17 16:05:31 -05004414 break;
James Smarteaf15d52008-12-04 22:39:29 -05004415 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004416 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4417 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004418 goto return_did_out;
dea31012005-04-17 16:05:31 -05004419 break;
James Smarteaf15d52008-12-04 22:39:29 -05004420 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004421 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004422 goto return_did_out;
dea31012005-04-17 16:05:31 -05004423 break;
James Smarteaf15d52008-12-04 22:39:29 -05004424 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004425 goto return_did_out;
dea31012005-04-17 16:05:31 -05004426 }
4427 }
James Smart92d7f7b2007-06-17 19:56:38 -05004428 }
James Smart7f5f3d02008-02-08 18:50:14 -05004429 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4430 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004431 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004432return_did_out:
4433 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4434 vport->fc_rscn_flush = 0;
4435 return did;
dea31012005-04-17 16:05:31 -05004436}
4437
James Smarte59058c2008-08-24 21:49:00 -04004438/**
James Smart3621a712009-04-06 18:47:14 -04004439 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004440 * @vport: pointer to a host virtual N_Port data structure.
4441 *
4442 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4443 * state machine for a @vport's nodes that are with pending RSCN (Registration
4444 * State Change Notification).
4445 *
4446 * Return code
4447 * 0 - Successful (currently alway return 0)
4448 **/
dea31012005-04-17 16:05:31 -05004449static int
James Smart2e0fef82007-06-17 19:56:36 -05004450lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004451{
James Smart685f0bf2007-04-25 09:53:08 -04004452 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004453
James Smart0d2b6b82008-06-14 22:52:47 -04004454 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004455 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004456 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004457 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4458 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004459 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004460 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004461 NLP_EVT_DEVICE_RECOVERY);
4462 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004463 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004464 return 0;
dea31012005-04-17 16:05:31 -05004465}
4466
James Smarte59058c2008-08-24 21:49:00 -04004467/**
James Smart3621a712009-04-06 18:47:14 -04004468 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004469 * @vport: pointer to a host virtual N_Port data structure.
4470 * @cmdiocb: pointer to lpfc command iocb data structure.
4471 *
4472 * lpfc_send_rscn_event sends an RSCN netlink event to management
4473 * applications.
4474 */
4475static void
4476lpfc_send_rscn_event(struct lpfc_vport *vport,
4477 struct lpfc_iocbq *cmdiocb)
4478{
4479 struct lpfc_dmabuf *pcmd;
4480 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4481 uint32_t *payload_ptr;
4482 uint32_t payload_len;
4483 struct lpfc_rscn_event_header *rscn_event_data;
4484
4485 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4486 payload_ptr = (uint32_t *) pcmd->virt;
4487 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4488
4489 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4490 payload_len, GFP_KERNEL);
4491 if (!rscn_event_data) {
4492 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4493 "0147 Failed to allocate memory for RSCN event\n");
4494 return;
4495 }
4496 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4497 rscn_event_data->payload_length = payload_len;
4498 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4499 payload_len);
4500
4501 fc_host_post_vendor_event(shost,
4502 fc_get_event_number(),
4503 sizeof(struct lpfc_els_event_header) + payload_len,
4504 (char *)rscn_event_data,
4505 LPFC_NL_VENDOR_ID);
4506
4507 kfree(rscn_event_data);
4508}
4509
4510/**
James Smart3621a712009-04-06 18:47:14 -04004511 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004512 * @vport: pointer to a host virtual N_Port data structure.
4513 * @cmdiocb: pointer to lpfc command iocb data structure.
4514 * @ndlp: pointer to a node-list data structure.
4515 *
4516 * This routine processes an unsolicited RSCN (Registration State Change
4517 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4518 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4519 * discover state machine is about to begin discovery, it just accepts the
4520 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4521 * contains N_Port IDs for other vports on this HBA, it just accepts the
4522 * RSCN and ignore processing it. If the state machine is in the recovery
4523 * state, the fc_rscn_id_list of this @vport is walked and the
4524 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4525 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4526 * routine is invoked to handle the RSCN event.
4527 *
4528 * Return code
4529 * 0 - Just sent the acc response
4530 * 1 - Sent the acc response and waited for name server completion
4531 **/
dea31012005-04-17 16:05:31 -05004532static int
James Smart2e0fef82007-06-17 19:56:36 -05004533lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004534 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004535{
James Smart2e0fef82007-06-17 19:56:36 -05004536 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4537 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004538 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004539 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004540 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004541 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004542 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004543 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004544 int i;
dea31012005-04-17 16:05:31 -05004545
4546 icmd = &cmdiocb->iocb;
4547 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4548 lp = (uint32_t *) pcmd->virt;
4549
James Smart92d7f7b2007-06-17 19:56:38 -05004550 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4551 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004552 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004553 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4554 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004555 vport->fc_flag, payload_len, *lp,
4556 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004557
4558 /* Send an RSCN event to the management application */
4559 lpfc_send_rscn_event(vport, cmdiocb);
4560
James Smartd2873e42006-08-18 17:46:43 -04004561 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004562 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004563 FCH_EVT_RSCN, lp[i]);
4564
dea31012005-04-17 16:05:31 -05004565 /* If we are about to begin discovery, just ACC the RSCN.
4566 * Discovery processing will satisfy it.
4567 */
James Smart2e0fef82007-06-17 19:56:36 -05004568 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004569 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4570 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4571 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4572
James Smart51ef4c22007-08-02 11:10:31 -04004573 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004574 return 0;
dea31012005-04-17 16:05:31 -05004575 }
4576
James Smart92d7f7b2007-06-17 19:56:38 -05004577 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4578 * just ACC and ignore it.
4579 */
4580 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004581 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004582 i = payload_len;
4583 datap = lp;
4584 while (i > 0) {
4585 nportid = *datap++;
4586 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4587 i -= sizeof(uint32_t);
4588 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004589 if (lpfc_find_vport_by_did(phba, nportid))
4590 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004591 }
4592 if (rscn_id == hba_id) {
4593 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004594 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004595 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004596 "Data: x%x x%x x%x x%x\n",
4597 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004598 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004599 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4600 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4601 ndlp->nlp_DID, vport->port_state,
4602 ndlp->nlp_flag);
4603
James Smart92d7f7b2007-06-17 19:56:38 -05004604 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004605 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004606 return 0;
4607 }
4608 }
4609
James Smart7f5f3d02008-02-08 18:50:14 -05004610 spin_lock_irq(shost->host_lock);
4611 if (vport->fc_rscn_flush) {
4612 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004613 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004614 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004615 /* Send back ACC */
4616 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004617 return 0;
4618 }
4619 /* Indicate we are walking fc_rscn_id_list on this vport */
4620 vport->fc_rscn_flush = 1;
4621 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004622 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004623 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004624 /* If we are already processing an RSCN, save the received
4625 * RSCN payload buffer, cmdiocb->context2 to process later.
4626 */
James Smart2e0fef82007-06-17 19:56:36 -05004627 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004628 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4629 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4630 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4631
James Smart09372822008-01-11 01:52:54 -05004632 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004633 vport->fc_flag |= FC_RSCN_DEFERRED;
4634 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004635 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004636 vport->fc_flag |= FC_RSCN_MODE;
4637 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004638 if (rscn_cnt) {
4639 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4640 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4641 }
4642 if ((rscn_cnt) &&
4643 (payload_len + length <= LPFC_BPL_SIZE)) {
4644 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004645 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004646 memcpy(((uint8_t *)cmd) + length, lp,
4647 payload_len);
4648 } else {
4649 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4650 vport->fc_rscn_id_cnt++;
4651 /* If we zero, cmdiocb->context2, the calling
4652 * routine will not try to free it.
4653 */
4654 cmdiocb->context2 = NULL;
4655 }
dea31012005-04-17 16:05:31 -05004656 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004657 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4658 "0235 Deferred RSCN "
4659 "Data: x%x x%x x%x\n",
4660 vport->fc_rscn_id_cnt, vport->fc_flag,
4661 vport->port_state);
dea31012005-04-17 16:05:31 -05004662 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004663 vport->fc_flag |= FC_RSCN_DISCOVERY;
4664 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004665 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004666 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4667 "0234 ReDiscovery RSCN "
4668 "Data: x%x x%x x%x\n",
4669 vport->fc_rscn_id_cnt, vport->fc_flag,
4670 vport->port_state);
dea31012005-04-17 16:05:31 -05004671 }
James Smart7f5f3d02008-02-08 18:50:14 -05004672 /* Indicate we are done walking fc_rscn_id_list on this vport */
4673 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004674 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004675 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004676 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004677 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004678 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004679 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004680 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004681 return 0;
dea31012005-04-17 16:05:31 -05004682 }
James Smart858c9f62007-06-17 19:56:39 -05004683 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4684 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4685 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4686
James Smart2e0fef82007-06-17 19:56:36 -05004687 spin_lock_irq(shost->host_lock);
4688 vport->fc_flag |= FC_RSCN_MODE;
4689 spin_unlock_irq(shost->host_lock);
4690 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004691 /* Indicate we are done walking fc_rscn_id_list on this vport */
4692 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004693 /*
4694 * If we zero, cmdiocb->context2, the calling routine will
4695 * not try to free it.
4696 */
4697 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004698 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004699 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004700 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004701 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004702 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004703 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004704}
4705
James Smarte59058c2008-08-24 21:49:00 -04004706/**
James Smart3621a712009-04-06 18:47:14 -04004707 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004708 * @vport: pointer to a host virtual N_Port data structure.
4709 *
4710 * This routine handles the Registration State Configuration Notification
4711 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4712 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4713 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4714 * NameServer shall be issued. If CT command to the NameServer fails to be
4715 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4716 * RSCN activities with the @vport.
4717 *
4718 * Return code
4719 * 0 - Cleaned up rscn on the @vport
4720 * 1 - Wait for plogi to name server before proceed
4721 **/
dea31012005-04-17 16:05:31 -05004722int
James Smart2e0fef82007-06-17 19:56:36 -05004723lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004724{
4725 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004726 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004727
James Smart92d7f7b2007-06-17 19:56:38 -05004728 /* Ignore RSCN if the port is being torn down. */
4729 if (vport->load_flag & FC_UNLOADING) {
4730 lpfc_els_flush_rscn(vport);
4731 return 0;
4732 }
4733
dea31012005-04-17 16:05:31 -05004734 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004735 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004736
4737 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004738 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4739 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4740 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4741 vport->port_state);
dea31012005-04-17 16:05:31 -05004742
4743 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004744 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004745 vport->num_disc_nodes = 0;
4746
James Smart2e0fef82007-06-17 19:56:36 -05004747 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004748 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4749 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004750 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004751 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004752 /* Wait for NameServer query cmpl before we can
4753 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004754 return 1;
dea31012005-04-17 16:05:31 -05004755 } else {
4756 /* If login to NameServer does not exist, issue one */
4757 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004758 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004759 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004760 /* Wait for NameServer login cmpl before we can
4761 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004762 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004763
James Smarte47c9092008-02-08 18:49:26 -05004764 if (ndlp) {
4765 ndlp = lpfc_enable_node(vport, ndlp,
4766 NLP_STE_PLOGI_ISSUE);
4767 if (!ndlp) {
4768 lpfc_els_flush_rscn(vport);
4769 return 0;
4770 }
4771 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004772 } else {
James Smarte47c9092008-02-08 18:49:26 -05004773 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4774 if (!ndlp) {
4775 lpfc_els_flush_rscn(vport);
4776 return 0;
4777 }
James Smart2e0fef82007-06-17 19:56:36 -05004778 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004779 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004780 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004781 }
James Smarte47c9092008-02-08 18:49:26 -05004782 ndlp->nlp_type |= NLP_FABRIC;
4783 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4784 /* Wait for NameServer login cmpl before we can
4785 * continue
4786 */
4787 return 1;
dea31012005-04-17 16:05:31 -05004788 }
4789
James Smart2e0fef82007-06-17 19:56:36 -05004790 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004791 return 0;
dea31012005-04-17 16:05:31 -05004792}
4793
James Smarte59058c2008-08-24 21:49:00 -04004794/**
James Smart3621a712009-04-06 18:47:14 -04004795 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004796 * @vport: pointer to a host virtual N_Port data structure.
4797 * @cmdiocb: pointer to lpfc command iocb data structure.
4798 * @ndlp: pointer to a node-list data structure.
4799 *
4800 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4801 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4802 * point topology. As an unsolicited FLOGI should not be received in a loop
4803 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4804 * lpfc_check_sparm() routine is invoked to check the parameters in the
4805 * unsolicited FLOGI. If parameters validation failed, the routine
4806 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4807 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4808 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4809 * will initiate PLOGI. The higher lexicographical value party shall has
4810 * higher priority (as the winning port) and will initiate PLOGI and
4811 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4812 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4813 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4814 *
4815 * Return code
4816 * 0 - Successfully processed the unsolicited flogi
4817 * 1 - Failed to process the unsolicited flogi
4818 **/
dea31012005-04-17 16:05:31 -05004819static int
James Smart2e0fef82007-06-17 19:56:36 -05004820lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004821 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004822{
James Smart2e0fef82007-06-17 19:56:36 -05004823 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4824 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004825 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4826 uint32_t *lp = (uint32_t *) pcmd->virt;
4827 IOCB_t *icmd = &cmdiocb->iocb;
4828 struct serv_parm *sp;
4829 LPFC_MBOXQ_t *mbox;
4830 struct ls_rjt stat;
4831 uint32_t cmd, did;
4832 int rc;
4833
4834 cmd = *lp++;
4835 sp = (struct serv_parm *) lp;
4836
4837 /* FLOGI received */
4838
James Smart2e0fef82007-06-17 19:56:36 -05004839 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004840
James Smart76a95d72010-11-20 23:11:48 -05004841 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004842 /* We should never receive a FLOGI in loop mode, ignore it */
4843 did = icmd->un.elsreq64.remoteID;
4844
4845 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4846 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004847 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4848 "0113 An FLOGI ELS command x%x was "
4849 "received from DID x%x in Loop Mode\n",
4850 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004851 return 1;
dea31012005-04-17 16:05:31 -05004852 }
4853
4854 did = Fabric_DID;
4855
James Smart341af102010-01-26 23:07:37 -05004856 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004857 /* For a FLOGI we accept, then if our portname is greater
4858 * then the remote portname we initiate Nport login.
4859 */
4860
James Smart2e0fef82007-06-17 19:56:36 -05004861 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004862 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004863
4864 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004865 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4866 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004867 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004868
dea31012005-04-17 16:05:31 -05004869 lpfc_linkdown(phba);
4870 lpfc_init_link(phba, mbox,
4871 phba->cfg_topology,
4872 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004873 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004874 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004875 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004876 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004877 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004878 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004879 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004880 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004881 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004882 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004883 spin_lock_irq(shost->host_lock);
4884 vport->fc_flag |= FC_PT2PT_PLOGI;
4885 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004886 }
James Smart2e0fef82007-06-17 19:56:36 -05004887 spin_lock_irq(shost->host_lock);
4888 vport->fc_flag |= FC_PT2PT;
4889 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4890 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004891 } else {
4892 /* Reject this request because invalid parameters */
4893 stat.un.b.lsRjtRsvd0 = 0;
4894 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4895 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4896 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004897 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4898 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004899 return 1;
dea31012005-04-17 16:05:31 -05004900 }
4901
4902 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004903 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004904
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004905 return 0;
dea31012005-04-17 16:05:31 -05004906}
4907
James Smarte59058c2008-08-24 21:49:00 -04004908/**
James Smart3621a712009-04-06 18:47:14 -04004909 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004910 * @vport: pointer to a host virtual N_Port data structure.
4911 * @cmdiocb: pointer to lpfc command iocb data structure.
4912 * @ndlp: pointer to a node-list data structure.
4913 *
4914 * This routine processes Request Node Identification Data (RNID) IOCB
4915 * received as an ELS unsolicited event. Only when the RNID specified format
4916 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4917 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4918 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4919 * rejected by invoking the lpfc_els_rsp_reject() routine.
4920 *
4921 * Return code
4922 * 0 - Successfully processed rnid iocb (currently always return 0)
4923 **/
dea31012005-04-17 16:05:31 -05004924static int
James Smart2e0fef82007-06-17 19:56:36 -05004925lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4926 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004927{
4928 struct lpfc_dmabuf *pcmd;
4929 uint32_t *lp;
4930 IOCB_t *icmd;
4931 RNID *rn;
4932 struct ls_rjt stat;
4933 uint32_t cmd, did;
4934
4935 icmd = &cmdiocb->iocb;
4936 did = icmd->un.elsreq64.remoteID;
4937 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4938 lp = (uint32_t *) pcmd->virt;
4939
4940 cmd = *lp++;
4941 rn = (RNID *) lp;
4942
4943 /* RNID received */
4944
4945 switch (rn->Format) {
4946 case 0:
4947 case RNID_TOPOLOGY_DISC:
4948 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004949 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004950 break;
4951 default:
4952 /* Reject this request because format not supported */
4953 stat.un.b.lsRjtRsvd0 = 0;
4954 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4955 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4956 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004957 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4958 NULL);
dea31012005-04-17 16:05:31 -05004959 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004960 return 0;
dea31012005-04-17 16:05:31 -05004961}
4962
James Smarte59058c2008-08-24 21:49:00 -04004963/**
James Smart12265f62010-10-22 11:05:53 -04004964 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4965 * @vport: pointer to a host virtual N_Port data structure.
4966 * @cmdiocb: pointer to lpfc command iocb data structure.
4967 * @ndlp: pointer to a node-list data structure.
4968 *
4969 * Return code
4970 * 0 - Successfully processed echo iocb (currently always return 0)
4971 **/
4972static int
4973lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4974 struct lpfc_nodelist *ndlp)
4975{
4976 uint8_t *pcmd;
4977
4978 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4979
4980 /* skip over first word of echo command to find echo data */
4981 pcmd += sizeof(uint32_t);
4982
4983 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
4984 return 0;
4985}
4986
4987/**
James Smart3621a712009-04-06 18:47:14 -04004988 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004989 * @vport: pointer to a host virtual N_Port data structure.
4990 * @cmdiocb: pointer to lpfc command iocb data structure.
4991 * @ndlp: pointer to a node-list data structure.
4992 *
4993 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4994 * received as an ELS unsolicited event. Currently, this function just invokes
4995 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4996 *
4997 * Return code
4998 * 0 - Successfully processed lirr iocb (currently always return 0)
4999 **/
dea31012005-04-17 16:05:31 -05005000static int
James Smart2e0fef82007-06-17 19:56:36 -05005001lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5002 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005003{
5004 struct ls_rjt stat;
5005
5006 /* For now, unconditionally reject this command */
5007 stat.un.b.lsRjtRsvd0 = 0;
5008 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5009 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5010 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005011 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005012 return 0;
5013}
5014
James Smarte59058c2008-08-24 21:49:00 -04005015/**
James Smart5ffc2662009-11-18 15:39:44 -05005016 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5017 * @vport: pointer to a host virtual N_Port data structure.
5018 * @cmdiocb: pointer to lpfc command iocb data structure.
5019 * @ndlp: pointer to a node-list data structure.
5020 *
5021 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5022 * received as an ELS unsolicited event. A request to RRQ shall only
5023 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5024 * Nx_Port N_Port_ID of the target Exchange is the same as the
5025 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5026 * not accepted, an LS_RJT with reason code "Unable to perform
5027 * command request" and reason code explanation "Invalid Originator
5028 * S_ID" shall be returned. For now, we just unconditionally accept
5029 * RRQ from the target.
5030 **/
5031static void
5032lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5033 struct lpfc_nodelist *ndlp)
5034{
5035 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05005036 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5037 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05005038}
5039
5040/**
James Smart12265f62010-10-22 11:05:53 -04005041 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5042 * @phba: pointer to lpfc hba data structure.
5043 * @pmb: pointer to the driver internal queue element for mailbox command.
5044 *
5045 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5046 * mailbox command. This callback function is to actually send the Accept
5047 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5048 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5049 * mailbox command, constructs the RPS response with the link statistics
5050 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5051 * response to the RPS.
5052 *
5053 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5054 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5055 * will be stored into the context1 field of the IOCB for the completion
5056 * callback function to the RPS Accept Response ELS IOCB command.
5057 *
5058 **/
5059static void
5060lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5061{
5062 MAILBOX_t *mb;
5063 IOCB_t *icmd;
5064 struct RLS_RSP *rls_rsp;
5065 uint8_t *pcmd;
5066 struct lpfc_iocbq *elsiocb;
5067 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005068 uint16_t oxid;
5069 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04005070 uint32_t cmdsize;
5071
5072 mb = &pmb->u.mb;
5073
5074 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005075 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5076 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04005077 pmb->context1 = NULL;
5078 pmb->context2 = NULL;
5079
5080 if (mb->mbxStatus) {
5081 mempool_free(pmb, phba->mbox_mem_pool);
5082 return;
5083 }
5084
5085 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
5086 mempool_free(pmb, phba->mbox_mem_pool);
5087 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5088 lpfc_max_els_tries, ndlp,
5089 ndlp->nlp_DID, ELS_CMD_ACC);
5090
5091 /* Decrement the ndlp reference count from previous mbox command */
5092 lpfc_nlp_put(ndlp);
5093
5094 if (!elsiocb)
5095 return;
5096
5097 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005098 icmd->ulpContext = rxid;
5099 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04005100
5101 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5102 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5103 pcmd += sizeof(uint32_t); /* Skip past command */
5104 rls_rsp = (struct RLS_RSP *)pcmd;
5105
5106 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5107 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5108 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5109 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5110 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5111 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
5112
5113 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5114 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5115 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5116 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5117 elsiocb->iotag, elsiocb->iocb.ulpContext,
5118 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5119 ndlp->nlp_rpi);
5120 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5121 phba->fc_stat.elsXmitACC++;
5122 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5123 lpfc_els_free_iocb(phba, elsiocb);
5124}
5125
5126/**
James Smart3621a712009-04-06 18:47:14 -04005127 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005128 * @phba: pointer to lpfc hba data structure.
5129 * @pmb: pointer to the driver internal queue element for mailbox command.
5130 *
5131 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5132 * mailbox command. This callback function is to actually send the Accept
5133 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5134 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5135 * mailbox command, constructs the RPS response with the link statistics
5136 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5137 * response to the RPS.
5138 *
5139 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5140 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5141 * will be stored into the context1 field of the IOCB for the completion
5142 * callback function to the RPS Accept Response ELS IOCB command.
5143 *
5144 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005145static void
James Smart329f9bc2007-04-25 09:53:01 -04005146lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005147{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005148 MAILBOX_t *mb;
5149 IOCB_t *icmd;
5150 RPS_RSP *rps_rsp;
5151 uint8_t *pcmd;
5152 struct lpfc_iocbq *elsiocb;
5153 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005154 uint16_t status;
5155 uint16_t oxid;
5156 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005157 uint32_t cmdsize;
5158
James Smart04c68492009-05-22 14:52:52 -04005159 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005160
5161 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005162 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5163 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07005164 pmb->context1 = NULL;
5165 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005166
5167 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005168 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005169 return;
5170 }
5171
5172 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005173 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005174 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5175 lpfc_max_els_tries, ndlp,
5176 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005177
5178 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005179 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005180
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005181 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005182 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005183
5184 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005185 icmd->ulpContext = rxid;
5186 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005187
5188 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5189 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005190 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005191 rps_rsp = (RPS_RSP *)pcmd;
5192
James Smart76a95d72010-11-20 23:11:48 -05005193 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005194 status = 0x10;
5195 else
5196 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005197 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005198 status |= 0x4;
5199
5200 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005201 rps_rsp->portStatus = cpu_to_be16(status);
5202 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5203 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5204 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5205 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5206 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5207 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005208 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005209 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5210 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5211 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5212 elsiocb->iotag, elsiocb->iocb.ulpContext,
5213 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5214 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005215 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005216 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005217 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005218 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005219 return;
5220}
5221
James Smarte59058c2008-08-24 21:49:00 -04005222/**
James Smart12265f62010-10-22 11:05:53 -04005223 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5224 * @vport: pointer to a host virtual N_Port data structure.
5225 * @cmdiocb: pointer to lpfc command iocb data structure.
5226 * @ndlp: pointer to a node-list data structure.
5227 *
5228 * This routine processes Read Port Status (RPL) IOCB received as an
5229 * ELS unsolicited event. It first checks the remote port state. If the
5230 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5231 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5232 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5233 * for reading the HBA link statistics. It is for the callback function,
5234 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5235 * to actually sending out RPL Accept (ACC) response.
5236 *
5237 * Return codes
5238 * 0 - Successfully processed rls iocb (currently always return 0)
5239 **/
5240static int
5241lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5242 struct lpfc_nodelist *ndlp)
5243{
5244 struct lpfc_hba *phba = vport->phba;
5245 LPFC_MBOXQ_t *mbox;
5246 struct lpfc_dmabuf *pcmd;
5247 struct ls_rjt stat;
5248
5249 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5250 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5251 /* reject the unsolicited RPS request and done with it */
5252 goto reject_out;
5253
5254 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5255
5256 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5257 if (mbox) {
5258 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005259 mbox->context1 = (void *)((unsigned long)
5260 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5261 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04005262 mbox->context2 = lpfc_nlp_get(ndlp);
5263 mbox->vport = vport;
5264 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5265 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5266 != MBX_NOT_FINISHED)
5267 /* Mbox completion will send ELS Response */
5268 return 0;
5269 /* Decrement reference count used for the failed mbox
5270 * command.
5271 */
5272 lpfc_nlp_put(ndlp);
5273 mempool_free(mbox, phba->mbox_mem_pool);
5274 }
5275reject_out:
5276 /* issue rejection response */
5277 stat.un.b.lsRjtRsvd0 = 0;
5278 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5279 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5280 stat.un.b.vendorUnique = 0;
5281 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5282 return 0;
5283}
5284
5285/**
5286 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5287 * @vport: pointer to a host virtual N_Port data structure.
5288 * @cmdiocb: pointer to lpfc command iocb data structure.
5289 * @ndlp: pointer to a node-list data structure.
5290 *
5291 * This routine processes Read Timout Value (RTV) IOCB received as an
5292 * ELS unsolicited event. It first checks the remote port state. If the
5293 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5294 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5295 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5296 * Value (RTV) unsolicited IOCB event.
5297 *
5298 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5299 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5300 * will be stored into the context1 field of the IOCB for the completion
5301 * callback function to the RPS Accept Response ELS IOCB command.
5302 *
5303 * Return codes
5304 * 0 - Successfully processed rtv iocb (currently always return 0)
5305 **/
5306static int
5307lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5308 struct lpfc_nodelist *ndlp)
5309{
5310 struct lpfc_hba *phba = vport->phba;
5311 struct ls_rjt stat;
5312 struct RTV_RSP *rtv_rsp;
5313 uint8_t *pcmd;
5314 struct lpfc_iocbq *elsiocb;
5315 uint32_t cmdsize;
5316
5317
5318 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5319 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5320 /* reject the unsolicited RPS request and done with it */
5321 goto reject_out;
5322
5323 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5324 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5325 lpfc_max_els_tries, ndlp,
5326 ndlp->nlp_DID, ELS_CMD_ACC);
5327
5328 if (!elsiocb)
5329 return 1;
5330
5331 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5332 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5333 pcmd += sizeof(uint32_t); /* Skip past command */
5334
5335 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04005336 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
5337 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04005338
5339 rtv_rsp = (struct RTV_RSP *)pcmd;
5340
5341 /* populate RTV payload */
5342 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5343 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5344 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5345 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5346 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5347
5348 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5349 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5350 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5351 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5352 "Data: x%x x%x x%x\n",
5353 elsiocb->iotag, elsiocb->iocb.ulpContext,
5354 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5355 ndlp->nlp_rpi,
5356 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5357 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5358 phba->fc_stat.elsXmitACC++;
5359 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5360 lpfc_els_free_iocb(phba, elsiocb);
5361 return 0;
5362
5363reject_out:
5364 /* issue rejection response */
5365 stat.un.b.lsRjtRsvd0 = 0;
5366 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5367 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5368 stat.un.b.vendorUnique = 0;
5369 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5370 return 0;
5371}
5372
5373/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005374 * @vport: pointer to a host virtual N_Port data structure.
5375 * @cmdiocb: pointer to lpfc command iocb data structure.
5376 * @ndlp: pointer to a node-list data structure.
5377 *
5378 * This routine processes Read Port Status (RPS) IOCB received as an
5379 * ELS unsolicited event. It first checks the remote port state. If the
5380 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5381 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5382 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5383 * for reading the HBA link statistics. It is for the callback function,
5384 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5385 * to actually sending out RPS Accept (ACC) response.
5386 *
5387 * Return codes
5388 * 0 - Successfully processed rps iocb (currently always return 0)
5389 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005390static int
James Smart2e0fef82007-06-17 19:56:36 -05005391lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5392 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005393{
James Smart2e0fef82007-06-17 19:56:36 -05005394 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005395 uint32_t *lp;
5396 uint8_t flag;
5397 LPFC_MBOXQ_t *mbox;
5398 struct lpfc_dmabuf *pcmd;
5399 RPS *rps;
5400 struct ls_rjt stat;
5401
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005402 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005403 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5404 /* reject the unsolicited RPS request and done with it */
5405 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005406
5407 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5408 lp = (uint32_t *) pcmd->virt;
5409 flag = (be32_to_cpu(*lp++) & 0xf);
5410 rps = (RPS *) lp;
5411
5412 if ((flag == 0) ||
5413 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005414 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005415 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005416
James Smart92d7f7b2007-06-17 19:56:38 -05005417 printk("Fix me....\n");
5418 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005419 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5420 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005421 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005422 mbox->context1 = (void *)((unsigned long)
5423 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5424 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04005425 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005426 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005427 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005428 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005429 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005430 /* Mbox completion will send ELS Response */
5431 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005432 /* Decrement reference count used for the failed mbox
5433 * command.
5434 */
James Smart329f9bc2007-04-25 09:53:01 -04005435 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005436 mempool_free(mbox, phba->mbox_mem_pool);
5437 }
5438 }
James Smart90160e02008-08-24 21:49:45 -04005439
5440reject_out:
5441 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005442 stat.un.b.lsRjtRsvd0 = 0;
5443 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5444 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5445 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005446 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005447 return 0;
5448}
5449
James Smart19ca7602010-11-20 23:11:55 -05005450/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5451 * @vport: pointer to a host virtual N_Port data structure.
5452 * @ndlp: pointer to a node-list data structure.
5453 * @did: DID of the target.
5454 * @rrq: Pointer to the rrq struct.
5455 *
5456 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5457 * Successful the the completion handler will clear the RRQ.
5458 *
5459 * Return codes
5460 * 0 - Successfully sent rrq els iocb.
5461 * 1 - Failed to send rrq els iocb.
5462 **/
5463static int
5464lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5465 uint32_t did, struct lpfc_node_rrq *rrq)
5466{
5467 struct lpfc_hba *phba = vport->phba;
5468 struct RRQ *els_rrq;
5469 IOCB_t *icmd;
5470 struct lpfc_iocbq *elsiocb;
5471 uint8_t *pcmd;
5472 uint16_t cmdsize;
5473 int ret;
5474
5475
5476 if (ndlp != rrq->ndlp)
5477 ndlp = rrq->ndlp;
5478 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5479 return 1;
5480
5481 /* If ndlp is not NULL, we will bump the reference count on it */
5482 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5483 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5484 ELS_CMD_RRQ);
5485 if (!elsiocb)
5486 return 1;
5487
5488 icmd = &elsiocb->iocb;
5489 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5490
5491 /* For RRQ request, remainder of payload is Exchange IDs */
5492 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5493 pcmd += sizeof(uint32_t);
5494 els_rrq = (struct RRQ *) pcmd;
5495
5496 bf_set(rrq_oxid, els_rrq, rrq->xritag);
5497 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5498 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5499 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5500 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5501
5502
5503 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5504 "Issue RRQ: did:x%x",
5505 did, rrq->xritag, rrq->rxid);
5506 elsiocb->context_un.rrq = rrq;
5507 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5508 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5509
5510 if (ret == IOCB_ERROR) {
5511 lpfc_els_free_iocb(phba, elsiocb);
5512 return 1;
5513 }
5514 return 0;
5515}
5516
5517/**
5518 * lpfc_send_rrq - Sends ELS RRQ if needed.
5519 * @phba: pointer to lpfc hba data structure.
5520 * @rrq: pointer to the active rrq.
5521 *
5522 * This routine will call the lpfc_issue_els_rrq if the rrq is
5523 * still active for the xri. If this function returns a failure then
5524 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5525 *
5526 * Returns 0 Success.
5527 * 1 Failure.
5528 **/
5529int
5530lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5531{
5532 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5533 rrq->nlp_DID);
5534 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5535 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5536 rrq->nlp_DID, rrq);
5537 else
5538 return 1;
5539}
5540
James Smarte59058c2008-08-24 21:49:00 -04005541/**
James Smart3621a712009-04-06 18:47:14 -04005542 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005543 * @vport: pointer to a host virtual N_Port data structure.
5544 * @cmdsize: size of the ELS command.
5545 * @oldiocb: pointer to the original lpfc command iocb data structure.
5546 * @ndlp: pointer to a node-list data structure.
5547 *
5548 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5549 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5550 *
5551 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5552 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5553 * will be stored into the context1 field of the IOCB for the completion
5554 * callback function to the RPL Accept Response ELS command.
5555 *
5556 * Return code
5557 * 0 - Successfully issued ACC RPL ELS command
5558 * 1 - Failed to issue ACC RPL ELS command
5559 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005560static int
James Smart2e0fef82007-06-17 19:56:36 -05005561lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5562 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005563{
James Smart2e0fef82007-06-17 19:56:36 -05005564 struct lpfc_hba *phba = vport->phba;
5565 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005566 RPL_RSP rpl_rsp;
5567 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005568 uint8_t *pcmd;
5569
James Smart2e0fef82007-06-17 19:56:36 -05005570 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5571 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005572
James Smart488d1462006-03-07 15:02:37 -05005573 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005574 return 1;
James Smart488d1462006-03-07 15:02:37 -05005575
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005576 icmd = &elsiocb->iocb;
5577 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005578 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5579 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005580
5581 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5582 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005583 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005584 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5585 pcmd += sizeof(uint16_t);
5586
5587 /* Setup the RPL ACC payload */
5588 rpl_rsp.listLen = be32_to_cpu(1);
5589 rpl_rsp.index = 0;
5590 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005591 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5592 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005593 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005594 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005595 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005596 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5597 "0120 Xmit ELS RPL ACC response tag x%x "
5598 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5599 "rpi x%x\n",
5600 elsiocb->iotag, elsiocb->iocb.ulpContext,
5601 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5602 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005603 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005604 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005605 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5606 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005607 lpfc_els_free_iocb(phba, elsiocb);
5608 return 1;
5609 }
5610 return 0;
5611}
5612
James Smarte59058c2008-08-24 21:49:00 -04005613/**
James Smart3621a712009-04-06 18:47:14 -04005614 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005615 * @vport: pointer to a host virtual N_Port data structure.
5616 * @cmdiocb: pointer to lpfc command iocb data structure.
5617 * @ndlp: pointer to a node-list data structure.
5618 *
5619 * This routine processes Read Port List (RPL) IOCB received as an ELS
5620 * unsolicited event. It first checks the remote port state. If the remote
5621 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5622 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5623 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5624 * to accept the RPL.
5625 *
5626 * Return code
5627 * 0 - Successfully processed rpl iocb (currently always return 0)
5628 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005629static int
James Smart2e0fef82007-06-17 19:56:36 -05005630lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5631 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005632{
5633 struct lpfc_dmabuf *pcmd;
5634 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005635 uint32_t maxsize;
5636 uint16_t cmdsize;
5637 RPL *rpl;
5638 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005639
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005640 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5641 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005642 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005643 stat.un.b.lsRjtRsvd0 = 0;
5644 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5645 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5646 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005647 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5648 NULL);
James Smart90160e02008-08-24 21:49:45 -04005649 /* rejected the unsolicited RPL request and done with it */
5650 return 0;
dea31012005-04-17 16:05:31 -05005651 }
5652
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005653 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5654 lp = (uint32_t *) pcmd->virt;
5655 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005656 maxsize = be32_to_cpu(rpl->maxsize);
5657
5658 /* We support only one port */
5659 if ((rpl->index == 0) &&
5660 ((maxsize == 0) ||
5661 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5662 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005663 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005664 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5665 }
James Smart2e0fef82007-06-17 19:56:36 -05005666 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005667
5668 return 0;
5669}
5670
James Smarte59058c2008-08-24 21:49:00 -04005671/**
James Smart3621a712009-04-06 18:47:14 -04005672 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005673 * @vport: pointer to a virtual N_Port data structure.
5674 * @cmdiocb: pointer to lpfc command iocb data structure.
5675 * @ndlp: pointer to a node-list data structure.
5676 *
5677 * This routine processes Fibre Channel Address Resolution Protocol
5678 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5679 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5680 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5681 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5682 * remote PortName is compared against the FC PortName stored in the @vport
5683 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5684 * compared against the FC NodeName stored in the @vport data structure.
5685 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5686 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5687 * invoked to send out FARP Response to the remote node. Before sending the
5688 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5689 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5690 * routine is invoked to log into the remote port first.
5691 *
5692 * Return code
5693 * 0 - Either the FARP Match Mode not supported or successfully processed
5694 **/
dea31012005-04-17 16:05:31 -05005695static int
James Smart2e0fef82007-06-17 19:56:36 -05005696lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5697 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005698{
5699 struct lpfc_dmabuf *pcmd;
5700 uint32_t *lp;
5701 IOCB_t *icmd;
5702 FARP *fp;
5703 uint32_t cmd, cnt, did;
5704
5705 icmd = &cmdiocb->iocb;
5706 did = icmd->un.elsreq64.remoteID;
5707 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5708 lp = (uint32_t *) pcmd->virt;
5709
5710 cmd = *lp++;
5711 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005712 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005713 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5714 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005715 /* We will only support match on WWPN or WWNN */
5716 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005717 return 0;
dea31012005-04-17 16:05:31 -05005718 }
5719
5720 cnt = 0;
5721 /* If this FARP command is searching for my portname */
5722 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005723 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005724 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005725 cnt = 1;
5726 }
5727
5728 /* If this FARP command is searching for my nodename */
5729 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005730 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005731 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005732 cnt = 1;
5733 }
5734
5735 if (cnt) {
5736 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5737 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5738 /* Log back into the node before sending the FARP. */
5739 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005740 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005741 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005742 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005743 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005744 }
5745
5746 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005747 if (fp->Rflags & FARP_REQUEST_FARPR)
5748 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005749 }
5750 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005751 return 0;
dea31012005-04-17 16:05:31 -05005752}
5753
James Smarte59058c2008-08-24 21:49:00 -04005754/**
James Smart3621a712009-04-06 18:47:14 -04005755 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005756 * @vport: pointer to a host virtual N_Port data structure.
5757 * @cmdiocb: pointer to lpfc command iocb data structure.
5758 * @ndlp: pointer to a node-list data structure.
5759 *
5760 * This routine processes Fibre Channel Address Resolution Protocol
5761 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5762 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5763 * the FARP response request.
5764 *
5765 * Return code
5766 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5767 **/
dea31012005-04-17 16:05:31 -05005768static int
James Smart2e0fef82007-06-17 19:56:36 -05005769lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5770 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005771{
5772 struct lpfc_dmabuf *pcmd;
5773 uint32_t *lp;
5774 IOCB_t *icmd;
5775 uint32_t cmd, did;
5776
5777 icmd = &cmdiocb->iocb;
5778 did = icmd->un.elsreq64.remoteID;
5779 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5780 lp = (uint32_t *) pcmd->virt;
5781
5782 cmd = *lp++;
5783 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005784 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5785 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005786 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005787 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005788
5789 return 0;
5790}
5791
James Smarte59058c2008-08-24 21:49:00 -04005792/**
James Smart3621a712009-04-06 18:47:14 -04005793 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005794 * @vport: pointer to a host virtual N_Port data structure.
5795 * @cmdiocb: pointer to lpfc command iocb data structure.
5796 * @fan_ndlp: pointer to a node-list data structure.
5797 *
5798 * This routine processes a Fabric Address Notification (FAN) IOCB
5799 * command received as an ELS unsolicited event. The FAN ELS command will
5800 * only be processed on a physical port (i.e., the @vport represents the
5801 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5802 * compared against those in the phba data structure. If any of those is
5803 * different, the lpfc_initial_flogi() routine is invoked to initialize
5804 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5805 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5806 * is invoked to register login to the fabric.
5807 *
5808 * Return code
5809 * 0 - Successfully processed fan iocb (currently always return 0).
5810 **/
dea31012005-04-17 16:05:31 -05005811static int
James Smart2e0fef82007-06-17 19:56:36 -05005812lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5813 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005814{
James Smart2e0fef82007-06-17 19:56:36 -05005815 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005816 uint32_t *lp;
5817 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005818
James Smart0d2b6b82008-06-14 22:52:47 -04005819 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5820 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5821 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005822 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005823 if ((vport == phba->pport) &&
5824 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005825 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005826 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005827 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005828 sizeof(struct lpfc_name)))) {
5829 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05005830 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005831 } else {
5832 /* FAN verified - skip FLOGI */
5833 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005834 if (phba->sli_rev < LPFC_SLI_REV4)
5835 lpfc_issue_fabric_reglogin(vport);
5836 else
5837 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005838 }
dea31012005-04-17 16:05:31 -05005839 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005840 return 0;
dea31012005-04-17 16:05:31 -05005841}
5842
James Smarte59058c2008-08-24 21:49:00 -04005843/**
James Smart3621a712009-04-06 18:47:14 -04005844 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005845 * @ptr: holder for the timer function associated data.
5846 *
5847 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5848 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5849 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5850 * up the worker thread. It is for the worker thread to invoke the routine
5851 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5852 **/
dea31012005-04-17 16:05:31 -05005853void
5854lpfc_els_timeout(unsigned long ptr)
5855{
James Smart2e0fef82007-06-17 19:56:36 -05005856 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5857 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005858 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005859 unsigned long iflag;
5860
James Smart2e0fef82007-06-17 19:56:36 -05005861 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005862 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5863 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005864 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005865 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005866
James Smart5e9d9b82008-06-14 22:52:53 -04005867 if (!tmo_posted)
5868 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005869 return;
5870}
5871
James Smart2a9bf3d2010-06-07 15:24:45 -04005872
James Smarte59058c2008-08-24 21:49:00 -04005873/**
James Smart3621a712009-04-06 18:47:14 -04005874 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005875 * @vport: pointer to a virtual N_Port data structure.
5876 *
5877 * This routine is the actual handler function that processes an ELS timeout
5878 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5879 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5880 * invoking the lpfc_sli_issue_abort_iotag() routine.
5881 **/
dea31012005-04-17 16:05:31 -05005882void
James Smart2e0fef82007-06-17 19:56:36 -05005883lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005884{
James Smart2e0fef82007-06-17 19:56:36 -05005885 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005886 struct lpfc_sli_ring *pring;
5887 struct lpfc_iocbq *tmp_iocb, *piocb;
5888 IOCB_t *cmd = NULL;
5889 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005890 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005891 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005892 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005893 LIST_HEAD(txcmplq_completions);
5894 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005895
James Smart2a9bf3d2010-06-07 15:24:45 -04005896
dea31012005-04-17 16:05:31 -05005897 timeout = (uint32_t)(phba->fc_ratov << 1);
5898
5899 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005900
James Smart2a9bf3d2010-06-07 15:24:45 -04005901 spin_lock_irq(&phba->hbalock);
5902 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5903 spin_unlock_irq(&phba->hbalock);
5904
5905 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005906 cmd = &piocb->iocb;
5907
James Smart2e0fef82007-06-17 19:56:36 -05005908 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5909 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5910 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005911 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005912
5913 if (piocb->vport != vport)
5914 continue;
5915
dea31012005-04-17 16:05:31 -05005916 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005917 if (pcmd)
5918 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005919
James Smart92d7f7b2007-06-17 19:56:38 -05005920 if (els_command == ELS_CMD_FARP ||
5921 els_command == ELS_CMD_FARPR ||
5922 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005923 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005924
dea31012005-04-17 16:05:31 -05005925 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005926 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005927 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005928 else
dea31012005-04-17 16:05:31 -05005929 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005930 continue;
5931 }
5932
James Smart2e0fef82007-06-17 19:56:36 -05005933 remote_ID = 0xffffffff;
5934 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005935 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005936 else {
5937 struct lpfc_nodelist *ndlp;
5938 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005939 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005940 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005941 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005942 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05005943 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005944 spin_lock_irq(&phba->hbalock);
5945 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05005946 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005947
James Smart2a9bf3d2010-06-07 15:24:45 -04005948 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5949 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5950 "0127 ELS timeout Data: x%x x%x x%x "
5951 "x%x\n", els_command,
5952 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5953 spin_lock_irq(&phba->hbalock);
5954 list_del_init(&piocb->dlist);
5955 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5956 spin_unlock_irq(&phba->hbalock);
5957 }
5958
James Smart2e0fef82007-06-17 19:56:36 -05005959 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5960 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005961}
5962
James Smarte59058c2008-08-24 21:49:00 -04005963/**
James Smart3621a712009-04-06 18:47:14 -04005964 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005965 * @vport: pointer to a host virtual N_Port data structure.
5966 *
5967 * This routine is used to clean up all the outstanding ELS commands on a
5968 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5969 * routine. After that, it walks the ELS transmit queue to remove all the
5970 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5971 * the IOCBs with a non-NULL completion callback function, the callback
5972 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5973 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5974 * callback function, the IOCB will simply be released. Finally, it walks
5975 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5976 * completion queue IOCB that is associated with the @vport and is not
5977 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5978 * part of the discovery state machine) out to HBA by invoking the
5979 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5980 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5981 * the IOCBs are aborted when this function returns.
5982 **/
dea31012005-04-17 16:05:31 -05005983void
James Smart2e0fef82007-06-17 19:56:36 -05005984lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005985{
James Smart2534ba72007-04-25 09:52:20 -04005986 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005987 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005988 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005989 struct lpfc_iocbq *tmp_iocb, *piocb;
5990 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005991
5992 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005993
James Smart2e0fef82007-06-17 19:56:36 -05005994 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005995 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5996 cmd = &piocb->iocb;
5997
5998 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5999 continue;
6000 }
6001
6002 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04006003 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6004 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6005 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6006 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05006007 continue;
dea31012005-04-17 16:05:31 -05006008
James Smart2e0fef82007-06-17 19:56:36 -05006009 if (piocb->vport != vport)
6010 continue;
6011
James Smart2534ba72007-04-25 09:52:20 -04006012 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04006013 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05006014 }
6015
6016 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05006017 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6018 continue;
6019 }
dea31012005-04-17 16:05:31 -05006020
James Smart2e0fef82007-06-17 19:56:36 -05006021 if (piocb->vport != vport)
6022 continue;
6023
James Smart07951072007-04-25 09:51:38 -04006024 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05006025 }
James Smart2e0fef82007-06-17 19:56:36 -05006026 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04006027
James Smarta257bf92009-04-06 18:48:10 -04006028 /* Cancell all the IOCBs from the completions list */
6029 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6030 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04006031
dea31012005-04-17 16:05:31 -05006032 return;
6033}
6034
James Smarte59058c2008-08-24 21:49:00 -04006035/**
James Smart3621a712009-04-06 18:47:14 -04006036 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04006037 * @phba: pointer to lpfc hba data structure.
6038 *
6039 * This routine is used to clean up all the outstanding ELS commands on a
6040 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6041 * routine. After that, it walks the ELS transmit queue to remove all the
6042 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6043 * the IOCBs with the completion callback function associated, the callback
6044 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6045 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6046 * callback function associated, the IOCB will simply be released. Finally,
6047 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6048 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6049 * management plane IOCBs that are not part of the discovery state machine)
6050 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6051 **/
James Smart549e55c2007-08-02 11:09:51 -04006052void
6053lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6054{
6055 LIST_HEAD(completions);
6056 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6057 struct lpfc_iocbq *tmp_iocb, *piocb;
6058 IOCB_t *cmd = NULL;
6059
6060 lpfc_fabric_abort_hba(phba);
6061 spin_lock_irq(&phba->hbalock);
6062 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6063 cmd = &piocb->iocb;
6064 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6065 continue;
6066 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6067 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6068 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6069 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6070 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6071 continue;
6072 list_move_tail(&piocb->list, &completions);
6073 pring->txq_cnt--;
6074 }
6075 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6076 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6077 continue;
6078 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6079 }
6080 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04006081
6082 /* Cancel all the IOCBs from the completions list */
6083 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6084 IOERR_SLI_ABORTED);
6085
James Smart549e55c2007-08-02 11:09:51 -04006086 return;
6087}
6088
James Smarte59058c2008-08-24 21:49:00 -04006089/**
James Smart3621a712009-04-06 18:47:14 -04006090 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04006091 * @phba: Pointer to hba context object.
6092 * @cmdiocbp: Pointer to command iocb which reported error.
6093 * @rspiocbp: Pointer to response iocb which reported error.
6094 *
6095 * This function sends an event when there is an ELS command
6096 * failure.
6097 **/
6098void
6099lpfc_send_els_failure_event(struct lpfc_hba *phba,
6100 struct lpfc_iocbq *cmdiocbp,
6101 struct lpfc_iocbq *rspiocbp)
6102{
6103 struct lpfc_vport *vport = cmdiocbp->vport;
6104 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6105 struct lpfc_lsrjt_event lsrjt_event;
6106 struct lpfc_fabric_event_header fabric_event;
6107 struct ls_rjt stat;
6108 struct lpfc_nodelist *ndlp;
6109 uint32_t *pcmd;
6110
6111 ndlp = cmdiocbp->context1;
6112 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6113 return;
6114
6115 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6116 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6117 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6118 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6119 sizeof(struct lpfc_name));
6120 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6121 sizeof(struct lpfc_name));
6122 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6123 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006124 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006125 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6126 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6127 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6128 fc_host_post_vendor_event(shost,
6129 fc_get_event_number(),
6130 sizeof(lsrjt_event),
6131 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006132 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006133 return;
6134 }
6135 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6136 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6137 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6138 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6139 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6140 else
6141 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6142 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6143 sizeof(struct lpfc_name));
6144 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6145 sizeof(struct lpfc_name));
6146 fc_host_post_vendor_event(shost,
6147 fc_get_event_number(),
6148 sizeof(fabric_event),
6149 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006150 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006151 return;
6152 }
6153
6154}
6155
6156/**
James Smart3621a712009-04-06 18:47:14 -04006157 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006158 * @vport: Pointer to vport object.
6159 * @ndlp: Pointer FC node object.
6160 * @cmd: ELS command code.
6161 *
6162 * This function posts an event when there is an incoming
6163 * unsolicited ELS command.
6164 **/
6165static void
6166lpfc_send_els_event(struct lpfc_vport *vport,
6167 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006168 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006169{
James Smartddcc50f2008-12-04 22:38:46 -05006170 struct lpfc_els_event_header *els_data = NULL;
6171 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006172 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6173
James Smartddcc50f2008-12-04 22:38:46 -05006174 if (*payload == ELS_CMD_LOGO) {
6175 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6176 if (!logo_data) {
6177 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6178 "0148 Failed to allocate memory "
6179 "for LOGO event\n");
6180 return;
6181 }
6182 els_data = &logo_data->header;
6183 } else {
6184 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6185 GFP_KERNEL);
6186 if (!els_data) {
6187 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6188 "0149 Failed to allocate memory "
6189 "for ELS event\n");
6190 return;
6191 }
6192 }
6193 els_data->event_type = FC_REG_ELS_EVENT;
6194 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006195 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006196 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006197 break;
6198 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006199 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006200 break;
6201 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006202 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6203 break;
6204 case ELS_CMD_LOGO:
6205 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6206 /* Copy the WWPN in the LOGO payload */
6207 memcpy(logo_data->logo_wwpn, &payload[2],
6208 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006209 break;
6210 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006211 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006212 return;
6213 }
James Smartddcc50f2008-12-04 22:38:46 -05006214 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6215 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6216 if (*payload == ELS_CMD_LOGO) {
6217 fc_host_post_vendor_event(shost,
6218 fc_get_event_number(),
6219 sizeof(struct lpfc_logo_event),
6220 (char *)logo_data,
6221 LPFC_NL_VENDOR_ID);
6222 kfree(logo_data);
6223 } else {
6224 fc_host_post_vendor_event(shost,
6225 fc_get_event_number(),
6226 sizeof(struct lpfc_els_event_header),
6227 (char *)els_data,
6228 LPFC_NL_VENDOR_ID);
6229 kfree(els_data);
6230 }
James Smartea2151b2008-09-07 11:52:10 -04006231
6232 return;
6233}
6234
6235
6236/**
James Smart3621a712009-04-06 18:47:14 -04006237 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006238 * @phba: pointer to lpfc hba data structure.
6239 * @pring: pointer to a SLI ring.
6240 * @vport: pointer to a host virtual N_Port data structure.
6241 * @elsiocb: pointer to lpfc els command iocb data structure.
6242 *
6243 * This routine is used for processing the IOCB associated with a unsolicited
6244 * event. It first determines whether there is an existing ndlp that matches
6245 * the DID from the unsolicited IOCB. If not, it will create a new one with
6246 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6247 * IOCB is then used to invoke the proper routine and to set up proper state
6248 * of the discovery state machine.
6249 **/
James Smarted957682007-06-17 19:56:37 -05006250static void
6251lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006252 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006253{
James Smart87af33f2007-10-27 13:37:43 -04006254 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006255 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006256 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006257 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05006258 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006259 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006260
James Smarte47c9092008-02-08 18:49:26 -05006261 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006262 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006263
dea31012005-04-17 16:05:31 -05006264 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006265 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6266 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006267 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006268 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006269
James Smart858c9f62007-06-17 19:56:39 -05006270 did = icmd->un.rcvels.remoteID;
6271 if (icmd->ulpStatus) {
6272 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6273 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6274 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006275 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006276 }
dea31012005-04-17 16:05:31 -05006277
6278 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006279 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006280 goto dropit;
dea31012005-04-17 16:05:31 -05006281
James Smartc8685952009-11-18 15:39:16 -05006282 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006283 if (vport->load_flag & FC_UNLOADING)
6284 goto dropit;
6285
James Smart92494142011-02-16 12:39:44 -05006286 /* If NPort discovery is delayed drop incoming ELS */
6287 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6288 (cmd != ELS_CMD_PLOGI))
6289 goto dropit;
6290
James Smart2e0fef82007-06-17 19:56:36 -05006291 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006292 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006293 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006294 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006295 if (!ndlp)
dea31012005-04-17 16:05:31 -05006296 goto dropit;
dea31012005-04-17 16:05:31 -05006297
James Smart2e0fef82007-06-17 19:56:36 -05006298 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006299 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006300 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006301 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006302 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006303 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6304 ndlp = lpfc_enable_node(vport, ndlp,
6305 NLP_STE_UNUSED_NODE);
6306 if (!ndlp)
6307 goto dropit;
6308 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6309 newnode = 1;
6310 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6311 ndlp->nlp_type |= NLP_FABRIC;
6312 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6313 /* This is similar to the new node path */
6314 ndlp = lpfc_nlp_get(ndlp);
6315 if (!ndlp)
6316 goto dropit;
6317 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6318 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006319 }
dea31012005-04-17 16:05:31 -05006320
6321 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006322
James Smart329f9bc2007-04-25 09:53:01 -04006323 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006324 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006325
6326 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6327 cmd &= ELS_CMD_MASK;
6328 }
6329 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006330 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6331 "0112 ELS command x%x received from NPORT x%x "
6332 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006333 switch (cmd) {
6334 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006335 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6336 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6337 did, vport->port_state, ndlp->nlp_flag);
6338
dea31012005-04-17 16:05:31 -05006339 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006340 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6341
James Smartddcc50f2008-12-04 22:38:46 -05006342 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05006343
6344 /* If Nport discovery is delayed, reject PLOGIs */
6345 if (vport->fc_flag & FC_DISC_DELAYED) {
6346 rjt_err = LSRJT_UNABLE_TPC;
6347 break;
6348 }
James Smart858c9f62007-06-17 19:56:39 -05006349 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006350 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6351 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6352 rjt_err = LSRJT_UNABLE_TPC;
6353 break;
6354 }
6355 /* We get here, and drop thru, if we are PT2PT with
6356 * another NPort and the other side has initiated
6357 * the PLOGI before responding to our FLOGI.
6358 */
dea31012005-04-17 16:05:31 -05006359 }
James Smart87af33f2007-10-27 13:37:43 -04006360
6361 shost = lpfc_shost_from_vport(vport);
6362 spin_lock_irq(shost->host_lock);
6363 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6364 spin_unlock_irq(shost->host_lock);
6365
James Smart2e0fef82007-06-17 19:56:36 -05006366 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6367 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006368
dea31012005-04-17 16:05:31 -05006369 break;
6370 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006371 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6372 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6373 did, vport->port_state, ndlp->nlp_flag);
6374
dea31012005-04-17 16:05:31 -05006375 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006376 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006377 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006378 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006379 break;
6380 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006381 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6382 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6383 did, vport->port_state, ndlp->nlp_flag);
6384
dea31012005-04-17 16:05:31 -05006385 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006386 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006387 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006388 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006389 break;
6390 }
James Smart2e0fef82007-06-17 19:56:36 -05006391 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006392 break;
6393 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006394 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6395 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6396 did, vport->port_state, ndlp->nlp_flag);
6397
dea31012005-04-17 16:05:31 -05006398 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006399 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006400 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006401 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006402 break;
6403 }
James Smart2e0fef82007-06-17 19:56:36 -05006404 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006405 break;
6406 case ELS_CMD_RSCN:
6407 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006408 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006409 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006410 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006411 break;
6412 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006413 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6414 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6415 did, vport->port_state, ndlp->nlp_flag);
6416
James Smartddcc50f2008-12-04 22:38:46 -05006417 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006418 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006419 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006420 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006421 break;
6422 }
James Smart2e0fef82007-06-17 19:56:36 -05006423 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6424 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006425 break;
6426 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006427 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6428 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6429 did, vport->port_state, ndlp->nlp_flag);
6430
dea31012005-04-17 16:05:31 -05006431 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006432 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006433 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006434 break;
6435 }
James Smart2e0fef82007-06-17 19:56:36 -05006436 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6437 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006438 break;
6439 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006440 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6441 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6442 did, vport->port_state, ndlp->nlp_flag);
6443
dea31012005-04-17 16:05:31 -05006444 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006445 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006446 break;
6447 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006448 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6449 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6450 did, vport->port_state, ndlp->nlp_flag);
6451
dea31012005-04-17 16:05:31 -05006452 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006453 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006454 break;
6455 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006456 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6457 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6458 did, vport->port_state, ndlp->nlp_flag);
6459
dea31012005-04-17 16:05:31 -05006460 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006461 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006462 break;
dea31012005-04-17 16:05:31 -05006463 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006464 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6465 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6466 did, vport->port_state, ndlp->nlp_flag);
6467
dea31012005-04-17 16:05:31 -05006468 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006469 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006470 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006471 break;
6472 }
James Smart2e0fef82007-06-17 19:56:36 -05006473 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006474 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006475 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006476 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6477 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6478 did, vport->port_state, ndlp->nlp_flag);
6479
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006480 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006481 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006482 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006483 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006484 break;
James Smart12265f62010-10-22 11:05:53 -04006485 case ELS_CMD_RLS:
6486 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6487 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6488 did, vport->port_state, ndlp->nlp_flag);
6489
6490 phba->fc_stat.elsRcvRLS++;
6491 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6492 if (newnode)
6493 lpfc_nlp_put(ndlp);
6494 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006495 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006496 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6497 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6498 did, vport->port_state, ndlp->nlp_flag);
6499
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006500 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006501 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006502 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006503 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006504 break;
6505 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006506 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6507 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6508 did, vport->port_state, ndlp->nlp_flag);
6509
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006510 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006511 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006512 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006513 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006514 break;
dea31012005-04-17 16:05:31 -05006515 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006516 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6517 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6518 did, vport->port_state, ndlp->nlp_flag);
6519
dea31012005-04-17 16:05:31 -05006520 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006521 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006522 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006523 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006524 break;
James Smart12265f62010-10-22 11:05:53 -04006525 case ELS_CMD_RTV:
6526 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6527 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6528 did, vport->port_state, ndlp->nlp_flag);
6529 phba->fc_stat.elsRcvRTV++;
6530 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6531 if (newnode)
6532 lpfc_nlp_put(ndlp);
6533 break;
James Smart5ffc2662009-11-18 15:39:44 -05006534 case ELS_CMD_RRQ:
6535 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6536 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6537 did, vport->port_state, ndlp->nlp_flag);
6538
6539 phba->fc_stat.elsRcvRRQ++;
6540 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6541 if (newnode)
6542 lpfc_nlp_put(ndlp);
6543 break;
James Smart12265f62010-10-22 11:05:53 -04006544 case ELS_CMD_ECHO:
6545 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6546 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6547 did, vport->port_state, ndlp->nlp_flag);
6548
6549 phba->fc_stat.elsRcvECHO++;
6550 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6551 if (newnode)
6552 lpfc_nlp_put(ndlp);
6553 break;
dea31012005-04-17 16:05:31 -05006554 default:
James Smart858c9f62007-06-17 19:56:39 -05006555 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6556 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6557 cmd, did, vport->port_state);
6558
dea31012005-04-17 16:05:31 -05006559 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006560 rjt_err = LSRJT_CMD_UNSUPPORTED;
dea31012005-04-17 16:05:31 -05006561
6562 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006563 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6564 "0115 Unknown ELS command x%x "
6565 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006566 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006567 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006568 break;
6569 }
6570
6571 /* check if need to LS_RJT received ELS cmd */
6572 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006573 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006574 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006575 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006576 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6577 NULL);
dea31012005-04-17 16:05:31 -05006578 }
6579
James Smartd7c255b2008-08-24 21:50:00 -04006580 lpfc_nlp_put(elsiocb->context1);
6581 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006582 return;
6583
6584dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006585 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006586 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6587 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006588 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006589 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006590 phba->fc_stat.elsRcvDrop++;
6591}
6592
James Smarte59058c2008-08-24 21:49:00 -04006593/**
James Smart3621a712009-04-06 18:47:14 -04006594 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04006595 * @phba: pointer to lpfc hba data structure.
6596 * @vpi: host virtual N_Port identifier.
6597 *
6598 * This routine finds a vport on a HBA (referred by @phba) through a
6599 * @vpi. The function walks the HBA's vport list and returns the address
6600 * of the vport with the matching @vpi.
6601 *
6602 * Return code
6603 * NULL - No vport with the matching @vpi found
6604 * Otherwise - Address to the vport with the matching @vpi.
6605 **/
James Smart6669f9b2009-10-02 15:16:45 -04006606struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05006607lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6608{
6609 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04006610 unsigned long flags;
James Smart6d368e52011-05-24 11:44:12 -04006611 int i;
6612
6613 /* The physical ports are always vpi 0 - translate is unnecessary. */
6614 if (vpi > 0) {
6615 /*
6616 * Translate the physical vpi to the logical vpi. The
6617 * vport stores the logical vpi.
6618 */
6619 for (i = 0; i < phba->max_vpi; i++) {
6620 if (vpi == phba->vpi_ids[i])
6621 break;
6622 }
6623
6624 if (i >= phba->max_vpi) {
6625 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
6626 "2936 Could not find Vport mapped "
6627 "to vpi %d\n", vpi);
6628 return NULL;
6629 }
6630 }
James Smart92d7f7b2007-06-17 19:56:38 -05006631
James Smart549e55c2007-08-02 11:09:51 -04006632 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006633 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04006634 if (vport->vpi == vpi) {
6635 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006636 return vport;
James Smart549e55c2007-08-02 11:09:51 -04006637 }
James Smart92d7f7b2007-06-17 19:56:38 -05006638 }
James Smart549e55c2007-08-02 11:09:51 -04006639 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006640 return NULL;
6641}
James Smarted957682007-06-17 19:56:37 -05006642
James Smarte59058c2008-08-24 21:49:00 -04006643/**
James Smart3621a712009-04-06 18:47:14 -04006644 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006645 * @phba: pointer to lpfc hba data structure.
6646 * @pring: pointer to a SLI ring.
6647 * @elsiocb: pointer to lpfc els iocb data structure.
6648 *
6649 * This routine is used to process an unsolicited event received from a SLI
6650 * (Service Level Interface) ring. The actual processing of the data buffer
6651 * associated with the unsolicited event is done by invoking the routine
6652 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6653 * SLI ring on which the unsolicited event was received.
6654 **/
James Smarted957682007-06-17 19:56:37 -05006655void
6656lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6657 struct lpfc_iocbq *elsiocb)
6658{
6659 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006660 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006661 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006662 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6663 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006664
James Smartd7c255b2008-08-24 21:50:00 -04006665 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006666 elsiocb->context2 = NULL;
6667 elsiocb->context3 = NULL;
6668
6669 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6670 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6671 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6672 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006673 phba->fc_stat.NoRcvBuf++;
6674 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006675 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006676 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006677 return;
6678 }
6679
James Smart92d7f7b2007-06-17 19:56:38 -05006680 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6681 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6682 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6683 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6684 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006685 else
6686 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04006687 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05006688 }
James Smart6d368e52011-05-24 11:44:12 -04006689
James Smart7f5f3d02008-02-08 18:50:14 -05006690 /* If there are no BDEs associated
6691 * with this IOCB, there is nothing to do.
6692 */
James Smarted957682007-06-17 19:56:37 -05006693 if (icmd->ulpBdeCount == 0)
6694 return;
6695
James Smart7f5f3d02008-02-08 18:50:14 -05006696 /* type of ELS cmd is first 32bit word
6697 * in packet
6698 */
James Smarted957682007-06-17 19:56:37 -05006699 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006700 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006701 } else {
6702 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6703 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006704 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6705 paddr);
James Smarted957682007-06-17 19:56:37 -05006706 }
6707
James Smart92d7f7b2007-06-17 19:56:38 -05006708 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6709 /*
6710 * The different unsolicited event handlers would tell us
6711 * if they are done with "mp" by setting context2 to NULL.
6712 */
dea31012005-04-17 16:05:31 -05006713 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006714 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6715 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006716 }
James Smarted957682007-06-17 19:56:37 -05006717
6718 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006719 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006720 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006721 elsiocb->context2 = bdeBuf2;
6722 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006723 /* free mp if we are done with it */
6724 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006725 lpfc_in_buf_free(phba, elsiocb->context2);
6726 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006727 }
dea31012005-04-17 16:05:31 -05006728 }
dea31012005-04-17 16:05:31 -05006729}
James Smart92d7f7b2007-06-17 19:56:38 -05006730
James Smarte59058c2008-08-24 21:49:00 -04006731/**
James Smart3621a712009-04-06 18:47:14 -04006732 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006733 * @phba: pointer to lpfc hba data structure.
6734 * @vport: pointer to a virtual N_Port data structure.
6735 *
6736 * This routine issues a Port Login (PLOGI) to the Name Server with
6737 * State Change Request (SCR) for a @vport. This routine will create an
6738 * ndlp for the Name Server associated to the @vport if such node does
6739 * not already exist. The PLOGI to Name Server is issued by invoking the
6740 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6741 * (FDMI) is configured to the @vport, a FDMI node will be created and
6742 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6743 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006744void
6745lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6746{
6747 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05006748 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6749
6750 /*
6751 * If lpfc_delay_discovery parameter is set and the clean address
6752 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6753 * discovery.
6754 */
6755 spin_lock_irq(shost->host_lock);
6756 if (vport->fc_flag & FC_DISC_DELAYED) {
6757 spin_unlock_irq(shost->host_lock);
6758 mod_timer(&vport->delayed_disc_tmo,
6759 jiffies + HZ * phba->fc_ratov);
6760 return;
6761 }
6762 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006763
6764 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6765 if (!ndlp) {
6766 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6767 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006768 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05006769 lpfc_disc_start(vport);
6770 return;
6771 }
6772 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006773 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6774 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006775 return;
6776 }
6777 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006778 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6779 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6780 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006781 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05006782 lpfc_disc_start(vport);
6783 return;
6784 }
6785 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6786 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6787 "0348 NameServer login: node freed\n");
6788 return;
6789 }
James Smart92d7f7b2007-06-17 19:56:38 -05006790 }
James Smart58da1ff2008-04-07 10:15:56 -04006791 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006792
6793 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6794
6795 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6796 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006797 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6798 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006799 return;
6800 }
6801
James Smart3de2a652007-08-02 11:09:59 -04006802 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05006803 /* If this is the first time, allocate an ndlp and initialize
6804 * it. Otherwise, make sure the node is enabled and then do the
6805 * login.
6806 */
6807 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
6808 if (!ndlp_fdmi) {
6809 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6810 GFP_KERNEL);
6811 if (ndlp_fdmi) {
6812 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6813 ndlp_fdmi->nlp_type |= NLP_FABRIC;
6814 } else
6815 return;
6816 }
6817 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
6818 ndlp_fdmi = lpfc_enable_node(vport,
6819 ndlp_fdmi,
6820 NLP_STE_NPR_NODE);
6821
James Smart92d7f7b2007-06-17 19:56:38 -05006822 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04006823 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05006824 NLP_STE_PLOGI_ISSUE);
6825 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006826 }
6827 }
James Smart92d7f7b2007-06-17 19:56:38 -05006828}
6829
James Smarte59058c2008-08-24 21:49:00 -04006830/**
James Smart3621a712009-04-06 18:47:14 -04006831 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006832 * @phba: pointer to lpfc hba data structure.
6833 * @pmb: pointer to the driver internal queue element for mailbox command.
6834 *
6835 * This routine is the completion callback function to register new vport
6836 * mailbox command. If the new vport mailbox command completes successfully,
6837 * the fabric registration login shall be performed on physical port (the
6838 * new vport created is actually a physical port, with VPI 0) or the port
6839 * login to Name Server for State Change Request (SCR) will be performed
6840 * on virtual port (real virtual port, with VPI greater than 0).
6841 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006842static void
6843lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6844{
6845 struct lpfc_vport *vport = pmb->vport;
6846 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6847 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006848 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006849 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006850
James Smart09372822008-01-11 01:52:54 -05006851 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006852 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006853 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006854
6855 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006856 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006857 "0915 Register VPI failed : Status: x%x"
6858 " upd bit: x%x \n", mb->mbxStatus,
6859 mb->un.varRegVpi.upd);
6860 if (phba->sli_rev == LPFC_SLI_REV4 &&
6861 mb->un.varRegVpi.upd)
6862 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006863
6864 switch (mb->mbxStatus) {
6865 case 0x11: /* unsupported feature */
6866 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006867 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006868 /* giving up on vport registration */
6869 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6870 spin_lock_irq(shost->host_lock);
6871 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6872 spin_unlock_irq(shost->host_lock);
6873 lpfc_can_disctmo(vport);
6874 break;
James Smart695a8142010-01-26 23:08:03 -05006875 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6876 case 0x20:
6877 spin_lock_irq(shost->host_lock);
6878 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6879 spin_unlock_irq(shost->host_lock);
6880 lpfc_init_vpi(phba, pmb, vport->vpi);
6881 pmb->vport = vport;
6882 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6883 rc = lpfc_sli_issue_mbox(phba, pmb,
6884 MBX_NOWAIT);
6885 if (rc == MBX_NOT_FINISHED) {
6886 lpfc_printf_vlog(vport,
6887 KERN_ERR, LOG_MBOX,
6888 "2732 Failed to issue INIT_VPI"
6889 " mailbox command\n");
6890 } else {
6891 lpfc_nlp_put(ndlp);
6892 return;
6893 }
6894
James Smart92d7f7b2007-06-17 19:56:38 -05006895 default:
6896 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04006897 if (phba->sli_rev == LPFC_SLI_REV4)
6898 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006899 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006900 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006901 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006902 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006903 if (vport->port_type == LPFC_PHYSICAL_PORT
6904 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05006905 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05006906 else
6907 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006908 break;
6909 }
James Smart92d7f7b2007-06-17 19:56:38 -05006910 } else {
James Smart695a8142010-01-26 23:08:03 -05006911 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006912 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006913 spin_unlock_irq(shost->host_lock);
6914 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006915 if (phba->sli_rev < LPFC_SLI_REV4)
6916 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006917 else {
James Smartfc2b9892010-02-26 14:15:29 -05006918 /*
6919 * If the physical port is instantiated using
6920 * FDISC, do not start vport discovery.
6921 */
6922 if (vport->port_state != LPFC_FDISC)
6923 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006924 lpfc_do_scr_ns_plogi(phba, vport);
6925 }
6926 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006927 lpfc_do_scr_ns_plogi(phba, vport);
6928 }
James Smart38b92ef2010-08-04 16:11:39 -04006929mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05006930 /* Now, we decrement the ndlp reference count held for this
6931 * callback function
6932 */
6933 lpfc_nlp_put(ndlp);
6934
James Smart92d7f7b2007-06-17 19:56:38 -05006935 mempool_free(pmb, phba->mbox_mem_pool);
6936 return;
6937}
6938
James Smarte59058c2008-08-24 21:49:00 -04006939/**
James Smart3621a712009-04-06 18:47:14 -04006940 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006941 * @phba: pointer to lpfc hba data structure.
6942 * @vport: pointer to a host virtual N_Port data structure.
6943 * @ndlp: pointer to a node-list data structure.
6944 *
6945 * This routine registers the @vport as a new virtual port with a HBA.
6946 * It is done through a registering vpi mailbox command.
6947 **/
James Smart695a8142010-01-26 23:08:03 -05006948void
James Smart92d7f7b2007-06-17 19:56:38 -05006949lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6950 struct lpfc_nodelist *ndlp)
6951{
James Smart09372822008-01-11 01:52:54 -05006952 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006953 LPFC_MBOXQ_t *mbox;
6954
6955 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6956 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006957 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006958 mbox->vport = vport;
6959 mbox->context2 = lpfc_nlp_get(ndlp);
6960 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006961 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006962 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006963 /* mailbox command not success, decrement ndlp
6964 * reference count for this command
6965 */
6966 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006967 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006968
James Smarte8b62012007-08-02 11:10:09 -04006969 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6970 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006971 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006972 }
6973 } else {
James Smarte8b62012007-08-02 11:10:09 -04006974 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6975 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006976 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006977 }
James Smartfa4066b2008-01-11 01:53:27 -05006978 return;
6979
6980mbox_err_exit:
6981 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6982 spin_lock_irq(shost->host_lock);
6983 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6984 spin_unlock_irq(shost->host_lock);
6985 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006986}
6987
James Smarte59058c2008-08-24 21:49:00 -04006988/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006989 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006990 * @phba: pointer to lpfc hba data structure.
6991 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006992 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006993 **/
6994void
James Smart0c9ab6f2010-02-26 14:15:57 -05006995lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006996{
6997 struct lpfc_vport **vports;
6998 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006999 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05007000 int i;
James Smart695a8142010-01-26 23:08:03 -05007001
7002 /* Treat this failure as linkdown for all vports */
7003 link_state = phba->link_state;
7004 lpfc_linkdown(phba);
7005 phba->link_state = link_state;
7006
7007 vports = lpfc_create_vport_work_array(phba);
7008
7009 if (vports) {
7010 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
7011 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
7012 if (ndlp)
7013 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
7014 lpfc_els_flush_cmd(vports[i]);
7015 }
7016 lpfc_destroy_vport_work_array(phba, vports);
7017 }
James Smart0c9ab6f2010-02-26 14:15:57 -05007018}
7019
7020/**
7021 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7022 * @phba: pointer to lpfc hba data structure.
7023 *
7024 * This routine abort all pending discovery commands and
7025 * start a timer to retry FLOGI for the physical port
7026 * discovery.
7027 **/
7028void
7029lpfc_retry_pport_discovery(struct lpfc_hba *phba)
7030{
7031 struct lpfc_nodelist *ndlp;
7032 struct Scsi_Host *shost;
7033
7034 /* Cancel the all vports retry delay retry timers */
7035 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05007036
7037 /* If fabric require FLOGI, then re-instantiate physical login */
7038 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
7039 if (!ndlp)
7040 return;
7041
James Smart695a8142010-01-26 23:08:03 -05007042 shost = lpfc_shost_from_vport(phba->pport);
7043 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
7044 spin_lock_irq(shost->host_lock);
7045 ndlp->nlp_flag |= NLP_DELAY_TMO;
7046 spin_unlock_irq(shost->host_lock);
7047 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7048 phba->pport->port_state = LPFC_FLOGI;
7049 return;
7050}
7051
7052/**
7053 * lpfc_fabric_login_reqd - Check if FLOGI required.
7054 * @phba: pointer to lpfc hba data structure.
7055 * @cmdiocb: pointer to FDISC command iocb.
7056 * @rspiocb: pointer to FDISC response iocb.
7057 *
7058 * This routine checks if a FLOGI is reguired for FDISC
7059 * to succeed.
7060 **/
7061static int
7062lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7063 struct lpfc_iocbq *cmdiocb,
7064 struct lpfc_iocbq *rspiocb)
7065{
7066
7067 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7068 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7069 return 0;
7070 else
7071 return 1;
7072}
7073
7074/**
James Smart3621a712009-04-06 18:47:14 -04007075 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007076 * @phba: pointer to lpfc hba data structure.
7077 * @cmdiocb: pointer to lpfc command iocb data structure.
7078 * @rspiocb: pointer to lpfc response iocb data structure.
7079 *
7080 * This routine is the completion callback function to a Fabric Discover
7081 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7082 * single threaded, each FDISC completion callback function will reset
7083 * the discovery timer for all vports such that the timers will not get
7084 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7085 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7086 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7087 * assigned to the vport has been changed with the completion of the FDISC
7088 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7089 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7090 * routine is invoked to register new vport with the HBA. Otherwise, the
7091 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7092 * Server for State Change Request (SCR).
7093 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007094static void
7095lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7096 struct lpfc_iocbq *rspiocb)
7097{
7098 struct lpfc_vport *vport = cmdiocb->vport;
7099 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7100 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7101 struct lpfc_nodelist *np;
7102 struct lpfc_nodelist *next_np;
7103 IOCB_t *irsp = &rspiocb->iocb;
7104 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05007105 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7106 struct serv_parm *sp;
7107 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05007108
James Smarte8b62012007-08-02 11:10:09 -04007109 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7110 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7111 irsp->ulpStatus, irsp->un.ulpWord[4],
7112 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05007113 /* Since all FDISCs are being single threaded, we
7114 * must reset the discovery timer for ALL vports
7115 * waiting to send FDISC when one completes.
7116 */
7117 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7118 lpfc_set_disctmo(piocb->vport);
7119 }
7120
James Smart858c9f62007-06-17 19:56:39 -05007121 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7122 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7123 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7124
James Smart92d7f7b2007-06-17 19:56:38 -05007125 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05007126
7127 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7128 lpfc_retry_pport_discovery(phba);
7129 goto out;
7130 }
7131
James Smart92d7f7b2007-06-17 19:56:38 -05007132 /* Check for retry */
7133 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7134 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007135 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04007136 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04007137 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04007138 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04007139 goto fdisc_failed;
7140 }
James Smartd7c255b2008-08-24 21:50:00 -04007141 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05007142 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04007143 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04007144 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05007145 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04007146 vport->fc_flag |= FC_PUBLIC_LOOP;
7147 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007148
James Smartd7c255b2008-08-24 21:50:00 -04007149 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7150 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05007151 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7152 sp = prsp->virt + sizeof(uint32_t);
7153 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7154 memcpy(&vport->fabric_portname, &sp->portName,
7155 sizeof(struct lpfc_name));
7156 memcpy(&vport->fabric_nodename, &sp->nodeName,
7157 sizeof(struct lpfc_name));
7158 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04007159 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7160 /* If our NportID changed, we need to ensure all
7161 * remaining NPORTs get unreg_login'ed so we can
7162 * issue unreg_vpi.
7163 */
7164 list_for_each_entry_safe(np, next_np,
7165 &vport->fc_nodes, nlp_listp) {
7166 if (!NLP_CHK_NODE_ACT(ndlp) ||
7167 (np->nlp_state != NLP_STE_NPR_NODE) ||
7168 !(np->nlp_flag & NLP_NPR_ADISC))
7169 continue;
James Smart09372822008-01-11 01:52:54 -05007170 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007171 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007172 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007173 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007174 }
James Smart78730cf2010-04-06 15:06:30 -04007175 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007176
7177 if (phba->sli_rev == LPFC_SLI_REV4)
7178 lpfc_sli4_unreg_all_rpis(vport);
7179
James Smartd7c255b2008-08-24 21:50:00 -04007180 lpfc_mbx_unreg_vpi(vport);
7181 spin_lock_irq(shost->host_lock);
7182 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007183 if (phba->sli_rev == LPFC_SLI_REV4)
7184 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007185 else
7186 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007187 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007188 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7189 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7190 /*
7191 * Driver needs to re-reg VPI in order for f/w
7192 * to update the MAC address.
7193 */
7194 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007195 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007196 }
7197
James Smartecfd03c2010-02-12 14:41:27 -05007198 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7199 lpfc_issue_init_vpi(vport);
7200 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007201 lpfc_register_new_vport(phba, vport, ndlp);
7202 else
7203 lpfc_do_scr_ns_plogi(phba, vport);
7204 goto out;
7205fdisc_failed:
7206 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7207 /* Cancel discovery timer */
7208 lpfc_can_disctmo(vport);
7209 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007210out:
7211 lpfc_els_free_iocb(phba, cmdiocb);
7212}
7213
James Smarte59058c2008-08-24 21:49:00 -04007214/**
James Smart3621a712009-04-06 18:47:14 -04007215 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007216 * @vport: pointer to a virtual N_Port data structure.
7217 * @ndlp: pointer to a node-list data structure.
7218 * @retry: number of retries to the command IOCB.
7219 *
7220 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7221 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7222 * routine to issue the IOCB, which makes sure only one outstanding fabric
7223 * IOCB will be sent off HBA at any given time.
7224 *
7225 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7226 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7227 * will be stored into the context1 field of the IOCB for the completion
7228 * callback function to the FDISC ELS command.
7229 *
7230 * Return code
7231 * 0 - Successfully issued fdisc iocb command
7232 * 1 - Failed to issue fdisc iocb command
7233 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007234static int
James Smart92d7f7b2007-06-17 19:56:38 -05007235lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7236 uint8_t retry)
7237{
7238 struct lpfc_hba *phba = vport->phba;
7239 IOCB_t *icmd;
7240 struct lpfc_iocbq *elsiocb;
7241 struct serv_parm *sp;
7242 uint8_t *pcmd;
7243 uint16_t cmdsize;
7244 int did = ndlp->nlp_DID;
7245 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007246
James Smart5ffc2662009-11-18 15:39:44 -05007247 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05007248 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7249 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7250 ELS_CMD_FDISC);
7251 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007252 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007253 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7254 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007255 return 1;
7256 }
7257
7258 icmd = &elsiocb->iocb;
7259 icmd->un.elsreq64.myID = 0;
7260 icmd->un.elsreq64.fl = 1;
7261
James Smart40426292010-12-15 17:58:10 -05007262 if ((phba->sli_rev == LPFC_SLI_REV4) &&
7263 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
7264 LPFC_SLI_INTF_IF_TYPE_0)) {
James Smartf1126682009-06-10 17:22:44 -04007265 /* FDISC needs to be 1 for WQE VPI */
7266 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
7267 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
7268 /* Set the ulpContext to the vpi */
James Smart6d368e52011-05-24 11:44:12 -04007269 elsiocb->iocb.ulpContext = phba->vpi_ids[vport->vpi];
James Smartf1126682009-06-10 17:22:44 -04007270 } else {
7271 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
7272 icmd->ulpCt_h = 1;
7273 icmd->ulpCt_l = 0;
7274 }
James Smart92d7f7b2007-06-17 19:56:38 -05007275
7276 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7277 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7278 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7279 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7280 sp = (struct serv_parm *) pcmd;
7281 /* Setup CSPs accordingly for Fabric */
7282 sp->cmn.e_d_tov = 0;
7283 sp->cmn.w2.r_a_tov = 0;
7284 sp->cls1.classValid = 0;
7285 sp->cls2.seqDelivery = 1;
7286 sp->cls3.seqDelivery = 1;
7287
7288 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7289 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7290 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7291 pcmd += sizeof(uint32_t); /* Port Name */
7292 memcpy(pcmd, &vport->fc_portname, 8);
7293 pcmd += sizeof(uint32_t); /* Node Name */
7294 pcmd += sizeof(uint32_t); /* Node Name */
7295 memcpy(pcmd, &vport->fc_nodename, 8);
7296
7297 lpfc_set_disctmo(vport);
7298
7299 phba->fc_stat.elsXmitFDISC++;
7300 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7301
James Smart858c9f62007-06-17 19:56:39 -05007302 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7303 "Issue FDISC: did:x%x",
7304 did, 0, 0);
7305
James Smart92d7f7b2007-06-17 19:56:38 -05007306 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7307 if (rc == IOCB_ERROR) {
7308 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007309 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007310 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7311 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007312 return 1;
7313 }
7314 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007315 return 0;
7316}
7317
James Smarte59058c2008-08-24 21:49:00 -04007318/**
James Smart3621a712009-04-06 18:47:14 -04007319 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007320 * @phba: pointer to lpfc hba data structure.
7321 * @cmdiocb: pointer to lpfc command iocb data structure.
7322 * @rspiocb: pointer to lpfc response iocb data structure.
7323 *
7324 * This routine is the completion callback function to the issuing of a LOGO
7325 * ELS command off a vport. It frees the command IOCB and then decrement the
7326 * reference count held on ndlp for this completion function, indicating that
7327 * the reference to the ndlp is no long needed. Note that the
7328 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7329 * callback function and an additional explicit ndlp reference decrementation
7330 * will trigger the actual release of the ndlp.
7331 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007332static void
7333lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7334 struct lpfc_iocbq *rspiocb)
7335{
7336 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007337 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007338 struct lpfc_nodelist *ndlp;
James Smart9589b062011-04-16 11:03:17 -04007339 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05007340
James Smart9589b062011-04-16 11:03:17 -04007341 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007342 irsp = &rspiocb->iocb;
7343 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7344 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7345 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007346
7347 lpfc_els_free_iocb(phba, cmdiocb);
7348 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007349
7350 /* Trigger the release of the ndlp after logo */
7351 lpfc_nlp_put(ndlp);
James Smart9589b062011-04-16 11:03:17 -04007352
7353 /* NPIV LOGO completes to NPort <nlp_DID> */
7354 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7355 "2928 NPIV LOGO completes to NPort x%x "
7356 "Data: x%x x%x x%x x%x\n",
7357 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
7358 irsp->ulpTimeout, vport->num_disc_nodes);
7359
7360 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
7361 spin_lock_irq(shost->host_lock);
7362 vport->fc_flag &= ~FC_FABRIC;
7363 spin_unlock_irq(shost->host_lock);
7364 }
James Smart92d7f7b2007-06-17 19:56:38 -05007365}
7366
James Smarte59058c2008-08-24 21:49:00 -04007367/**
James Smart3621a712009-04-06 18:47:14 -04007368 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007369 * @vport: pointer to a virtual N_Port data structure.
7370 * @ndlp: pointer to a node-list data structure.
7371 *
7372 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7373 *
7374 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7375 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7376 * will be stored into the context1 field of the IOCB for the completion
7377 * callback function to the LOGO ELS command.
7378 *
7379 * Return codes
7380 * 0 - Successfully issued logo off the @vport
7381 * 1 - Failed to issue logo off the @vport
7382 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007383int
7384lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7385{
7386 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7387 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007388 IOCB_t *icmd;
7389 struct lpfc_iocbq *elsiocb;
7390 uint8_t *pcmd;
7391 uint16_t cmdsize;
7392
7393 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7394 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7395 ELS_CMD_LOGO);
7396 if (!elsiocb)
7397 return 1;
7398
7399 icmd = &elsiocb->iocb;
7400 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7401 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7402 pcmd += sizeof(uint32_t);
7403
7404 /* Fill in LOGO payload */
7405 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7406 pcmd += sizeof(uint32_t);
7407 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7408
James Smart858c9f62007-06-17 19:56:39 -05007409 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7410 "Issue LOGO npiv did:x%x flg:x%x",
7411 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7412
James Smart92d7f7b2007-06-17 19:56:38 -05007413 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7414 spin_lock_irq(shost->host_lock);
7415 ndlp->nlp_flag |= NLP_LOGO_SND;
7416 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007417 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7418 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007419 spin_lock_irq(shost->host_lock);
7420 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7421 spin_unlock_irq(shost->host_lock);
7422 lpfc_els_free_iocb(phba, elsiocb);
7423 return 1;
7424 }
7425 return 0;
7426}
7427
James Smarte59058c2008-08-24 21:49:00 -04007428/**
James Smart3621a712009-04-06 18:47:14 -04007429 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007430 * @ptr: holder for the timer function associated data.
7431 *
7432 * This routine is invoked by the fabric iocb block timer after
7433 * timeout. It posts the fabric iocb block timeout event by setting the
7434 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7435 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7436 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7437 * posted event WORKER_FABRIC_BLOCK_TMO.
7438 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007439void
7440lpfc_fabric_block_timeout(unsigned long ptr)
7441{
7442 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7443 unsigned long iflags;
7444 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007445
James Smart92d7f7b2007-06-17 19:56:38 -05007446 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7447 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7448 if (!tmo_posted)
7449 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7450 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7451
James Smart5e9d9b82008-06-14 22:52:53 -04007452 if (!tmo_posted)
7453 lpfc_worker_wake_up(phba);
7454 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007455}
7456
James Smarte59058c2008-08-24 21:49:00 -04007457/**
James Smart3621a712009-04-06 18:47:14 -04007458 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007459 * @phba: pointer to lpfc hba data structure.
7460 *
7461 * This routine issues one fabric iocb from the driver internal list to
7462 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7463 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7464 * remove one pending fabric iocb from the driver internal list and invokes
7465 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7466 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007467static void
7468lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7469{
7470 struct lpfc_iocbq *iocb;
7471 unsigned long iflags;
7472 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007473 IOCB_t *cmd;
7474
7475repeat:
7476 iocb = NULL;
7477 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007478 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007479 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7480 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7481 list);
7482 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007483 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007484 atomic_inc(&phba->fabric_iocb_count);
7485 }
7486 spin_unlock_irqrestore(&phba->hbalock, iflags);
7487 if (iocb) {
7488 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7489 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7490 iocb->iocb_flag |= LPFC_IO_FABRIC;
7491
James Smart858c9f62007-06-17 19:56:39 -05007492 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7493 "Fabric sched1: ste:x%x",
7494 iocb->vport->port_state, 0, 0);
7495
James Smart3772a992009-05-22 14:50:54 -04007496 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007497
7498 if (ret == IOCB_ERROR) {
7499 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7500 iocb->fabric_iocb_cmpl = NULL;
7501 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7502 cmd = &iocb->iocb;
7503 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7504 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7505 iocb->iocb_cmpl(phba, iocb, iocb);
7506
7507 atomic_dec(&phba->fabric_iocb_count);
7508 goto repeat;
7509 }
7510 }
7511
7512 return;
7513}
7514
James Smarte59058c2008-08-24 21:49:00 -04007515/**
James Smart3621a712009-04-06 18:47:14 -04007516 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007517 * @phba: pointer to lpfc hba data structure.
7518 *
7519 * This routine unblocks the issuing fabric iocb command. The function
7520 * will clear the fabric iocb block bit and then invoke the routine
7521 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7522 * from the driver internal fabric iocb list.
7523 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007524void
7525lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7526{
7527 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7528
7529 lpfc_resume_fabric_iocbs(phba);
7530 return;
7531}
7532
James Smarte59058c2008-08-24 21:49:00 -04007533/**
James Smart3621a712009-04-06 18:47:14 -04007534 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007535 * @phba: pointer to lpfc hba data structure.
7536 *
7537 * This routine blocks the issuing fabric iocb for a specified amount of
7538 * time (currently 100 ms). This is done by set the fabric iocb block bit
7539 * and set up a timeout timer for 100ms. When the block bit is set, no more
7540 * fabric iocb will be issued out of the HBA.
7541 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007542static void
7543lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7544{
7545 int blocked;
7546
7547 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007548 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007549 if (!blocked)
7550 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7551
7552 return;
7553}
7554
James Smarte59058c2008-08-24 21:49:00 -04007555/**
James Smart3621a712009-04-06 18:47:14 -04007556 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007557 * @phba: pointer to lpfc hba data structure.
7558 * @cmdiocb: pointer to lpfc command iocb data structure.
7559 * @rspiocb: pointer to lpfc response iocb data structure.
7560 *
7561 * This routine is the callback function that is put to the fabric iocb's
7562 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7563 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7564 * function first restores and invokes the original iocb's callback function
7565 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7566 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7567 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007568static void
7569lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7570 struct lpfc_iocbq *rspiocb)
7571{
7572 struct ls_rjt stat;
7573
7574 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7575 BUG();
7576
7577 switch (rspiocb->iocb.ulpStatus) {
7578 case IOSTAT_NPORT_RJT:
7579 case IOSTAT_FABRIC_RJT:
7580 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7581 lpfc_block_fabric_iocbs(phba);
7582 }
7583 break;
7584
7585 case IOSTAT_NPORT_BSY:
7586 case IOSTAT_FABRIC_BSY:
7587 lpfc_block_fabric_iocbs(phba);
7588 break;
7589
7590 case IOSTAT_LS_RJT:
7591 stat.un.lsRjtError =
7592 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7593 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7594 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7595 lpfc_block_fabric_iocbs(phba);
7596 break;
7597 }
7598
7599 if (atomic_read(&phba->fabric_iocb_count) == 0)
7600 BUG();
7601
7602 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7603 cmdiocb->fabric_iocb_cmpl = NULL;
7604 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7605 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7606
7607 atomic_dec(&phba->fabric_iocb_count);
7608 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007609 /* Post any pending iocbs to HBA */
7610 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007611 }
7612}
7613
James Smarte59058c2008-08-24 21:49:00 -04007614/**
James Smart3621a712009-04-06 18:47:14 -04007615 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007616 * @phba: pointer to lpfc hba data structure.
7617 * @iocb: pointer to lpfc command iocb data structure.
7618 *
7619 * This routine is used as the top-level API for issuing a fabric iocb command
7620 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7621 * function makes sure that only one fabric bound iocb will be outstanding at
7622 * any given time. As such, this function will first check to see whether there
7623 * is already an outstanding fabric iocb on the wire. If so, it will put the
7624 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7625 * issued later. Otherwise, it will issue the iocb on the wire and update the
7626 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7627 *
7628 * Note, this implementation has a potential sending out fabric IOCBs out of
7629 * order. The problem is caused by the construction of the "ready" boolen does
7630 * not include the condition that the internal fabric IOCB list is empty. As
7631 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7632 * ahead of the fabric IOCBs in the internal list.
7633 *
7634 * Return code
7635 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7636 * IOCB_ERROR - failed to issue fabric iocb
7637 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007638static int
James Smart92d7f7b2007-06-17 19:56:38 -05007639lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7640{
7641 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007642 int ready;
7643 int ret;
7644
7645 if (atomic_read(&phba->fabric_iocb_count) > 1)
7646 BUG();
7647
7648 spin_lock_irqsave(&phba->hbalock, iflags);
7649 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7650 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7651
James Smart7f5f3d02008-02-08 18:50:14 -05007652 if (ready)
7653 /* Increment fabric iocb count to hold the position */
7654 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007655 spin_unlock_irqrestore(&phba->hbalock, iflags);
7656 if (ready) {
7657 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7658 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7659 iocb->iocb_flag |= LPFC_IO_FABRIC;
7660
James Smart858c9f62007-06-17 19:56:39 -05007661 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7662 "Fabric sched2: ste:x%x",
7663 iocb->vport->port_state, 0, 0);
7664
James Smart3772a992009-05-22 14:50:54 -04007665 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007666
7667 if (ret == IOCB_ERROR) {
7668 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7669 iocb->fabric_iocb_cmpl = NULL;
7670 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7671 atomic_dec(&phba->fabric_iocb_count);
7672 }
7673 } else {
7674 spin_lock_irqsave(&phba->hbalock, iflags);
7675 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7676 spin_unlock_irqrestore(&phba->hbalock, iflags);
7677 ret = IOCB_SUCCESS;
7678 }
7679 return ret;
7680}
7681
James Smarte59058c2008-08-24 21:49:00 -04007682/**
James Smart3621a712009-04-06 18:47:14 -04007683 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007684 * @vport: pointer to a virtual N_Port data structure.
7685 *
7686 * This routine aborts all the IOCBs associated with a @vport from the
7687 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7688 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7689 * list, removes each IOCB associated with the @vport off the list, set the
7690 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7691 * associated with the IOCB.
7692 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007693static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007694{
7695 LIST_HEAD(completions);
7696 struct lpfc_hba *phba = vport->phba;
7697 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007698
7699 spin_lock_irq(&phba->hbalock);
7700 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7701 list) {
7702
7703 if (piocb->vport != vport)
7704 continue;
7705
7706 list_move_tail(&piocb->list, &completions);
7707 }
7708 spin_unlock_irq(&phba->hbalock);
7709
James Smarta257bf92009-04-06 18:48:10 -04007710 /* Cancel all the IOCBs from the completions list */
7711 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7712 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007713}
7714
James Smarte59058c2008-08-24 21:49:00 -04007715/**
James Smart3621a712009-04-06 18:47:14 -04007716 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007717 * @ndlp: pointer to a node-list data structure.
7718 *
7719 * This routine aborts all the IOCBs associated with an @ndlp from the
7720 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7721 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7722 * list, removes each IOCB associated with the @ndlp off the list, set the
7723 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7724 * associated with the IOCB.
7725 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007726void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7727{
7728 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007729 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007730 struct lpfc_iocbq *tmp_iocb, *piocb;
7731 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007732
7733 spin_lock_irq(&phba->hbalock);
7734 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7735 list) {
7736 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7737
7738 list_move_tail(&piocb->list, &completions);
7739 }
7740 }
7741 spin_unlock_irq(&phba->hbalock);
7742
James Smarta257bf92009-04-06 18:48:10 -04007743 /* Cancel all the IOCBs from the completions list */
7744 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7745 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007746}
7747
James Smarte59058c2008-08-24 21:49:00 -04007748/**
James Smart3621a712009-04-06 18:47:14 -04007749 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007750 * @phba: pointer to lpfc hba data structure.
7751 *
7752 * This routine aborts all the IOCBs currently on the driver internal
7753 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7754 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7755 * list, removes IOCBs off the list, set the status feild to
7756 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7757 * the IOCB.
7758 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007759void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7760{
7761 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007762
7763 spin_lock_irq(&phba->hbalock);
7764 list_splice_init(&phba->fabric_iocb_list, &completions);
7765 spin_unlock_irq(&phba->hbalock);
7766
James Smarta257bf92009-04-06 18:48:10 -04007767 /* Cancel all the IOCBs from the completions list */
7768 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7769 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007770}
James Smart6fb120a2009-05-22 14:52:59 -04007771
7772/**
James Smart1151e3e2011-02-16 12:39:35 -05007773 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7774 * @vport: pointer to lpfc vport data structure.
7775 *
7776 * This routine is invoked by the vport cleanup for deletions and the cleanup
7777 * for an ndlp on removal.
7778 **/
7779void
7780lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
7781{
7782 struct lpfc_hba *phba = vport->phba;
7783 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7784 unsigned long iflag = 0;
7785
7786 spin_lock_irqsave(&phba->hbalock, iflag);
7787 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7788 list_for_each_entry_safe(sglq_entry, sglq_next,
7789 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7790 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
7791 sglq_entry->ndlp = NULL;
7792 }
7793 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7794 spin_unlock_irqrestore(&phba->hbalock, iflag);
7795 return;
7796}
7797
7798/**
James Smart6fb120a2009-05-22 14:52:59 -04007799 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7800 * @phba: pointer to lpfc hba data structure.
7801 * @axri: pointer to the els xri abort wcqe structure.
7802 *
7803 * This routine is invoked by the worker thread to process a SLI4 slow-path
7804 * ELS aborted xri.
7805 **/
7806void
7807lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7808 struct sli4_wcqe_xri_aborted *axri)
7809{
7810 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05007811 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04007812 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05007813
James Smart6fb120a2009-05-22 14:52:59 -04007814 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7815 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05007816 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04007817 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007818
James Smart0f65ff62010-02-26 14:14:23 -05007819 spin_lock_irqsave(&phba->hbalock, iflag);
7820 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007821 list_for_each_entry_safe(sglq_entry, sglq_next,
7822 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7823 if (sglq_entry->sli4_xritag == xri) {
7824 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05007825 ndlp = sglq_entry->ndlp;
7826 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04007827 list_add_tail(&sglq_entry->list,
7828 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007829 sglq_entry->state = SGL_FREED;
7830 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007831 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart19ca7602010-11-20 23:11:55 -05007832 lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04007833
7834 /* Check if TXQ queue needs to be serviced */
7835 if (pring->txq_cnt)
7836 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007837 return;
7838 }
7839 }
James Smart0f65ff62010-02-26 14:14:23 -05007840 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04007841 lxri = lpfc_sli4_xri_inrange(phba, xri);
7842 if (lxri == NO_XRI) {
7843 spin_unlock_irqrestore(&phba->hbalock, iflag);
7844 return;
7845 }
7846 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05007847 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7848 spin_unlock_irqrestore(&phba->hbalock, iflag);
7849 return;
7850 }
7851 sglq_entry->state = SGL_XRI_ABORTED;
7852 spin_unlock_irqrestore(&phba->hbalock, iflag);
7853 return;
James Smart6fb120a2009-05-22 14:52:59 -04007854}