blob: 95cff9909eff53fe39d3c0f6fcc35cecf1f84dae [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartd4379ac2012-03-01 22:37:07 -05004 * Copyright (C) 2004-2012 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050021/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_transport_fc.h>
31
James Smartda0436e2009-05-22 14:51:39 -040032#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050033#include "lpfc_hw.h"
34#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040036#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_disc.h"
38#include "lpfc_scsi.h"
39#include "lpfc.h"
40#include "lpfc_logmsg.h"
41#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050042#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050043#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050044
45static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
46 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050047static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
48 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010049static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
50static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
51 struct lpfc_nodelist *ndlp, uint8_t retry);
52static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
53 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050054
dea31012005-04-17 16:05:31 -050055static int lpfc_max_els_tries = 3;
56
James Smarte59058c2008-08-24 21:49:00 -040057/**
James Smart3621a712009-04-06 18:47:14 -040058 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040059 * @vport: pointer to a host virtual N_Port data structure.
60 *
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
68 * had happened.
69 *
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
74 *
75 * Return codes
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
78 **/
James Smart858c9f62007-06-17 19:56:39 -050079int
James Smart2e0fef82007-06-17 19:56:36 -050080lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050081{
James Smart2e0fef82007-06-17 19:56:36 -050082 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
83 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050084 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050085
James Smart2e0fef82007-06-17 19:56:36 -050086 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040087 phba->link_state == LPFC_LINK_DOWN ||
88 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050089 return 0;
90
91 /* Read the HBA Host Attention Register */
James Smart9940b972011-03-11 16:06:12 -050092 if (lpfc_readl(phba->HAregaddr, &ha_copy))
93 return 1;
dea31012005-04-17 16:05:31 -050094
95 if (!(ha_copy & HA_LATT))
96 return 0;
97
98 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040099 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
100 "0237 Pending Link Event during "
101 "Discovery: State x%x\n",
102 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500103
104 /* CLEAR_LA should re-enable link attention events and
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300105 * we should then immediately take a LATT event. The
dea31012005-04-17 16:05:31 -0500106 * LATT processing should call lpfc_linkdown() which
107 * will cleanup any left over in-progress discovery
108 * events.
109 */
James Smart2e0fef82007-06-17 19:56:36 -0500110 spin_lock_irq(shost->host_lock);
111 vport->fc_flag |= FC_ABORT_DISCOVERY;
112 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500113
James Smart92d7f7b2007-06-17 19:56:38 -0500114 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500115 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500116
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500117 return 1;
dea31012005-04-17 16:05:31 -0500118}
119
James Smarte59058c2008-08-24 21:49:00 -0400120/**
James Smart3621a712009-04-06 18:47:14 -0400121 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400122 * @vport: pointer to a host virtual N_Port data structure.
123 * @expectRsp: flag indicating whether response is expected.
124 * @cmdSize: size of the ELS command.
125 * @retry: number of retries to the command IOCB when it fails.
126 * @ndlp: pointer to a node-list data structure.
127 * @did: destination identifier.
128 * @elscmd: the ELS command code.
129 *
130 * This routine is used for allocating a lpfc-IOCB data structure from
131 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
132 * passed into the routine for discovery state machine to issue an Extended
133 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
134 * and preparation routine that is used by all the discovery state machine
135 * routines and the ELS command-specific fields will be later set up by
136 * the individual discovery machine routines after calling this routine
137 * allocating and preparing a generic IOCB data structure. It fills in the
138 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
139 * payload and response payload (if expected). The reference count on the
140 * ndlp is incremented by 1 and the reference to the ndlp is put into
141 * context1 of the IOCB data structure for this IOCB to hold the ndlp
142 * reference for the command's callback function to access later.
143 *
144 * Return code
145 * Pointer to the newly allocated/prepared els iocb data structure
146 * NULL - when els iocb data structure allocation/preparation failed
147 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400148struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500149lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
150 uint16_t cmdSize, uint8_t retry,
151 struct lpfc_nodelist *ndlp, uint32_t did,
152 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500153{
James Smart2e0fef82007-06-17 19:56:36 -0500154 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400155 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500156 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
157 struct ulp_bde64 *bpl;
158 IOCB_t *icmd;
159
dea31012005-04-17 16:05:31 -0500160
James Smart2e0fef82007-06-17 19:56:36 -0500161 if (!lpfc_is_link_up(phba))
162 return NULL;
dea31012005-04-17 16:05:31 -0500163
dea31012005-04-17 16:05:31 -0500164 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400165 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500166
167 if (elsiocb == NULL)
168 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500169
James Smart0c287582009-06-10 17:22:56 -0400170 /*
171 * If this command is for fabric controller and HBA running
172 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
173 */
174 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400175 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400176 ((elscmd == ELS_CMD_FLOGI) ||
177 (elscmd == ELS_CMD_FDISC) ||
178 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500179 switch (elscmd) {
180 case ELS_CMD_FLOGI:
James Smartf0d9bcc2010-10-22 11:07:09 -0400181 elsiocb->iocb_flag |=
182 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500183 & LPFC_FIP_ELS_ID_MASK);
184 break;
185 case ELS_CMD_FDISC:
James Smartf0d9bcc2010-10-22 11:07:09 -0400186 elsiocb->iocb_flag |=
187 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500188 & LPFC_FIP_ELS_ID_MASK);
189 break;
190 case ELS_CMD_LOGO:
James Smartf0d9bcc2010-10-22 11:07:09 -0400191 elsiocb->iocb_flag |=
192 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500193 & LPFC_FIP_ELS_ID_MASK);
194 break;
195 }
James Smart0c287582009-06-10 17:22:56 -0400196 else
James Smartc8685952009-11-18 15:39:16 -0500197 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400198
dea31012005-04-17 16:05:31 -0500199 icmd = &elsiocb->iocb;
200
201 /* fill in BDEs for command */
202 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400203 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
204 if (pcmd)
205 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500206 if (!pcmd || !pcmd->virt)
207 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500208
209 INIT_LIST_HEAD(&pcmd->list);
210
211 /* Allocate buffer for response payload */
212 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500213 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500214 if (prsp)
215 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
216 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500217 if (!prsp || !prsp->virt)
218 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500219 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500220 } else
dea31012005-04-17 16:05:31 -0500221 prsp = NULL;
dea31012005-04-17 16:05:31 -0500222
223 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500224 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500225 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500226 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
227 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500228 if (!pbuflist || !pbuflist->virt)
229 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500230
231 INIT_LIST_HEAD(&pbuflist->list);
232
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
James Smart1b511972011-12-13 13:23:09 -0500424 * the @vport. This mailbox command is necessary for SLI4 port only.
James Smart6fb120a2009-05-22 14:52:59 -0400425 *
426 * Return code
427 * 0 - successfully issued REG_VFI for @vport
428 * A failure code otherwise.
429 **/
James Smart1b511972011-12-13 13:23:09 -0500430int
James Smart6fb120a2009-05-22 14:52:59 -0400431lpfc_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;
James Smart1b511972011-12-13 13:23:09 -0500441 /* move forward in case of SLI4 FC port loopback test */
442 if ((phba->sli_rev == LPFC_SLI_REV4) &&
443 !(phba->link_flag & LS_LOOPBACK_MODE)) {
444 ndlp = lpfc_findnode_did(vport, Fabric_DID);
445 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
446 rc = -ENODEV;
447 goto fail;
448 }
James Smart6fb120a2009-05-22 14:52:59 -0400449 }
450
451 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
452 if (!dmabuf) {
453 rc = -ENOMEM;
454 goto fail;
455 }
456 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
457 if (!dmabuf->virt) {
458 rc = -ENOMEM;
459 goto fail_free_dmabuf;
460 }
James Smart6d368e52011-05-24 11:44:12 -0400461
James Smart6fb120a2009-05-22 14:52:59 -0400462 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
463 if (!mboxq) {
464 rc = -ENOMEM;
465 goto fail_free_coherent;
466 }
467 vport->port_state = LPFC_FABRIC_CFG_LINK;
468 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
469 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
470 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
471 mboxq->vport = vport;
472 mboxq->context1 = dmabuf;
473 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
474 if (rc == MBX_NOT_FINISHED) {
475 rc = -ENXIO;
476 goto fail_free_mbox;
477 }
478 return 0;
479
480fail_free_mbox:
481 mempool_free(mboxq, phba->mbox_mem_pool);
482fail_free_coherent:
483 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
484fail_free_dmabuf:
485 kfree(dmabuf);
486fail:
487 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
488 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
489 "0289 Issue Register VFI failed: Err %d\n", rc);
490 return rc;
491}
492
493/**
James Smart1b511972011-12-13 13:23:09 -0500494 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
495 * @vport: pointer to a host virtual N_Port data structure.
496 *
497 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
498 * the @vport. This mailbox command is necessary for SLI4 port only.
499 *
500 * Return code
501 * 0 - successfully issued REG_VFI for @vport
502 * A failure code otherwise.
503 **/
504int
505lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
506{
507 struct lpfc_hba *phba = vport->phba;
508 struct Scsi_Host *shost;
509 LPFC_MBOXQ_t *mboxq;
510 int rc;
511
512 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
513 if (!mboxq) {
514 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
515 "2556 UNREG_VFI mbox allocation failed"
516 "HBA state x%x\n", phba->pport->port_state);
517 return -ENOMEM;
518 }
519
520 lpfc_unreg_vfi(mboxq, vport);
521 mboxq->vport = vport;
522 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
523
524 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
525 if (rc == MBX_NOT_FINISHED) {
526 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
527 "2557 UNREG_VFI issue mbox failed rc x%x "
528 "HBA state x%x\n",
529 rc, phba->pport->port_state);
530 mempool_free(mboxq, phba->mbox_mem_pool);
531 return -EIO;
532 }
533
534 shost = lpfc_shost_from_vport(vport);
535 spin_lock_irq(shost->host_lock);
536 vport->fc_flag &= ~FC_VFI_REGISTERED;
537 spin_unlock_irq(shost->host_lock);
538 return 0;
539}
540
541/**
James Smart92494142011-02-16 12:39:44 -0500542 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
543 * @vport: pointer to a host virtual N_Port data structure.
544 * @sp: pointer to service parameter data structure.
545 *
546 * This routine is called from FLOGI/FDISC completion handler functions.
547 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
548 * node nodename is changed in the completion service parameter else return
549 * 0. This function also set flag in the vport data structure to delay
550 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
551 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
552 * node nodename is changed in the completion service parameter.
553 *
554 * Return code
555 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
556 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
557 *
558 **/
559static uint8_t
560lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
561 struct serv_parm *sp)
562{
563 uint8_t fabric_param_changed = 0;
564 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
565
566 if ((vport->fc_prevDID != vport->fc_myDID) ||
567 memcmp(&vport->fabric_portname, &sp->portName,
568 sizeof(struct lpfc_name)) ||
569 memcmp(&vport->fabric_nodename, &sp->nodeName,
570 sizeof(struct lpfc_name)))
571 fabric_param_changed = 1;
572
573 /*
574 * Word 1 Bit 31 in common service parameter is overloaded.
575 * Word 1 Bit 31 in FLOGI request is multiple NPort request
576 * Word 1 Bit 31 in FLOGI response is clean address bit
577 *
578 * If fabric parameter is changed and clean address bit is
579 * cleared delay nport discovery if
580 * - vport->fc_prevDID != 0 (not initial discovery) OR
581 * - lpfc_delay_discovery module parameter is set.
582 */
583 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
584 (vport->fc_prevDID || lpfc_delay_discovery)) {
585 spin_lock_irq(shost->host_lock);
586 vport->fc_flag |= FC_DISC_DELAYED;
587 spin_unlock_irq(shost->host_lock);
588 }
589
590 return fabric_param_changed;
591}
592
593
594/**
James Smart3621a712009-04-06 18:47:14 -0400595 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400596 * @vport: pointer to a host virtual N_Port data structure.
597 * @ndlp: pointer to a node-list data structure.
598 * @sp: pointer to service parameter data structure.
599 * @irsp: pointer to the IOCB within the lpfc response IOCB.
600 *
601 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
602 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
603 * port in a fabric topology. It properly sets up the parameters to the @ndlp
604 * from the IOCB response. It also check the newly assigned N_Port ID to the
605 * @vport against the previously assigned N_Port ID. If it is different from
606 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
607 * is invoked on all the remaining nodes with the @vport to unregister the
608 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
609 * is invoked to register login to the fabric.
610 *
611 * Return code
612 * 0 - Success (currently, always return 0)
613 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500614static int
James Smart2e0fef82007-06-17 19:56:36 -0500615lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
616 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500617{
James Smart2e0fef82007-06-17 19:56:36 -0500618 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
619 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500620 struct lpfc_nodelist *np;
621 struct lpfc_nodelist *next_np;
James Smart92494142011-02-16 12:39:44 -0500622 uint8_t fabric_param_changed;
dea31012005-04-17 16:05:31 -0500623
James Smart2e0fef82007-06-17 19:56:36 -0500624 spin_lock_irq(shost->host_lock);
625 vport->fc_flag |= FC_FABRIC;
626 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500627
628 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
629 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
630 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
631
James Smart12265f62010-10-22 11:05:53 -0400632 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500633 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
634
James Smart76a95d72010-11-20 23:11:48 -0500635 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500636 spin_lock_irq(shost->host_lock);
637 vport->fc_flag |= FC_PUBLIC_LOOP;
638 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500639 }
640
James Smart2e0fef82007-06-17 19:56:36 -0500641 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500642 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500643 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500644 ndlp->nlp_class_sup = 0;
645 if (sp->cls1.classValid)
646 ndlp->nlp_class_sup |= FC_COS_CLASS1;
647 if (sp->cls2.classValid)
648 ndlp->nlp_class_sup |= FC_COS_CLASS2;
649 if (sp->cls3.classValid)
650 ndlp->nlp_class_sup |= FC_COS_CLASS3;
651 if (sp->cls4.classValid)
652 ndlp->nlp_class_sup |= FC_COS_CLASS4;
653 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
654 sp->cmn.bbRcvSizeLsb;
James Smart92494142011-02-16 12:39:44 -0500655
656 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
657 memcpy(&vport->fabric_portname, &sp->portName,
658 sizeof(struct lpfc_name));
659 memcpy(&vport->fabric_nodename, &sp->nodeName,
660 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500661 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
662
James Smart92d7f7b2007-06-17 19:56:38 -0500663 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
664 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400665 lpfc_printf_vlog(vport, KERN_WARNING,
666 LOG_ELS | LOG_VPORT,
667 "1816 FLOGI NPIV supported, "
668 "response data 0x%x\n",
669 sp->cmn.response_multiple_NPort);
James Smart1b511972011-12-13 13:23:09 -0500670 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500671 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500672 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500673 } else {
674 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400675 to call reg_vnpid atleast for the physcial host */
676 lpfc_printf_vlog(vport, KERN_WARNING,
677 LOG_ELS | LOG_VPORT,
678 "1817 Fabric does not support NPIV "
679 "- configuring single port mode.\n");
James Smart1b511972011-12-13 13:23:09 -0500680 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500681 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500682 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500683 }
684 }
685
James Smart92494142011-02-16 12:39:44 -0500686 if (fabric_param_changed &&
James Smart92d7f7b2007-06-17 19:56:38 -0500687 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
688
689 /* If our NportID changed, we need to ensure all
690 * remaining NPORTs get unreg_login'ed.
691 */
692 list_for_each_entry_safe(np, next_np,
693 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400694 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500695 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500696 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
697 !(np->nlp_flag & NLP_NPR_ADISC))
698 continue;
699 spin_lock_irq(shost->host_lock);
700 np->nlp_flag &= ~NLP_NPR_ADISC;
701 spin_unlock_irq(shost->host_lock);
702 lpfc_unreg_rpi(vport, np);
703 }
James Smart78730cf2010-04-06 15:06:30 -0400704 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400705
James Smart5248a742011-07-22 18:37:06 -0400706 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart5af5eee2010-10-22 11:06:38 -0400707 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500708 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500709 spin_lock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -0500710 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
711 spin_unlock_irq(shost->host_lock);
712 }
James Smart27aa1b72012-05-09 21:18:49 -0400713
714 /*
715 * For SLI3 and SLI4, the VPI needs to be reregistered in
716 * response to this fabric parameter change event.
717 */
718 spin_lock_irq(shost->host_lock);
719 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
720 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -0400721 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
722 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
723 /*
724 * Driver needs to re-reg VPI in order for f/w
725 * to update the MAC address.
726 */
James Smart9589b062011-04-16 11:03:17 -0400727 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400728 lpfc_register_new_vport(phba, vport, ndlp);
729 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500730 }
731
James Smart6fb120a2009-05-22 14:52:59 -0400732 if (phba->sli_rev < LPFC_SLI_REV4) {
733 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
734 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
735 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
736 lpfc_register_new_vport(phba, vport, ndlp);
737 else
738 lpfc_issue_fabric_reglogin(vport);
739 } else {
740 ndlp->nlp_type |= NLP_FABRIC;
741 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500742 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
743 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400744 lpfc_start_fdiscs(phba);
745 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500746 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500747 lpfc_issue_init_vpi(vport);
James Smart1b511972011-12-13 13:23:09 -0500748 else {
749 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
750 "3135 Need register VFI: (x%x/%x)\n",
751 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -0400752 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -0500753 }
James Smart92d7f7b2007-06-17 19:56:38 -0500754 }
dea31012005-04-17 16:05:31 -0500755 return 0;
dea31012005-04-17 16:05:31 -0500756}
James Smart1b511972011-12-13 13:23:09 -0500757
James Smarte59058c2008-08-24 21:49:00 -0400758/**
James Smart3621a712009-04-06 18:47:14 -0400759 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400760 * @vport: pointer to a host virtual N_Port data structure.
761 * @ndlp: pointer to a node-list data structure.
762 * @sp: pointer to service parameter data structure.
763 *
764 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
765 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
766 * in a point-to-point topology. First, the @vport's N_Port Name is compared
767 * with the received N_Port Name: if the @vport's N_Port Name is greater than
768 * the received N_Port Name lexicographically, this node shall assign local
769 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
770 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
771 * this node shall just wait for the remote node to issue PLOGI and assign
772 * N_Port IDs.
773 *
774 * Return code
775 * 0 - Success
776 * -ENXIO - Fail
777 **/
dea31012005-04-17 16:05:31 -0500778static int
James Smart2e0fef82007-06-17 19:56:36 -0500779lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
780 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500781{
James Smart2e0fef82007-06-17 19:56:36 -0500782 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
783 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500784 LPFC_MBOXQ_t *mbox;
785 int rc;
786
James Smart2e0fef82007-06-17 19:56:36 -0500787 spin_lock_irq(shost->host_lock);
788 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
789 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500790
791 phba->fc_edtov = FF_DEF_EDTOV;
792 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500793 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500794 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500795 if (rc >= 0) {
796 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500797 spin_lock_irq(shost->host_lock);
798 vport->fc_flag |= FC_PT2PT_PLOGI;
799 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500800
801 /*
802 * N_Port ID cannot be 0, set our to LocalID the other
803 * side will be RemoteID.
804 */
805
806 /* not equal */
807 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500808 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500809
810 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
811 if (!mbox)
812 goto fail;
813
814 lpfc_config_link(phba, mbox);
815
816 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500817 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400818 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500819 if (rc == MBX_NOT_FINISHED) {
820 mempool_free(mbox, phba->mbox_mem_pool);
821 goto fail;
822 }
James Smarte47c9092008-02-08 18:49:26 -0500823 /* Decrement ndlp reference count indicating that ndlp can be
824 * safely released when other references to it are done.
825 */
James Smart329f9bc2007-04-25 09:53:01 -0400826 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500827
James Smart2e0fef82007-06-17 19:56:36 -0500828 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500829 if (!ndlp) {
830 /*
831 * Cannot find existing Fabric ndlp, so allocate a
832 * new one
833 */
834 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
835 if (!ndlp)
836 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500837 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500838 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
839 ndlp = lpfc_enable_node(vport, ndlp,
840 NLP_STE_UNUSED_NODE);
841 if(!ndlp)
842 goto fail;
dea31012005-04-17 16:05:31 -0500843 }
844
845 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500846 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500847 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500848 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500849 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500850 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
851 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500852 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500853 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500854 } else
855 /* This side will wait for the PLOGI, decrement ndlp reference
856 * count indicating that ndlp can be released when other
857 * references to it are done.
858 */
James Smart329f9bc2007-04-25 09:53:01 -0400859 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500860
James Smart09372822008-01-11 01:52:54 -0500861 /* If we are pt2pt with another NPort, force NPIV off! */
862 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
863
James Smart2e0fef82007-06-17 19:56:36 -0500864 spin_lock_irq(shost->host_lock);
865 vport->fc_flag |= FC_PT2PT;
866 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500867
868 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500869 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500870 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500871fail:
dea31012005-04-17 16:05:31 -0500872 return -ENXIO;
873}
874
James Smarte59058c2008-08-24 21:49:00 -0400875/**
James Smart3621a712009-04-06 18:47:14 -0400876 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400877 * @phba: pointer to lpfc hba data structure.
878 * @cmdiocb: pointer to lpfc command iocb data structure.
879 * @rspiocb: pointer to lpfc response iocb data structure.
880 *
881 * This routine is the top-level completion callback function for issuing
882 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
883 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
884 * retry has been made (either immediately or delayed with lpfc_els_retry()
885 * returning 1), the command IOCB will be released and function returned.
886 * If the retry attempt has been given up (possibly reach the maximum
887 * number of retries), one additional decrement of ndlp reference shall be
888 * invoked before going out after releasing the command IOCB. This will
889 * actually release the remote node (Note, lpfc_els_free_iocb() will also
890 * invoke one decrement of ndlp reference count). If no error reported in
891 * the IOCB status, the command Port ID field is used to determine whether
892 * this is a point-to-point topology or a fabric topology: if the Port ID
893 * field is assigned, it is a fabric topology; otherwise, it is a
894 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
895 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
896 * specific topology completion conditions.
897 **/
dea31012005-04-17 16:05:31 -0500898static void
James Smart329f9bc2007-04-25 09:53:01 -0400899lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
900 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500901{
James Smart2e0fef82007-06-17 19:56:36 -0500902 struct lpfc_vport *vport = cmdiocb->vport;
903 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500904 IOCB_t *irsp = &rspiocb->iocb;
905 struct lpfc_nodelist *ndlp = cmdiocb->context1;
906 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
907 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500908 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500909 int rc;
910
911 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500912 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500913 /* One additional decrement on node reference count to
914 * trigger the release of the node
915 */
James Smart329f9bc2007-04-25 09:53:01 -0400916 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500917 goto out;
918 }
919
James Smart858c9f62007-06-17 19:56:39 -0500920 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
921 "FLOGI cmpl: status:x%x/x%x state:x%x",
922 irsp->ulpStatus, irsp->un.ulpWord[4],
923 vport->port_state);
924
dea31012005-04-17 16:05:31 -0500925 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500926 /*
James Smarta93ff372010-10-22 11:06:08 -0400927 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500928 * due to new FCF discovery
929 */
930 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart80c17842012-03-01 22:35:45 -0500931 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
932 if (phba->link_state < LPFC_LINK_UP)
933 goto stop_rr_fcf_flogi;
934 if ((phba->fcoe_cvl_eventtag_attn ==
935 phba->fcoe_cvl_eventtag) &&
936 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
937 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))
938 goto stop_rr_fcf_flogi;
939 else
940 phba->fcoe_cvl_eventtag_attn =
941 phba->fcoe_cvl_eventtag;
James Smart0c9ab6f2010-02-26 14:15:57 -0500942 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400943 "2611 FLOGI failed on FCF (x%x), "
944 "status:x%x/x%x, tmo:x%x, perform "
945 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -0400946 phba->fcf.current_rec.fcf_indx,
947 irsp->ulpStatus, irsp->un.ulpWord[4],
948 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -0400949 lpfc_sli4_set_fcf_flogi_fail(phba,
950 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500951 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -0400952 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
953 if (rc)
954 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500955 }
956
James Smart80c17842012-03-01 22:35:45 -0500957stop_rr_fcf_flogi:
James Smart38b92ef2010-08-04 16:11:39 -0400958 /* FLOGI failure */
959 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
960 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
961 irsp->ulpStatus, irsp->un.ulpWord[4],
962 irsp->ulpTimeout);
963
dea31012005-04-17 16:05:31 -0500964 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500965 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500966 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500967
James Smart76a95d72010-11-20 23:11:48 -0500968 /* FLOGI failure */
969 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
970 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
971 irsp->ulpStatus, irsp->un.ulpWord[4],
972 irsp->ulpTimeout);
973
dea31012005-04-17 16:05:31 -0500974 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500975 spin_lock_irq(shost->host_lock);
976 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
977 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500978
James Smart329f9bc2007-04-25 09:53:01 -0400979 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500980 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
981 * alpa map would take too long otherwise.
982 */
James Smart1b511972011-12-13 13:23:09 -0500983 if (phba->alpa_map[0] == 0)
James Smart3de2a652007-08-02 11:09:59 -0400984 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -0500985 if ((phba->sli_rev == LPFC_SLI_REV4) &&
986 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
987 (vport->fc_prevDID != vport->fc_myDID))) {
988 if (vport->fc_flag & FC_VFI_REGISTERED)
989 lpfc_sli4_unreg_all_rpis(vport);
990 lpfc_issue_reg_vfi(vport);
991 lpfc_nlp_put(ndlp);
992 goto out;
dea31012005-04-17 16:05:31 -0500993 }
dea31012005-04-17 16:05:31 -0500994 goto flogifail;
995 }
James Smart695a8142010-01-26 23:08:03 -0500996 spin_lock_irq(shost->host_lock);
997 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400998 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500999 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001000
1001 /*
1002 * The FLogI succeeded. Sync the data for the CPU before
1003 * accessing it.
1004 */
1005 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1006
1007 sp = prsp->virt + sizeof(uint32_t);
1008
1009 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -04001010 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001011 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -04001012 "Data: x%x x%x x%x x%x\n",
1013 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1014 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -05001015
James Smart2e0fef82007-06-17 19:56:36 -05001016 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -05001017 /*
1018 * If Common Service Parameters indicate Nport
1019 * we are point to point, if Fport we are Fabric.
1020 */
1021 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -05001022 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -05001023 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001024 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -04001025 else {
1026 lpfc_printf_vlog(vport, KERN_ERR,
1027 LOG_FIP | LOG_ELS,
1028 "2831 FLOGI response with cleared Fabric "
1029 "bit fcf_index 0x%x "
1030 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1031 "Fabric Name "
1032 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1033 phba->fcf.current_rec.fcf_indx,
1034 phba->fcf.current_rec.switch_name[0],
1035 phba->fcf.current_rec.switch_name[1],
1036 phba->fcf.current_rec.switch_name[2],
1037 phba->fcf.current_rec.switch_name[3],
1038 phba->fcf.current_rec.switch_name[4],
1039 phba->fcf.current_rec.switch_name[5],
1040 phba->fcf.current_rec.switch_name[6],
1041 phba->fcf.current_rec.switch_name[7],
1042 phba->fcf.current_rec.fabric_name[0],
1043 phba->fcf.current_rec.fabric_name[1],
1044 phba->fcf.current_rec.fabric_name[2],
1045 phba->fcf.current_rec.fabric_name[3],
1046 phba->fcf.current_rec.fabric_name[4],
1047 phba->fcf.current_rec.fabric_name[5],
1048 phba->fcf.current_rec.fabric_name[6],
1049 phba->fcf.current_rec.fabric_name[7]);
1050 lpfc_nlp_put(ndlp);
1051 spin_lock_irq(&phba->hbalock);
1052 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001053 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -04001054 spin_unlock_irq(&phba->hbalock);
1055 goto out;
1056 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001057 if (!rc) {
1058 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -04001059 if (phba->hba_flag & HBA_FIP_SUPPORT)
1060 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1061 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001062 "2769 FLOGI to FCF (x%x) "
1063 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -04001064 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001065 spin_lock_irq(&phba->hbalock);
1066 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001067 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -05001068 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001069 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001070 }
dea31012005-04-17 16:05:31 -05001071 }
1072
1073flogifail:
James Smart329f9bc2007-04-25 09:53:01 -04001074 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001075
James Smart858c9f62007-06-17 19:56:39 -05001076 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001077 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001078 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001079
1080 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001081 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001082 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1083 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
1084 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
1085 (phba->link_state != LPFC_CLEAR_LA)) {
1086 /* If FLOGI failed enable link interrupt. */
1087 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001088 }
dea31012005-04-17 16:05:31 -05001089out:
1090 lpfc_els_free_iocb(phba, cmdiocb);
1091}
1092
James Smarte59058c2008-08-24 21:49:00 -04001093/**
James Smart3621a712009-04-06 18:47:14 -04001094 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001095 * @vport: pointer to a host virtual N_Port data structure.
1096 * @ndlp: pointer to a node-list data structure.
1097 * @retry: number of retries to the command IOCB.
1098 *
1099 * This routine issues a Fabric Login (FLOGI) Request ELS command
1100 * for a @vport. The initiator service parameters are put into the payload
1101 * of the FLOGI Request IOCB and the top-level callback function pointer
1102 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1103 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1104 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1105 *
1106 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1107 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1108 * will be stored into the context1 field of the IOCB for the completion
1109 * callback function to the FLOGI ELS command.
1110 *
1111 * Return code
1112 * 0 - successfully issued flogi iocb for @vport
1113 * 1 - failed to issue flogi iocb for @vport
1114 **/
dea31012005-04-17 16:05:31 -05001115static int
James Smart2e0fef82007-06-17 19:56:36 -05001116lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001117 uint8_t retry)
1118{
James Smart2e0fef82007-06-17 19:56:36 -05001119 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001120 struct serv_parm *sp;
1121 IOCB_t *icmd;
1122 struct lpfc_iocbq *elsiocb;
1123 struct lpfc_sli_ring *pring;
1124 uint8_t *pcmd;
1125 uint16_t cmdsize;
1126 uint32_t tmo;
1127 int rc;
1128
1129 pring = &phba->sli.ring[LPFC_ELS_RING];
1130
James Smart92d7f7b2007-06-17 19:56:38 -05001131 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001132 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1133 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001134
James Smart488d1462006-03-07 15:02:37 -05001135 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001136 return 1;
dea31012005-04-17 16:05:31 -05001137
1138 icmd = &elsiocb->iocb;
1139 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1140
1141 /* For FLOGI request, remainder of payload is service parameters */
1142 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001143 pcmd += sizeof(uint32_t);
1144 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001145 sp = (struct serv_parm *) pcmd;
1146
1147 /* Setup CSPs accordingly for Fabric */
1148 sp->cmn.e_d_tov = 0;
1149 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001150 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001151 sp->cls1.classValid = 0;
1152 sp->cls2.seqDelivery = 1;
1153 sp->cls3.seqDelivery = 1;
1154 if (sp->cmn.fcphLow < FC_PH3)
1155 sp->cmn.fcphLow = FC_PH3;
1156 if (sp->cmn.fcphHigh < FC_PH3)
1157 sp->cmn.fcphHigh = FC_PH3;
1158
James Smartc31098c2011-04-16 11:03:33 -04001159 if (phba->sli_rev == LPFC_SLI_REV4) {
1160 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1161 LPFC_SLI_INTF_IF_TYPE_0) {
1162 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1163 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1164 /* FLOGI needs to be 3 for WQE FCFI */
1165 /* Set the fcfi to the fcfi we registered with */
1166 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1167 }
James Smart5248a742011-07-22 18:37:06 -04001168 } else {
1169 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1170 sp->cmn.request_multiple_Nport = 1;
1171 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1172 icmd->ulpCt_h = 1;
1173 icmd->ulpCt_l = 0;
1174 } else
1175 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001176 }
1177
James Smart76a95d72010-11-20 23:11:48 -05001178 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001179 icmd->un.elsreq64.myID = 0;
1180 icmd->un.elsreq64.fl = 1;
1181 }
1182
dea31012005-04-17 16:05:31 -05001183 tmo = phba->fc_ratov;
1184 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001185 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001186 phba->fc_ratov = tmo;
1187
1188 phba->fc_stat.elsXmitFLOGI++;
1189 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001190
1191 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1192 "Issue FLOGI: opt:x%x",
1193 phba->sli3_options, 0, 0);
1194
James Smart92d7f7b2007-06-17 19:56:38 -05001195 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001196 if (rc == IOCB_ERROR) {
1197 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001198 return 1;
dea31012005-04-17 16:05:31 -05001199 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001200 return 0;
dea31012005-04-17 16:05:31 -05001201}
1202
James Smarte59058c2008-08-24 21:49:00 -04001203/**
James Smart3621a712009-04-06 18:47:14 -04001204 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001205 * @phba: pointer to lpfc hba data structure.
1206 *
1207 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1208 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1209 * list and issues an abort IOCB commond on each outstanding IOCB that
1210 * contains a active Fabric_DID ndlp. Note that this function is to issue
1211 * the abort IOCB command on all the outstanding IOCBs, thus when this
1212 * function returns, it does not guarantee all the IOCBs are actually aborted.
1213 *
1214 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001215 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001216 **/
dea31012005-04-17 16:05:31 -05001217int
James Smart2e0fef82007-06-17 19:56:36 -05001218lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001219{
1220 struct lpfc_sli_ring *pring;
1221 struct lpfc_iocbq *iocb, *next_iocb;
1222 struct lpfc_nodelist *ndlp;
1223 IOCB_t *icmd;
1224
1225 /* Abort outstanding I/O on NPort <nlp_DID> */
1226 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001227 "0201 Abort outstanding I/O on NPort x%x\n",
1228 Fabric_DID);
dea31012005-04-17 16:05:31 -05001229
1230 pring = &phba->sli.ring[LPFC_ELS_RING];
1231
1232 /*
1233 * Check the txcmplq for an iocb that matches the nport the driver is
1234 * searching for.
1235 */
James Smart2e0fef82007-06-17 19:56:36 -05001236 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001237 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1238 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001239 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001240 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001241 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1242 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001243 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001244 }
1245 }
James Smart2e0fef82007-06-17 19:56:36 -05001246 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001247
1248 return 0;
1249}
1250
James Smarte59058c2008-08-24 21:49:00 -04001251/**
James Smart3621a712009-04-06 18:47:14 -04001252 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001253 * @vport: pointer to a host virtual N_Port data structure.
1254 *
1255 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1256 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1257 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1258 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1259 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1260 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1261 * @vport.
1262 *
1263 * Return code
1264 * 0 - failed to issue initial flogi for @vport
1265 * 1 - successfully issued initial flogi for @vport
1266 **/
dea31012005-04-17 16:05:31 -05001267int
James Smart2e0fef82007-06-17 19:56:36 -05001268lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001269{
James Smart2e0fef82007-06-17 19:56:36 -05001270 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001271 struct lpfc_nodelist *ndlp;
1272
James Smart98c9ea52007-10-27 13:37:33 -04001273 vport->port_state = LPFC_FLOGI;
1274 lpfc_set_disctmo(vport);
1275
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001276 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001277 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001278 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001279 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001280 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1281 if (!ndlp)
1282 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001283 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001284 /* Set the node type */
1285 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001286 /* Put ndlp onto node list */
1287 lpfc_enqueue_node(vport, ndlp);
1288 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1289 /* re-setup ndlp without removing from node list */
1290 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1291 if (!ndlp)
1292 return 0;
dea31012005-04-17 16:05:31 -05001293 }
James Smart87af33f2007-10-27 13:37:43 -04001294
James Smart5ac6b302010-10-22 11:05:36 -04001295 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001296 /* This decrement of reference count to node shall kick off
1297 * the release of the node.
1298 */
James Smart329f9bc2007-04-25 09:53:01 -04001299 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001300 return 0;
1301 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001302 return 1;
dea31012005-04-17 16:05:31 -05001303}
1304
James Smarte59058c2008-08-24 21:49:00 -04001305/**
James Smart3621a712009-04-06 18:47:14 -04001306 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001307 * @vport: pointer to a host virtual N_Port data structure.
1308 *
1309 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1310 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1311 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1312 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1313 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1314 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1315 * @vport.
1316 *
1317 * Return code
1318 * 0 - failed to issue initial fdisc for @vport
1319 * 1 - successfully issued initial fdisc for @vport
1320 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001321int
1322lpfc_initial_fdisc(struct lpfc_vport *vport)
1323{
1324 struct lpfc_hba *phba = vport->phba;
1325 struct lpfc_nodelist *ndlp;
1326
1327 /* First look for the Fabric ndlp */
1328 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1329 if (!ndlp) {
1330 /* Cannot find existing Fabric ndlp, so allocate a new one */
1331 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1332 if (!ndlp)
1333 return 0;
1334 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001335 /* Put ndlp onto node list */
1336 lpfc_enqueue_node(vport, ndlp);
1337 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1338 /* re-setup ndlp without removing from node list */
1339 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1340 if (!ndlp)
1341 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001342 }
James Smarte47c9092008-02-08 18:49:26 -05001343
James Smart92d7f7b2007-06-17 19:56:38 -05001344 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001345 /* decrement node reference count to trigger the release of
1346 * the node.
1347 */
James Smart92d7f7b2007-06-17 19:56:38 -05001348 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001349 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001350 }
1351 return 1;
1352}
James Smart87af33f2007-10-27 13:37:43 -04001353
James Smarte59058c2008-08-24 21:49:00 -04001354/**
James Smart3621a712009-04-06 18:47:14 -04001355 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001356 * @vport: pointer to a host virtual N_Port data structure.
1357 *
1358 * This routine checks whether there are more remaining Port Logins
1359 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1360 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1361 * to issue ELS PLOGIs up to the configured discover threads with the
1362 * @vport (@vport->cfg_discovery_threads). The function also decrement
1363 * the @vport's num_disc_node by 1 if it is not already 0.
1364 **/
James Smart87af33f2007-10-27 13:37:43 -04001365void
James Smart2e0fef82007-06-17 19:56:36 -05001366lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001367{
1368 int sentplogi;
1369
James Smart2e0fef82007-06-17 19:56:36 -05001370 if (vport->num_disc_nodes)
1371 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001372
1373 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001374 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1375 "0232 Continue discovery with %d PLOGIs to go "
1376 "Data: x%x x%x x%x\n",
1377 vport->num_disc_nodes, vport->fc_plogi_cnt,
1378 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001379 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001380 if (vport->fc_flag & FC_NLP_MORE)
1381 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1382 sentplogi = lpfc_els_disc_plogi(vport);
1383
dea31012005-04-17 16:05:31 -05001384 return;
1385}
1386
James Smarte59058c2008-08-24 21:49:00 -04001387/**
James Smart3621a712009-04-06 18:47:14 -04001388 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001389 * @phba: pointer to lpfc hba data structure.
1390 * @prsp: pointer to response IOCB payload.
1391 * @ndlp: pointer to a node-list data structure.
1392 *
1393 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1394 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1395 * The following cases are considered N_Port confirmed:
1396 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1397 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1398 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1399 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1400 * 1) if there is a node on vport list other than the @ndlp with the same
1401 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1402 * on that node to release the RPI associated with the node; 2) if there is
1403 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1404 * into, a new node shall be allocated (or activated). In either case, the
1405 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1406 * be released and the new_ndlp shall be put on to the vport node list and
1407 * its pointer returned as the confirmed node.
1408 *
1409 * Note that before the @ndlp got "released", the keepDID from not-matching
1410 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1411 * of the @ndlp. This is because the release of @ndlp is actually to put it
1412 * into an inactive state on the vport node list and the vport node list
1413 * management algorithm does not allow two node with a same DID.
1414 *
1415 * Return code
1416 * pointer to the PLOGI N_Port @ndlp
1417 **/
James Smart488d1462006-03-07 15:02:37 -05001418static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001419lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001420 struct lpfc_nodelist *ndlp)
1421{
James Smart2e0fef82007-06-17 19:56:36 -05001422 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001423 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001424 struct lpfc_rport_data *rdata;
1425 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001426 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001427 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001428 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001429 int put_node;
1430 int put_rport;
James Smart19ca7602010-11-20 23:11:55 -05001431 struct lpfc_node_rrqs rrq;
James Smart488d1462006-03-07 15:02:37 -05001432
James Smart2fb9bd82006-12-02 13:33:57 -05001433 /* Fabric nodes can have the same WWPN so we don't bother searching
1434 * by WWPN. Just return the ndlp that was given to us.
1435 */
1436 if (ndlp->nlp_type & NLP_FABRIC)
1437 return ndlp;
1438
James Smart92d7f7b2007-06-17 19:56:38 -05001439 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001440 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001441
James Smart685f0bf2007-04-25 09:53:08 -04001442 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001443 * we have for that ndlp. If not, we have some work to do.
1444 */
James Smart2e0fef82007-06-17 19:56:36 -05001445 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001446
James Smarte47c9092008-02-08 18:49:26 -05001447 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001448 return ndlp;
James Smart19ca7602010-11-20 23:11:55 -05001449 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
James Smart488d1462006-03-07 15:02:37 -05001450
1451 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001452 rc = memcmp(&ndlp->nlp_portname, name,
1453 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001454 if (!rc)
1455 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001456 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1457 if (!new_ndlp)
1458 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001459 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001460 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001461 rc = memcmp(&ndlp->nlp_portname, name,
1462 sizeof(struct lpfc_name));
1463 if (!rc)
1464 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001465 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1466 NLP_STE_UNUSED_NODE);
1467 if (!new_ndlp)
1468 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001469 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001470 if (phba->sli_rev == LPFC_SLI_REV4)
1471 memcpy(&rrq.xri_bitmap,
1472 &new_ndlp->active_rrqs.xri_bitmap,
1473 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1474 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001475 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001476 if (phba->sli_rev == LPFC_SLI_REV4)
1477 memcpy(&rrq.xri_bitmap,
1478 &new_ndlp->active_rrqs.xri_bitmap,
1479 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1480 }
James Smart488d1462006-03-07 15:02:37 -05001481
James Smart2e0fef82007-06-17 19:56:36 -05001482 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001483 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001484 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001485 if (phba->sli_rev == LPFC_SLI_REV4)
1486 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1487 &ndlp->active_rrqs.xri_bitmap,
1488 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart0ff10d42008-01-11 01:52:36 -05001489
1490 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1491 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1492 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1493
James Smarte47c9092008-02-08 18:49:26 -05001494 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001495 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001496
James Smart2e0fef82007-06-17 19:56:36 -05001497 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001498 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1499 /* The new_ndlp is replacing ndlp totally, so we need
1500 * to put ndlp on UNUSED list and try to free it.
1501 */
James Smart0ff10d42008-01-11 01:52:36 -05001502
1503 /* Fix up the rport accordingly */
1504 rport = ndlp->rport;
1505 if (rport) {
1506 rdata = rport->dd_data;
1507 if (rdata->pnode == ndlp) {
1508 lpfc_nlp_put(ndlp);
1509 ndlp->rport = NULL;
1510 rdata->pnode = lpfc_nlp_get(new_ndlp);
1511 new_ndlp->rport = rport;
1512 }
1513 new_ndlp->nlp_type = ndlp->nlp_type;
1514 }
James Smart58da1ff2008-04-07 10:15:56 -04001515 /* We shall actually free the ndlp with both nlp_DID and
1516 * nlp_portname fields equals 0 to avoid any ndlp on the
1517 * nodelist never to be used.
1518 */
1519 if (ndlp->nlp_DID == 0) {
1520 spin_lock_irq(&phba->ndlp_lock);
1521 NLP_SET_FREE_REQ(ndlp);
1522 spin_unlock_irq(&phba->ndlp_lock);
1523 }
James Smart0ff10d42008-01-11 01:52:36 -05001524
James Smart58da1ff2008-04-07 10:15:56 -04001525 /* Two ndlps cannot have the same did on the nodelist */
1526 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001527 if (phba->sli_rev == LPFC_SLI_REV4)
1528 memcpy(&ndlp->active_rrqs.xri_bitmap,
1529 &rrq.xri_bitmap,
1530 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001531 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001532 }
James Smart92795652006-07-06 15:50:02 -04001533 else {
James Smart2e0fef82007-06-17 19:56:36 -05001534 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001535 /* Two ndlps cannot have the same did */
1536 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001537 if (phba->sli_rev == LPFC_SLI_REV4)
1538 memcpy(&ndlp->active_rrqs.xri_bitmap,
1539 &rrq.xri_bitmap,
1540 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart38b92ef2010-08-04 16:11:39 -04001541 /* Since we are swapping the ndlp passed in with the new one
1542 * and the did has already been swapped, copy over the
1543 * state and names.
1544 */
1545 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1546 sizeof(struct lpfc_name));
1547 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1548 sizeof(struct lpfc_name));
1549 new_ndlp->nlp_state = ndlp->nlp_state;
James Smarteff4a012012-01-18 16:25:25 -05001550 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart38b92ef2010-08-04 16:11:39 -04001551 /* Fix up the rport accordingly */
1552 rport = ndlp->rport;
1553 if (rport) {
1554 rdata = rport->dd_data;
1555 put_node = rdata->pnode != NULL;
1556 put_rport = ndlp->rport != NULL;
1557 rdata->pnode = NULL;
1558 ndlp->rport = NULL;
1559 if (put_node)
1560 lpfc_nlp_put(ndlp);
1561 if (put_rport)
1562 put_device(&rport->dev);
1563 }
James Smart92795652006-07-06 15:50:02 -04001564 }
James Smart488d1462006-03-07 15:02:37 -05001565 return new_ndlp;
1566}
1567
James Smarte59058c2008-08-24 21:49:00 -04001568/**
James Smart3621a712009-04-06 18:47:14 -04001569 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001570 * @vport: pointer to a host virtual N_Port data structure.
1571 *
1572 * This routine checks whether more Registration State Change
1573 * Notifications (RSCNs) came in while the discovery state machine was in
1574 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1575 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1576 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1577 * handling the RSCNs.
1578 **/
James Smart87af33f2007-10-27 13:37:43 -04001579void
1580lpfc_end_rscn(struct lpfc_vport *vport)
1581{
1582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1583
1584 if (vport->fc_flag & FC_RSCN_MODE) {
1585 /*
1586 * Check to see if more RSCNs came in while we were
1587 * processing this one.
1588 */
1589 if (vport->fc_rscn_id_cnt ||
1590 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1591 lpfc_els_handle_rscn(vport);
1592 else {
1593 spin_lock_irq(shost->host_lock);
1594 vport->fc_flag &= ~FC_RSCN_MODE;
1595 spin_unlock_irq(shost->host_lock);
1596 }
1597 }
1598}
1599
James Smarte59058c2008-08-24 21:49:00 -04001600/**
James Smart19ca7602010-11-20 23:11:55 -05001601 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1602 * @phba: pointer to lpfc hba data structure.
1603 * @cmdiocb: pointer to lpfc command iocb data structure.
1604 * @rspiocb: pointer to lpfc response iocb data structure.
1605 *
1606 * This routine will call the clear rrq function to free the rrq and
1607 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1608 * exist then the clear_rrq is still called because the rrq needs to
1609 * be freed.
1610 **/
1611
1612static void
1613lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1614 struct lpfc_iocbq *rspiocb)
1615{
1616 struct lpfc_vport *vport = cmdiocb->vport;
1617 IOCB_t *irsp;
1618 struct lpfc_nodelist *ndlp;
1619 struct lpfc_node_rrq *rrq;
1620
1621 /* we pass cmdiocb to state machine which needs rspiocb as well */
1622 rrq = cmdiocb->context_un.rrq;
1623 cmdiocb->context_un.rsp_iocb = rspiocb;
1624
1625 irsp = &rspiocb->iocb;
1626 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1627 "RRQ cmpl: status:x%x/x%x did:x%x",
1628 irsp->ulpStatus, irsp->un.ulpWord[4],
1629 irsp->un.elsreq64.remoteID);
1630
1631 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1632 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1633 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1634 "2882 RRQ completes to NPort x%x "
1635 "with no ndlp. Data: x%x x%x x%x\n",
1636 irsp->un.elsreq64.remoteID,
1637 irsp->ulpStatus, irsp->un.ulpWord[4],
1638 irsp->ulpIoTag);
1639 goto out;
1640 }
1641
1642 /* rrq completes to NPort <nlp_DID> */
1643 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1644 "2880 RRQ completes to NPort x%x "
1645 "Data: x%x x%x x%x x%x x%x\n",
1646 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1647 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1648
1649 if (irsp->ulpStatus) {
1650 /* Check for retry */
1651 /* RRQ failed Don't print the vport to vport rjts */
1652 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1653 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1654 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1655 (phba)->pport->cfg_log_verbose & LOG_ELS)
1656 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1657 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1658 ndlp->nlp_DID, irsp->ulpStatus,
1659 irsp->un.ulpWord[4]);
1660 }
1661out:
1662 if (rrq)
1663 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1664 lpfc_els_free_iocb(phba, cmdiocb);
1665 return;
1666}
1667/**
James Smart3621a712009-04-06 18:47:14 -04001668 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001669 * @phba: pointer to lpfc hba data structure.
1670 * @cmdiocb: pointer to lpfc command iocb data structure.
1671 * @rspiocb: pointer to lpfc response iocb data structure.
1672 *
1673 * This routine is the completion callback function for issuing the Port
1674 * Login (PLOGI) command. For PLOGI completion, there must be an active
1675 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001676 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001677 * ignored and command IOCB released. The PLOGI response IOCB status is
1678 * checked for error conditons. If there is error status reported, PLOGI
1679 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1680 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1681 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1682 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1683 * there are additional N_Port nodes with the vport that need to perform
1684 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1685 * PLOGIs.
1686 **/
dea31012005-04-17 16:05:31 -05001687static void
James Smart2e0fef82007-06-17 19:56:36 -05001688lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1689 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001690{
James Smart2e0fef82007-06-17 19:56:36 -05001691 struct lpfc_vport *vport = cmdiocb->vport;
1692 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001693 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001694 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001695 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001696 int disc, rc, did, type;
1697
dea31012005-04-17 16:05:31 -05001698 /* we pass cmdiocb to state machine which needs rspiocb as well */
1699 cmdiocb->context_un.rsp_iocb = rspiocb;
1700
1701 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001702 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1703 "PLOGI cmpl: status:x%x/x%x did:x%x",
1704 irsp->ulpStatus, irsp->un.ulpWord[4],
1705 irsp->un.elsreq64.remoteID);
1706
James Smart2e0fef82007-06-17 19:56:36 -05001707 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001708 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001709 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1710 "0136 PLOGI completes to NPort x%x "
1711 "with no ndlp. Data: x%x x%x x%x\n",
1712 irsp->un.elsreq64.remoteID,
1713 irsp->ulpStatus, irsp->un.ulpWord[4],
1714 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001715 goto out;
James Smarted957682007-06-17 19:56:37 -05001716 }
dea31012005-04-17 16:05:31 -05001717
1718 /* Since ndlp can be freed in the disc state machine, note if this node
1719 * is being used during discovery.
1720 */
James Smart2e0fef82007-06-17 19:56:36 -05001721 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001722 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001723 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001724 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001725 rc = 0;
1726
1727 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001728 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1729 "0102 PLOGI completes to NPort x%x "
1730 "Data: x%x x%x x%x x%x x%x\n",
1731 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1732 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001733 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001734 if (lpfc_els_chk_latt(vport)) {
1735 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001736 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001737 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001738 goto out;
1739 }
1740
1741 /* ndlp could be freed in DSM, save these values now */
1742 type = ndlp->nlp_type;
1743 did = ndlp->nlp_DID;
1744
1745 if (irsp->ulpStatus) {
1746 /* Check for retry */
1747 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1748 /* ELS command is being retried */
1749 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001750 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001751 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001752 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001753 }
1754 goto out;
1755 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001756 /* PLOGI failed Don't print the vport to vport rjts */
1757 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1758 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1759 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1760 (phba)->pport->cfg_log_verbose & LOG_ELS)
1761 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001762 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1763 ndlp->nlp_DID, irsp->ulpStatus,
1764 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001765 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001766 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001767 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001768 else
James Smart2e0fef82007-06-17 19:56:36 -05001769 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001770 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001771 } else {
1772 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001773 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001774 cmdiocb->context2)->list.next,
1775 struct lpfc_dmabuf, list);
1776 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001777 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001778 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001779 }
1780
James Smart2e0fef82007-06-17 19:56:36 -05001781 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001782 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001783 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001784
James Smart2e0fef82007-06-17 19:56:36 -05001785 if (vport->num_disc_nodes == 0) {
1786 spin_lock_irq(shost->host_lock);
1787 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1788 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001789
James Smart2e0fef82007-06-17 19:56:36 -05001790 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001791 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001792 }
1793 }
1794
1795out:
1796 lpfc_els_free_iocb(phba, cmdiocb);
1797 return;
1798}
1799
James Smarte59058c2008-08-24 21:49:00 -04001800/**
James Smart3621a712009-04-06 18:47:14 -04001801 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001802 * @vport: pointer to a host virtual N_Port data structure.
1803 * @did: destination port identifier.
1804 * @retry: number of retries to the command IOCB.
1805 *
1806 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1807 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1808 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1809 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1810 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1811 *
1812 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1813 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1814 * will be stored into the context1 field of the IOCB for the completion
1815 * callback function to the PLOGI ELS command.
1816 *
1817 * Return code
1818 * 0 - Successfully issued a plogi for @vport
1819 * 1 - failed to issue a plogi for @vport
1820 **/
dea31012005-04-17 16:05:31 -05001821int
James Smart2e0fef82007-06-17 19:56:36 -05001822lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001823{
James Smart2e0fef82007-06-17 19:56:36 -05001824 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001825 struct serv_parm *sp;
1826 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001827 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001828 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001829 struct lpfc_sli *psli;
1830 uint8_t *pcmd;
1831 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001832 int ret;
dea31012005-04-17 16:05:31 -05001833
1834 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001835
James Smart98c9ea52007-10-27 13:37:33 -04001836 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001837 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1838 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001839
James Smarte47c9092008-02-08 18:49:26 -05001840 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001841 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001842 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001843 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001844 if (!elsiocb)
1845 return 1;
dea31012005-04-17 16:05:31 -05001846
1847 icmd = &elsiocb->iocb;
1848 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1849
1850 /* For PLOGI request, remainder of payload is service parameters */
1851 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001852 pcmd += sizeof(uint32_t);
1853 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001854 sp = (struct serv_parm *) pcmd;
1855
James Smart5ac6b302010-10-22 11:05:36 -04001856 /*
1857 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1858 * to device on remote loops work.
1859 */
1860 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1861 sp->cmn.altBbCredit = 1;
1862
dea31012005-04-17 16:05:31 -05001863 if (sp->cmn.fcphLow < FC_PH_4_3)
1864 sp->cmn.fcphLow = FC_PH_4_3;
1865
1866 if (sp->cmn.fcphHigh < FC_PH3)
1867 sp->cmn.fcphHigh = FC_PH3;
1868
James Smart858c9f62007-06-17 19:56:39 -05001869 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1870 "Issue PLOGI: did:x%x",
1871 did, 0, 0);
1872
dea31012005-04-17 16:05:31 -05001873 phba->fc_stat.elsXmitPLOGI++;
1874 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001875 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001876
1877 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001878 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001879 return 1;
dea31012005-04-17 16:05:31 -05001880 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001881 return 0;
dea31012005-04-17 16:05:31 -05001882}
1883
James Smarte59058c2008-08-24 21:49:00 -04001884/**
James Smart3621a712009-04-06 18:47:14 -04001885 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001886 * @phba: pointer to lpfc hba data structure.
1887 * @cmdiocb: pointer to lpfc command iocb data structure.
1888 * @rspiocb: pointer to lpfc response iocb data structure.
1889 *
1890 * This routine is the completion callback function for a Process Login
1891 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1892 * status. If there is error status reported, PRLI retry shall be attempted
1893 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1894 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1895 * ndlp to mark the PRLI completion.
1896 **/
dea31012005-04-17 16:05:31 -05001897static void
James Smart2e0fef82007-06-17 19:56:36 -05001898lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1899 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001900{
James Smart2e0fef82007-06-17 19:56:36 -05001901 struct lpfc_vport *vport = cmdiocb->vport;
1902 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001903 IOCB_t *irsp;
1904 struct lpfc_sli *psli;
1905 struct lpfc_nodelist *ndlp;
1906
1907 psli = &phba->sli;
1908 /* we pass cmdiocb to state machine which needs rspiocb as well */
1909 cmdiocb->context_un.rsp_iocb = rspiocb;
1910
1911 irsp = &(rspiocb->iocb);
1912 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001913 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001914 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001915 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001916
James Smart858c9f62007-06-17 19:56:39 -05001917 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1918 "PRLI cmpl: status:x%x/x%x did:x%x",
1919 irsp->ulpStatus, irsp->un.ulpWord[4],
1920 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001921 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001922 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1923 "0103 PRLI completes to NPort x%x "
1924 "Data: x%x x%x x%x x%x\n",
1925 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1926 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001927
James Smart2e0fef82007-06-17 19:56:36 -05001928 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001929 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001930 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001931 goto out;
1932
1933 if (irsp->ulpStatus) {
1934 /* Check for retry */
1935 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1936 /* ELS command is being retried */
1937 goto out;
1938 }
1939 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001940 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1941 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1942 ndlp->nlp_DID, irsp->ulpStatus,
1943 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001944 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001945 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001946 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001947 else
James Smart2e0fef82007-06-17 19:56:36 -05001948 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001949 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001950 } else
dea31012005-04-17 16:05:31 -05001951 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001952 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001953 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001954out:
1955 lpfc_els_free_iocb(phba, cmdiocb);
1956 return;
1957}
1958
James Smarte59058c2008-08-24 21:49:00 -04001959/**
James Smart3621a712009-04-06 18:47:14 -04001960 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001961 * @vport: pointer to a host virtual N_Port data structure.
1962 * @ndlp: pointer to a node-list data structure.
1963 * @retry: number of retries to the command IOCB.
1964 *
1965 * This routine issues a Process Login (PRLI) ELS command for the
1966 * @vport. The PRLI service parameters are set up in the payload of the
1967 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1968 * is put to the IOCB completion callback func field before invoking the
1969 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1970 *
1971 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1972 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1973 * will be stored into the context1 field of the IOCB for the completion
1974 * callback function to the PRLI ELS command.
1975 *
1976 * Return code
1977 * 0 - successfully issued prli iocb command for @vport
1978 * 1 - failed to issue prli iocb command for @vport
1979 **/
dea31012005-04-17 16:05:31 -05001980int
James Smart2e0fef82007-06-17 19:56:36 -05001981lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001982 uint8_t retry)
1983{
James Smart2e0fef82007-06-17 19:56:36 -05001984 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1985 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001986 PRLI *npr;
1987 IOCB_t *icmd;
1988 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001989 uint8_t *pcmd;
1990 uint16_t cmdsize;
1991
James Smart92d7f7b2007-06-17 19:56:38 -05001992 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001993 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1994 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001995 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001996 return 1;
dea31012005-04-17 16:05:31 -05001997
1998 icmd = &elsiocb->iocb;
1999 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2000
2001 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05002002 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05002003 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05002004 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002005
2006 /* For PRLI, remainder of payload is PRLI parameter page */
2007 npr = (PRLI *) pcmd;
2008 /*
2009 * If our firmware version is 3.20 or later,
2010 * set the following bits for FC-TAPE support.
2011 */
2012 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2013 npr->ConfmComplAllowed = 1;
2014 npr->Retry = 1;
2015 npr->TaskRetryIdReq = 1;
2016 }
2017 npr->estabImagePair = 1;
2018 npr->readXferRdyDis = 1;
2019
2020 /* For FCP support */
2021 npr->prliType = PRLI_FCP_TYPE;
2022 npr->initiatorFunc = 1;
2023
James Smart858c9f62007-06-17 19:56:39 -05002024 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2025 "Issue PRLI: did:x%x",
2026 ndlp->nlp_DID, 0, 0);
2027
dea31012005-04-17 16:05:31 -05002028 phba->fc_stat.elsXmitPRLI++;
2029 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05002030 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002031 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002032 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002033 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2034 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002035 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002036 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002037 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002038 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002039 return 1;
dea31012005-04-17 16:05:31 -05002040 }
James Smart2e0fef82007-06-17 19:56:36 -05002041 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002042 return 0;
dea31012005-04-17 16:05:31 -05002043}
2044
James Smarte59058c2008-08-24 21:49:00 -04002045/**
James Smart3621a712009-04-06 18:47:14 -04002046 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002047 * @vport: pointer to a host virtual N_Port data structure.
2048 *
2049 * This routine performs Registration State Change Notification (RSCN)
2050 * discovery for a @vport. If the @vport's node port recovery count is not
2051 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2052 * the nodes that need recovery. If none of the PLOGI were needed through
2053 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2054 * invoked to check and handle possible more RSCN came in during the period
2055 * of processing the current ones.
2056 **/
2057static void
2058lpfc_rscn_disc(struct lpfc_vport *vport)
2059{
2060 lpfc_can_disctmo(vport);
2061
2062 /* RSCN discovery */
2063 /* go thru NPR nodes and issue ELS PLOGIs */
2064 if (vport->fc_npr_cnt)
2065 if (lpfc_els_disc_plogi(vport))
2066 return;
2067
2068 lpfc_end_rscn(vport);
2069}
2070
2071/**
James Smart3621a712009-04-06 18:47:14 -04002072 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002073 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2074 *
2075 * This function is called when the final ADISC is completed during discovery.
2076 * This function handles clearing link attention or issuing reg_vpi depending
2077 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2078 * discovery.
2079 * This function is called with no locks held.
2080 **/
2081static void
2082lpfc_adisc_done(struct lpfc_vport *vport)
2083{
2084 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2085 struct lpfc_hba *phba = vport->phba;
2086
2087 /*
2088 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2089 * and continue discovery.
2090 */
2091 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002092 !(vport->fc_flag & FC_RSCN_MODE) &&
2093 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04002094 lpfc_issue_reg_vpi(phba, vport);
2095 return;
2096 }
2097 /*
2098 * For SLI2, we need to set port_state to READY
2099 * and continue discovery.
2100 */
2101 if (vport->port_state < LPFC_VPORT_READY) {
2102 /* If we get here, there is nothing to ADISC */
2103 if (vport->port_type == LPFC_PHYSICAL_PORT)
2104 lpfc_issue_clear_la(phba, vport);
2105 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2106 vport->num_disc_nodes = 0;
2107 /* go thru NPR list, issue ELS PLOGIs */
2108 if (vport->fc_npr_cnt)
2109 lpfc_els_disc_plogi(vport);
2110 if (!vport->num_disc_nodes) {
2111 spin_lock_irq(shost->host_lock);
2112 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2113 spin_unlock_irq(shost->host_lock);
2114 lpfc_can_disctmo(vport);
2115 lpfc_end_rscn(vport);
2116 }
2117 }
2118 vport->port_state = LPFC_VPORT_READY;
2119 } else
2120 lpfc_rscn_disc(vport);
2121}
2122
2123/**
James Smart3621a712009-04-06 18:47:14 -04002124 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002125 * @vport: pointer to a host virtual N_Port data structure.
2126 *
2127 * This routine determines whether there are more ndlps on a @vport
2128 * node list need to have Address Discover (ADISC) issued. If so, it will
2129 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2130 * remaining nodes which need to have ADISC sent.
2131 **/
James Smart0ff10d42008-01-11 01:52:36 -05002132void
James Smart2e0fef82007-06-17 19:56:36 -05002133lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002134{
2135 int sentadisc;
2136
James Smart2e0fef82007-06-17 19:56:36 -05002137 if (vport->num_disc_nodes)
2138 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002139 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002140 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2141 "0210 Continue discovery with %d ADISCs to go "
2142 "Data: x%x x%x x%x\n",
2143 vport->num_disc_nodes, vport->fc_adisc_cnt,
2144 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002145 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002146 if (vport->fc_flag & FC_NLP_MORE) {
2147 lpfc_set_disctmo(vport);
2148 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2149 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002150 }
James Smart90160e02008-08-24 21:49:45 -04002151 if (!vport->num_disc_nodes)
2152 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002153 return;
2154}
2155
James Smarte59058c2008-08-24 21:49:00 -04002156/**
James Smart3621a712009-04-06 18:47:14 -04002157 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002158 * @phba: pointer to lpfc hba data structure.
2159 * @cmdiocb: pointer to lpfc command iocb data structure.
2160 * @rspiocb: pointer to lpfc response iocb data structure.
2161 *
2162 * This routine is the completion function for issuing the Address Discover
2163 * (ADISC) command. It first checks to see whether link went down during
2164 * the discovery process. If so, the node will be marked as node port
2165 * recovery for issuing discover IOCB by the link attention handler and
2166 * exit. Otherwise, the response status is checked. If error was reported
2167 * in the response status, the ADISC command shall be retried by invoking
2168 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2169 * the response status, the state machine is invoked to set transition
2170 * with respect to NLP_EVT_CMPL_ADISC event.
2171 **/
dea31012005-04-17 16:05:31 -05002172static void
James Smart2e0fef82007-06-17 19:56:36 -05002173lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2174 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002175{
James Smart2e0fef82007-06-17 19:56:36 -05002176 struct lpfc_vport *vport = cmdiocb->vport;
2177 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002178 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002179 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002180 int disc;
dea31012005-04-17 16:05:31 -05002181
2182 /* we pass cmdiocb to state machine which needs rspiocb as well */
2183 cmdiocb->context_un.rsp_iocb = rspiocb;
2184
2185 irsp = &(rspiocb->iocb);
2186 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002187
James Smart858c9f62007-06-17 19:56:39 -05002188 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2189 "ADISC cmpl: status:x%x/x%x did:x%x",
2190 irsp->ulpStatus, irsp->un.ulpWord[4],
2191 ndlp->nlp_DID);
2192
dea31012005-04-17 16:05:31 -05002193 /* Since ndlp can be freed in the disc state machine, note if this node
2194 * is being used during discovery.
2195 */
James Smart2e0fef82007-06-17 19:56:36 -05002196 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002197 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002198 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002199 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002200 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002201 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2202 "0104 ADISC completes to NPort x%x "
2203 "Data: x%x x%x x%x x%x x%x\n",
2204 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2205 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002206 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002207 if (lpfc_els_chk_latt(vport)) {
2208 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002209 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002210 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002211 goto out;
2212 }
2213
2214 if (irsp->ulpStatus) {
2215 /* Check for retry */
2216 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2217 /* ELS command is being retried */
2218 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002219 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002220 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002221 spin_unlock_irq(shost->host_lock);
2222 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002223 }
2224 goto out;
2225 }
2226 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002227 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2228 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2229 ndlp->nlp_DID, irsp->ulpStatus,
2230 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002231 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002232 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002233 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002234 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002235 } else
dea31012005-04-17 16:05:31 -05002236 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002237 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002238 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002239
James Smart90160e02008-08-24 21:49:45 -04002240 /* Check to see if there are more ADISCs to be sent */
2241 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002242 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002243out:
2244 lpfc_els_free_iocb(phba, cmdiocb);
2245 return;
2246}
2247
James Smarte59058c2008-08-24 21:49:00 -04002248/**
James Smart3621a712009-04-06 18:47:14 -04002249 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002250 * @vport: pointer to a virtual N_Port data structure.
2251 * @ndlp: pointer to a node-list data structure.
2252 * @retry: number of retries to the command IOCB.
2253 *
2254 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2255 * @vport. It prepares the payload of the ADISC ELS command, updates the
2256 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2257 * to issue the ADISC ELS command.
2258 *
2259 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2260 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2261 * will be stored into the context1 field of the IOCB for the completion
2262 * callback function to the ADISC ELS command.
2263 *
2264 * Return code
2265 * 0 - successfully issued adisc
2266 * 1 - failed to issue adisc
2267 **/
dea31012005-04-17 16:05:31 -05002268int
James Smart2e0fef82007-06-17 19:56:36 -05002269lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002270 uint8_t retry)
2271{
James Smart2e0fef82007-06-17 19:56:36 -05002272 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2273 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002274 ADISC *ap;
2275 IOCB_t *icmd;
2276 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002277 uint8_t *pcmd;
2278 uint16_t cmdsize;
2279
James Smart92d7f7b2007-06-17 19:56:38 -05002280 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002281 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2282 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002283 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002284 return 1;
dea31012005-04-17 16:05:31 -05002285
2286 icmd = &elsiocb->iocb;
2287 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2288
2289 /* For ADISC request, remainder of payload is service parameters */
2290 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002291 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002292
2293 /* Fill in ADISC payload */
2294 ap = (ADISC *) pcmd;
2295 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002296 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2297 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002298 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002299
James Smart858c9f62007-06-17 19:56:39 -05002300 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2301 "Issue ADISC: did:x%x",
2302 ndlp->nlp_DID, 0, 0);
2303
dea31012005-04-17 16:05:31 -05002304 phba->fc_stat.elsXmitADISC++;
2305 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002306 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002307 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002308 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002309 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2310 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002311 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002312 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002313 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002314 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002315 return 1;
dea31012005-04-17 16:05:31 -05002316 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002317 return 0;
dea31012005-04-17 16:05:31 -05002318}
2319
James Smarte59058c2008-08-24 21:49:00 -04002320/**
James Smart3621a712009-04-06 18:47:14 -04002321 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002322 * @phba: pointer to lpfc hba data structure.
2323 * @cmdiocb: pointer to lpfc command iocb data structure.
2324 * @rspiocb: pointer to lpfc response iocb data structure.
2325 *
2326 * This routine is the completion function for issuing the ELS Logout (LOGO)
2327 * command. If no error status was reported from the LOGO response, the
2328 * state machine of the associated ndlp shall be invoked for transition with
2329 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2330 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2331 **/
dea31012005-04-17 16:05:31 -05002332static void
James Smart2e0fef82007-06-17 19:56:36 -05002333lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2334 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002335{
James Smart2e0fef82007-06-17 19:56:36 -05002336 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2337 struct lpfc_vport *vport = ndlp->vport;
2338 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002339 IOCB_t *irsp;
2340 struct lpfc_sli *psli;
James Smart92494142011-02-16 12:39:44 -05002341 struct lpfcMboxq *mbox;
dea31012005-04-17 16:05:31 -05002342
2343 psli = &phba->sli;
2344 /* we pass cmdiocb to state machine which needs rspiocb as well */
2345 cmdiocb->context_un.rsp_iocb = rspiocb;
2346
2347 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002348 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002349 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002350 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002351
James Smart858c9f62007-06-17 19:56:39 -05002352 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2353 "LOGO cmpl: status:x%x/x%x did:x%x",
2354 irsp->ulpStatus, irsp->un.ulpWord[4],
2355 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002356 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002357 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2358 "0105 LOGO completes to NPort x%x "
2359 "Data: x%x x%x x%x x%x\n",
2360 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2361 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002362 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002363 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002364 goto out;
2365
James Smart92d7f7b2007-06-17 19:56:38 -05002366 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2367 /* NLP_EVT_DEVICE_RM should unregister the RPI
2368 * which should abort all outstanding IOs.
2369 */
2370 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2371 NLP_EVT_DEVICE_RM);
2372 goto out;
2373 }
2374
dea31012005-04-17 16:05:31 -05002375 if (irsp->ulpStatus) {
2376 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002377 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002378 /* ELS command is being retried */
2379 goto out;
dea31012005-04-17 16:05:31 -05002380 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002381 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2382 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2383 ndlp->nlp_DID, irsp->ulpStatus,
2384 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002385 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002386 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002387 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002388 else
James Smart2e0fef82007-06-17 19:56:36 -05002389 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002390 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002391 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002392 /* Good status, call state machine.
2393 * This will unregister the rpi if needed.
2394 */
James Smart2e0fef82007-06-17 19:56:36 -05002395 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002396 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002397out:
2398 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002399 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2400 if ((vport->fc_flag & FC_PT2PT) &&
2401 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2402 phba->pport->fc_myDID = 0;
2403 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2404 if (mbox) {
2405 lpfc_config_link(phba, mbox);
2406 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2407 mbox->vport = vport;
2408 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2409 MBX_NOT_FINISHED) {
2410 mempool_free(mbox, phba->mbox_mem_pool);
2411 }
2412 }
2413 }
dea31012005-04-17 16:05:31 -05002414 return;
2415}
2416
James Smarte59058c2008-08-24 21:49:00 -04002417/**
James Smart3621a712009-04-06 18:47:14 -04002418 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002419 * @vport: pointer to a virtual N_Port data structure.
2420 * @ndlp: pointer to a node-list data structure.
2421 * @retry: number of retries to the command IOCB.
2422 *
2423 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2424 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2425 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2426 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2427 *
2428 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2429 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2430 * will be stored into the context1 field of the IOCB for the completion
2431 * callback function to the LOGO ELS command.
2432 *
2433 * Return code
2434 * 0 - successfully issued logo
2435 * 1 - failed to issue logo
2436 **/
dea31012005-04-17 16:05:31 -05002437int
James Smart2e0fef82007-06-17 19:56:36 -05002438lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002439 uint8_t retry)
2440{
James Smart2e0fef82007-06-17 19:56:36 -05002441 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2442 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002443 IOCB_t *icmd;
2444 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002445 uint8_t *pcmd;
2446 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002447 int rc;
dea31012005-04-17 16:05:31 -05002448
James Smart98c9ea52007-10-27 13:37:33 -04002449 spin_lock_irq(shost->host_lock);
2450 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2451 spin_unlock_irq(shost->host_lock);
2452 return 0;
2453 }
2454 spin_unlock_irq(shost->host_lock);
2455
James Smart92d7f7b2007-06-17 19:56:38 -05002456 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002457 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2458 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002459 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002460 return 1;
dea31012005-04-17 16:05:31 -05002461
2462 icmd = &elsiocb->iocb;
2463 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2464 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002465 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002466
2467 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002468 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002469 pcmd += sizeof(uint32_t);
2470 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002471
James Smart858c9f62007-06-17 19:56:39 -05002472 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2473 "Issue LOGO: did:x%x",
2474 ndlp->nlp_DID, 0, 0);
2475
dea31012005-04-17 16:05:31 -05002476 phba->fc_stat.elsXmitLOGO++;
2477 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002478 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002479 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002480 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002481 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002482
2483 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002484 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002485 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002486 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002487 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002488 return 1;
dea31012005-04-17 16:05:31 -05002489 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002490 return 0;
dea31012005-04-17 16:05:31 -05002491}
2492
James Smarte59058c2008-08-24 21:49:00 -04002493/**
James Smart3621a712009-04-06 18:47:14 -04002494 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002495 * @phba: pointer to lpfc hba data structure.
2496 * @cmdiocb: pointer to lpfc command iocb data structure.
2497 * @rspiocb: pointer to lpfc response iocb data structure.
2498 *
2499 * This routine is a generic completion callback function for ELS commands.
2500 * Specifically, it is the callback function which does not need to perform
2501 * any command specific operations. It is currently used by the ELS command
2502 * issuing routines for the ELS State Change Request (SCR),
2503 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2504 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2505 * certain debug loggings, this callback function simply invokes the
2506 * lpfc_els_chk_latt() routine to check whether link went down during the
2507 * discovery process.
2508 **/
dea31012005-04-17 16:05:31 -05002509static void
James Smart2e0fef82007-06-17 19:56:36 -05002510lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2511 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002512{
James Smart2e0fef82007-06-17 19:56:36 -05002513 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002514 IOCB_t *irsp;
2515
2516 irsp = &rspiocb->iocb;
2517
James Smart858c9f62007-06-17 19:56:39 -05002518 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2519 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2520 irsp->ulpStatus, irsp->un.ulpWord[4],
2521 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002522 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002523 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2524 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2525 irsp->ulpIoTag, irsp->ulpStatus,
2526 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002527 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002528 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002529 lpfc_els_free_iocb(phba, cmdiocb);
2530 return;
2531}
2532
James Smarte59058c2008-08-24 21:49:00 -04002533/**
James Smart3621a712009-04-06 18:47:14 -04002534 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002535 * @vport: pointer to a host virtual N_Port data structure.
2536 * @nportid: N_Port identifier to the remote node.
2537 * @retry: number of retries to the command IOCB.
2538 *
2539 * This routine issues a State Change Request (SCR) to a fabric node
2540 * on a @vport. The remote node @nportid is passed into the function. It
2541 * first search the @vport node list to find the matching ndlp. If no such
2542 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2543 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2544 * routine is invoked to send the SCR IOCB.
2545 *
2546 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2547 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2548 * will be stored into the context1 field of the IOCB for the completion
2549 * callback function to the SCR ELS command.
2550 *
2551 * Return code
2552 * 0 - Successfully issued scr command
2553 * 1 - Failed to issue scr command
2554 **/
dea31012005-04-17 16:05:31 -05002555int
James Smart2e0fef82007-06-17 19:56:36 -05002556lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002557{
James Smart2e0fef82007-06-17 19:56:36 -05002558 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002559 IOCB_t *icmd;
2560 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002561 struct lpfc_sli *psli;
2562 uint8_t *pcmd;
2563 uint16_t cmdsize;
2564 struct lpfc_nodelist *ndlp;
2565
2566 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002567 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002568
James Smarte47c9092008-02-08 18:49:26 -05002569 ndlp = lpfc_findnode_did(vport, nportid);
2570 if (!ndlp) {
2571 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2572 if (!ndlp)
2573 return 1;
2574 lpfc_nlp_init(vport, ndlp, nportid);
2575 lpfc_enqueue_node(vport, ndlp);
2576 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2577 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2578 if (!ndlp)
2579 return 1;
2580 }
dea31012005-04-17 16:05:31 -05002581
James Smart2e0fef82007-06-17 19:56:36 -05002582 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2583 ndlp->nlp_DID, ELS_CMD_SCR);
2584
James Smart488d1462006-03-07 15:02:37 -05002585 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002586 /* This will trigger the release of the node just
2587 * allocated
2588 */
James Smart329f9bc2007-04-25 09:53:01 -04002589 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002590 return 1;
dea31012005-04-17 16:05:31 -05002591 }
2592
2593 icmd = &elsiocb->iocb;
2594 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2595
2596 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002597 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002598
2599 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002600 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002601 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2602
James Smart858c9f62007-06-17 19:56:39 -05002603 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2604 "Issue SCR: did:x%x",
2605 ndlp->nlp_DID, 0, 0);
2606
dea31012005-04-17 16:05:31 -05002607 phba->fc_stat.elsXmitSCR++;
2608 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002609 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2610 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002611 /* The additional lpfc_nlp_put will cause the following
2612 * lpfc_els_free_iocb routine to trigger the rlease of
2613 * the node.
2614 */
James Smart329f9bc2007-04-25 09:53:01 -04002615 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002616 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002617 return 1;
dea31012005-04-17 16:05:31 -05002618 }
James Smartfa4066b2008-01-11 01:53:27 -05002619 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2620 * trigger the release of node.
2621 */
James Smart329f9bc2007-04-25 09:53:01 -04002622 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002623 return 0;
dea31012005-04-17 16:05:31 -05002624}
2625
James Smarte59058c2008-08-24 21:49:00 -04002626/**
James Smart3621a712009-04-06 18:47:14 -04002627 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002628 * @vport: pointer to a host virtual N_Port data structure.
2629 * @nportid: N_Port identifier to the remote node.
2630 * @retry: number of retries to the command IOCB.
2631 *
2632 * This routine issues a Fibre Channel Address Resolution Response
2633 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2634 * is passed into the function. It first search the @vport node list to find
2635 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2636 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2637 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2638 *
2639 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2640 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2641 * will be stored into the context1 field of the IOCB for the completion
2642 * callback function to the PARPR ELS command.
2643 *
2644 * Return code
2645 * 0 - Successfully issued farpr command
2646 * 1 - Failed to issue farpr command
2647 **/
dea31012005-04-17 16:05:31 -05002648static int
James Smart2e0fef82007-06-17 19:56:36 -05002649lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002650{
James Smart2e0fef82007-06-17 19:56:36 -05002651 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002652 IOCB_t *icmd;
2653 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002654 struct lpfc_sli *psli;
2655 FARP *fp;
2656 uint8_t *pcmd;
2657 uint32_t *lp;
2658 uint16_t cmdsize;
2659 struct lpfc_nodelist *ondlp;
2660 struct lpfc_nodelist *ndlp;
2661
2662 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002663 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002664
James Smarte47c9092008-02-08 18:49:26 -05002665 ndlp = lpfc_findnode_did(vport, nportid);
2666 if (!ndlp) {
2667 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2668 if (!ndlp)
2669 return 1;
2670 lpfc_nlp_init(vport, ndlp, nportid);
2671 lpfc_enqueue_node(vport, ndlp);
2672 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2673 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2674 if (!ndlp)
2675 return 1;
2676 }
James Smart2e0fef82007-06-17 19:56:36 -05002677
2678 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2679 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002680 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002681 /* This will trigger the release of the node just
2682 * allocated
2683 */
James Smart329f9bc2007-04-25 09:53:01 -04002684 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002685 return 1;
dea31012005-04-17 16:05:31 -05002686 }
2687
2688 icmd = &elsiocb->iocb;
2689 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2690
2691 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002692 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002693
2694 /* Fill in FARPR payload */
2695 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002696 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002697 lp = (uint32_t *) pcmd;
2698 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002699 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002700 fp->Rflags = 0;
2701 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2702
James Smart92d7f7b2007-06-17 19:56:38 -05002703 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2704 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002705 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002706 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002707 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002708 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002709 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002710 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002711 }
2712
James Smart858c9f62007-06-17 19:56:39 -05002713 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2714 "Issue FARPR: did:x%x",
2715 ndlp->nlp_DID, 0, 0);
2716
dea31012005-04-17 16:05:31 -05002717 phba->fc_stat.elsXmitFARPR++;
2718 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002719 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2720 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002721 /* The additional lpfc_nlp_put will cause the following
2722 * lpfc_els_free_iocb routine to trigger the release of
2723 * the node.
2724 */
James Smart329f9bc2007-04-25 09:53:01 -04002725 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002726 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002727 return 1;
dea31012005-04-17 16:05:31 -05002728 }
James Smartfa4066b2008-01-11 01:53:27 -05002729 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2730 * trigger the release of the node.
2731 */
James Smart329f9bc2007-04-25 09:53:01 -04002732 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002733 return 0;
dea31012005-04-17 16:05:31 -05002734}
2735
James Smarte59058c2008-08-24 21:49:00 -04002736/**
James Smart3621a712009-04-06 18:47:14 -04002737 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002738 * @vport: pointer to a host virtual N_Port data structure.
2739 * @nlp: pointer to a node-list data structure.
2740 *
2741 * This routine cancels the timer with a delayed IOCB-command retry for
2742 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2743 * removes the ELS retry event if it presents. In addition, if the
2744 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2745 * commands are sent for the @vport's nodes that require issuing discovery
2746 * ADISC.
2747 **/
dea31012005-04-17 16:05:31 -05002748void
James Smart2e0fef82007-06-17 19:56:36 -05002749lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002750{
James Smart2e0fef82007-06-17 19:56:36 -05002751 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002752 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002753
James Smart0d2b6b82008-06-14 22:52:47 -04002754 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2755 return;
James Smart2e0fef82007-06-17 19:56:36 -05002756 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002757 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002758 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002759 del_timer_sync(&nlp->nlp_delayfunc);
2760 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002761 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002762 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002763 /* Decrement nlp reference count held for the delayed retry */
2764 evtp = &nlp->els_retry_evt;
2765 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2766 }
James Smartfdcebe22006-03-07 15:04:01 -05002767 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002768 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002769 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002770 spin_unlock_irq(shost->host_lock);
2771 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002772 if (vport->port_state < LPFC_VPORT_READY) {
2773 /* Check if there are more ADISCs to be sent */
2774 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002775 } else {
2776 /* Check if there are more PLOGIs to be sent */
2777 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002778 if (vport->num_disc_nodes == 0) {
2779 spin_lock_irq(shost->host_lock);
2780 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2781 spin_unlock_irq(shost->host_lock);
2782 lpfc_can_disctmo(vport);
2783 lpfc_end_rscn(vport);
2784 }
James Smartfdcebe22006-03-07 15:04:01 -05002785 }
2786 }
2787 }
2788 return;
2789}
2790
James Smarte59058c2008-08-24 21:49:00 -04002791/**
James Smart3621a712009-04-06 18:47:14 -04002792 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002793 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2794 *
2795 * This routine is invoked by the ndlp delayed-function timer to check
2796 * whether there is any pending ELS retry event(s) with the node. If not, it
2797 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2798 * adds the delayed events to the HBA work list and invokes the
2799 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2800 * event. Note that lpfc_nlp_get() is called before posting the event to
2801 * the work list to hold reference count of ndlp so that it guarantees the
2802 * reference to ndlp will still be available when the worker thread gets
2803 * to the event associated with the ndlp.
2804 **/
James Smartfdcebe22006-03-07 15:04:01 -05002805void
dea31012005-04-17 16:05:31 -05002806lpfc_els_retry_delay(unsigned long ptr)
2807{
James Smart2e0fef82007-06-17 19:56:36 -05002808 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2809 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002810 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002811 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002812 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002813
James Smart92d7f7b2007-06-17 19:56:38 -05002814 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002815 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002816 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002817 return;
2818 }
2819
James Smartfa4066b2008-01-11 01:53:27 -05002820 /* We need to hold the node by incrementing the reference
2821 * count until the queued work is done
2822 */
2823 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002824 if (evtp->evt_arg1) {
2825 evtp->evt = LPFC_EVT_ELS_RETRY;
2826 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002827 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002828 }
James Smart92d7f7b2007-06-17 19:56:38 -05002829 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002830 return;
2831}
2832
James Smarte59058c2008-08-24 21:49:00 -04002833/**
James Smart3621a712009-04-06 18:47:14 -04002834 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002835 * @ndlp: pointer to a node-list data structure.
2836 *
2837 * This routine is the worker-thread handler for processing the @ndlp delayed
2838 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2839 * the last ELS command from the associated ndlp and invokes the proper ELS
2840 * function according to the delayed ELS command to retry the command.
2841 **/
dea31012005-04-17 16:05:31 -05002842void
2843lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2844{
James Smart2e0fef82007-06-17 19:56:36 -05002845 struct lpfc_vport *vport = ndlp->vport;
2846 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2847 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002848
James Smart2e0fef82007-06-17 19:56:36 -05002849 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002850 did = ndlp->nlp_DID;
2851 cmd = ndlp->nlp_last_elscmd;
2852 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002853
2854 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002855 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002856 return;
2857 }
2858
2859 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002860 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002861 /*
2862 * If a discovery event readded nlp_delayfunc after timer
2863 * firing and before processing the timer, cancel the
2864 * nlp_delayfunc.
2865 */
2866 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002867 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002868 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002869
2870 switch (cmd) {
2871 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002872 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002873 break;
2874 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002875 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002876 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002877 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002878 }
dea31012005-04-17 16:05:31 -05002879 break;
2880 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002881 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002882 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002883 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002884 }
dea31012005-04-17 16:05:31 -05002885 break;
2886 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002887 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002888 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002889 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002890 }
dea31012005-04-17 16:05:31 -05002891 break;
2892 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002893 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002894 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002895 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002896 }
dea31012005-04-17 16:05:31 -05002897 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002898 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05002899 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
2900 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05002901 break;
dea31012005-04-17 16:05:31 -05002902 }
2903 return;
2904}
2905
James Smarte59058c2008-08-24 21:49:00 -04002906/**
James Smart3621a712009-04-06 18:47:14 -04002907 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002908 * @phba: pointer to lpfc hba data structure.
2909 * @cmdiocb: pointer to lpfc command iocb data structure.
2910 * @rspiocb: pointer to lpfc response iocb data structure.
2911 *
2912 * This routine makes a retry decision on an ELS command IOCB, which has
2913 * failed. The following ELS IOCBs use this function for retrying the command
2914 * when previously issued command responsed with error status: FLOGI, PLOGI,
2915 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2916 * returned error status, it makes the decision whether a retry shall be
2917 * issued for the command, and whether a retry shall be made immediately or
2918 * delayed. In the former case, the corresponding ELS command issuing-function
2919 * is called to retry the command. In the later case, the ELS command shall
2920 * be posted to the ndlp delayed event and delayed function timer set to the
2921 * ndlp for the delayed command issusing.
2922 *
2923 * Return code
2924 * 0 - No retry of els command is made
2925 * 1 - Immediate or delayed retry of els command is made
2926 **/
dea31012005-04-17 16:05:31 -05002927static int
James Smart2e0fef82007-06-17 19:56:36 -05002928lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2929 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002930{
James Smart2e0fef82007-06-17 19:56:36 -05002931 struct lpfc_vport *vport = cmdiocb->vport;
2932 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2933 IOCB_t *irsp = &rspiocb->iocb;
2934 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2935 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002936 uint32_t *elscmd;
2937 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002938 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002939 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002940 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002941 uint32_t did;
dea31012005-04-17 16:05:31 -05002942
James Smart488d1462006-03-07 15:02:37 -05002943
dea31012005-04-17 16:05:31 -05002944 /* Note: context2 may be 0 for internal driver abort
2945 * of delays ELS command.
2946 */
2947
2948 if (pcmd && pcmd->virt) {
2949 elscmd = (uint32_t *) (pcmd->virt);
2950 cmd = *elscmd++;
2951 }
2952
James Smarte47c9092008-02-08 18:49:26 -05002953 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002954 did = ndlp->nlp_DID;
2955 else {
2956 /* We should only hit this case for retrying PLOGI */
2957 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002958 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002959 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2960 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002961 return 1;
2962 }
2963
James Smart858c9f62007-06-17 19:56:39 -05002964 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2965 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2966 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2967
dea31012005-04-17 16:05:31 -05002968 switch (irsp->ulpStatus) {
2969 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05002970 break;
James Smart1151e3e2011-02-16 12:39:35 -05002971 case IOSTAT_REMOTE_STOP:
2972 if (phba->sli_rev == LPFC_SLI_REV4) {
2973 /* This IO was aborted by the target, we don't
2974 * know the rxid and because we did not send the
2975 * ABTS we cannot generate and RRQ.
2976 */
2977 lpfc_set_rrq_active(phba, ndlp,
2978 cmdiocb->sli4_xritag, 0, 0);
2979 }
2980 break;
dea31012005-04-17 16:05:31 -05002981 case IOSTAT_LOCAL_REJECT:
2982 switch ((irsp->un.ulpWord[4] & 0xff)) {
2983 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002984 if (cmd == ELS_CMD_FLOGI) {
2985 if (PCI_DEVICE_ID_HORNET ==
2986 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05002987 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05002988 phba->pport->fc_myDID = 0;
2989 phba->alpa_map[0] = 0;
2990 phba->alpa_map[1] = 0;
2991 }
2992 }
James Smart2e0fef82007-06-17 19:56:36 -05002993 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002994 delay = 1000;
dea31012005-04-17 16:05:31 -05002995 retry = 1;
2996 break;
2997
James Smart92d7f7b2007-06-17 19:56:38 -05002998 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002999 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3000 "0124 Retry illegal cmd x%x "
3001 "retry:x%x delay:x%x\n",
3002 cmd, cmdiocb->retry, delay);
3003 retry = 1;
3004 /* All command's retry policy */
3005 maxretry = 8;
3006 if (cmdiocb->retry > 2)
3007 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05003008 break;
3009
dea31012005-04-17 16:05:31 -05003010 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04003011 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05003012 retry = 1;
3013 if (cmdiocb->retry > 100)
3014 delay = 100;
3015 maxretry = 250;
3016 break;
3017
3018 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05003019 delay = 100;
dea31012005-04-17 16:05:31 -05003020 retry = 1;
3021 break;
3022
James Smart858c9f62007-06-17 19:56:39 -05003023 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05003024 case IOERR_INVALID_RPI:
3025 retry = 1;
3026 break;
3027 }
3028 break;
3029
3030 case IOSTAT_NPORT_RJT:
3031 case IOSTAT_FABRIC_RJT:
3032 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3033 retry = 1;
3034 break;
3035 }
3036 break;
3037
3038 case IOSTAT_NPORT_BSY:
3039 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04003040 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05003041 retry = 1;
3042 break;
3043
3044 case IOSTAT_LS_RJT:
3045 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3046 /* Added for Vendor specifc support
3047 * Just keep retrying for these Rsn / Exp codes
3048 */
3049 switch (stat.un.b.lsRjtRsnCode) {
3050 case LSRJT_UNABLE_TPC:
3051 if (stat.un.b.lsRjtRsnCodeExp ==
3052 LSEXP_CMD_IN_PROGRESS) {
3053 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003054 delay = 1000;
dea31012005-04-17 16:05:31 -05003055 maxretry = 48;
3056 }
3057 retry = 1;
3058 break;
3059 }
James Smartffc95492010-06-07 15:23:17 -04003060 if (stat.un.b.lsRjtRsnCodeExp ==
3061 LSEXP_CANT_GIVE_DATA) {
3062 if (cmd == ELS_CMD_PLOGI) {
3063 delay = 1000;
3064 maxretry = 48;
3065 }
3066 retry = 1;
3067 break;
3068 }
dea31012005-04-17 16:05:31 -05003069 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003070 delay = 1000;
dea31012005-04-17 16:05:31 -05003071 maxretry = lpfc_max_els_tries + 1;
3072 retry = 1;
3073 break;
3074 }
James Smart92d7f7b2007-06-17 19:56:38 -05003075 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3076 (cmd == ELS_CMD_FDISC) &&
3077 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003078 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3079 "0125 FDISC Failed (x%x). "
3080 "Fabric out of resources\n",
3081 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003082 lpfc_vport_set_state(vport,
3083 FC_VPORT_NO_FABRIC_RSCS);
3084 }
dea31012005-04-17 16:05:31 -05003085 break;
3086
3087 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003088 if ((cmd == ELS_CMD_PLOGI) ||
3089 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003090 delay = 1000;
dea31012005-04-17 16:05:31 -05003091 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003092 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003093 /* FDISC retry policy */
3094 maxretry = 48;
3095 if (cmdiocb->retry >= 32)
3096 delay = 1000;
dea31012005-04-17 16:05:31 -05003097 }
3098 retry = 1;
3099 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003100
3101 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003102 /* There are some cases where switches return this
3103 * error when they are not ready and should be returning
3104 * Logical Busy. We should delay every time.
3105 */
3106 if (cmd == ELS_CMD_FDISC &&
3107 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3108 maxretry = 3;
3109 delay = 1000;
3110 retry = 1;
3111 break;
3112 }
James Smart92d7f7b2007-06-17 19:56:38 -05003113 case LSRJT_PROTOCOL_ERR:
3114 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3115 (cmd == ELS_CMD_FDISC) &&
3116 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3117 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3118 ) {
James Smarte8b62012007-08-02 11:10:09 -04003119 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003120 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003121 "Fabric Detected Bad WWN\n",
3122 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003123 lpfc_vport_set_state(vport,
3124 FC_VPORT_FABRIC_REJ_WWN);
3125 }
3126 break;
dea31012005-04-17 16:05:31 -05003127 }
3128 break;
3129
3130 case IOSTAT_INTERMED_RSP:
3131 case IOSTAT_BA_RJT:
3132 break;
3133
3134 default:
3135 break;
3136 }
3137
James Smart488d1462006-03-07 15:02:37 -05003138 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003139 retry = 1;
dea31012005-04-17 16:05:31 -05003140
James Smartdf9e1b52011-12-13 13:22:17 -05003141 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05003142 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003143 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003144 /* FLOGI retry policy */
3145 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05003146 /* retry FLOGI forever */
James Smart6669f9b2009-10-02 15:16:45 -04003147 maxretry = 0;
3148 if (cmdiocb->retry >= 100)
3149 delay = 5000;
3150 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003151 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05003152 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3153 /* retry FDISCs every second up to devloss */
3154 retry = 1;
3155 maxretry = vport->cfg_devloss_tmo;
3156 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04003157 }
3158
James Smart6669f9b2009-10-02 15:16:45 -04003159 cmdiocb->retry++;
3160 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003161 phba->fc_stat.elsRetryExceeded++;
3162 retry = 0;
3163 }
3164
James Smarted957682007-06-17 19:56:37 -05003165 if ((vport->load_flag & FC_UNLOADING) != 0)
3166 retry = 0;
3167
dea31012005-04-17 16:05:31 -05003168 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003169 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3170 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3171 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3172 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3173 "2849 Stop retry ELS command "
3174 "x%x to remote NPORT x%x, "
3175 "Data: x%x x%x\n", cmd, did,
3176 cmdiocb->retry, delay);
3177 return 0;
3178 }
3179 }
dea31012005-04-17 16:05:31 -05003180
3181 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003182 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3183 "0107 Retry ELS command x%x to remote "
3184 "NPORT x%x Data: x%x x%x\n",
3185 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003186
James Smart858c9f62007-06-17 19:56:39 -05003187 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3188 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3189 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
3190 /* Don't reset timer for no resources */
3191
dea31012005-04-17 16:05:31 -05003192 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003193 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003194 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003195 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003196 }
3197
3198 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003199 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003200 phba->fc_stat.elsDelayRetry++;
3201 ndlp->nlp_retry = cmdiocb->retry;
3202
James Smart92d7f7b2007-06-17 19:56:38 -05003203 /* delay is specified in milliseconds */
3204 mod_timer(&ndlp->nlp_delayfunc,
3205 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003206 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003207 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003208 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003209
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003210 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003211 if (cmd == ELS_CMD_PRLI)
3212 lpfc_nlp_set_state(vport, ndlp,
3213 NLP_STE_REG_LOGIN_ISSUE);
3214 else
3215 lpfc_nlp_set_state(vport, ndlp,
3216 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003217 ndlp->nlp_last_elscmd = cmd;
3218
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003219 return 1;
dea31012005-04-17 16:05:31 -05003220 }
3221 switch (cmd) {
3222 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003223 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003224 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003225 case ELS_CMD_FDISC:
3226 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3227 return 1;
dea31012005-04-17 16:05:31 -05003228 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003229 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003230 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003231 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003232 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003233 }
James Smart2e0fef82007-06-17 19:56:36 -05003234 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003235 return 1;
dea31012005-04-17 16:05:31 -05003236 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003237 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003238 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3239 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003240 return 1;
dea31012005-04-17 16:05:31 -05003241 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003242 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003243 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3244 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003245 return 1;
dea31012005-04-17 16:05:31 -05003246 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003247 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003248 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3249 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003250 return 1;
dea31012005-04-17 16:05:31 -05003251 }
3252 }
dea31012005-04-17 16:05:31 -05003253 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003254 if (logerr) {
3255 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3256 "0137 No retry ELS command x%x to remote "
3257 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3258 cmd, did, irsp->ulpStatus,
3259 irsp->un.ulpWord[4]);
3260 }
3261 else {
3262 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003263 "0108 No retry ELS command x%x to remote "
3264 "NPORT x%x Retried:%d Error:x%x/%x\n",
3265 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3266 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003267 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003268 return 0;
dea31012005-04-17 16:05:31 -05003269}
3270
James Smarte59058c2008-08-24 21:49:00 -04003271/**
James Smart3621a712009-04-06 18:47:14 -04003272 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003273 * @phba: pointer to lpfc hba data structure.
3274 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3275 *
3276 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3277 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3278 * checks to see whether there is a lpfc DMA buffer associated with the
3279 * response of the command IOCB. If so, it will be released before releasing
3280 * the lpfc DMA buffer associated with the IOCB itself.
3281 *
3282 * Return code
3283 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3284 **/
James Smart09372822008-01-11 01:52:54 -05003285static int
James Smart87af33f2007-10-27 13:37:43 -04003286lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3287{
3288 struct lpfc_dmabuf *buf_ptr;
3289
James Smarte59058c2008-08-24 21:49:00 -04003290 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003291 if (!list_empty(&buf_ptr1->list)) {
3292 list_remove_head(&buf_ptr1->list, buf_ptr,
3293 struct lpfc_dmabuf,
3294 list);
3295 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3296 kfree(buf_ptr);
3297 }
3298 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3299 kfree(buf_ptr1);
3300 return 0;
3301}
3302
James Smarte59058c2008-08-24 21:49:00 -04003303/**
James Smart3621a712009-04-06 18:47:14 -04003304 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003305 * @phba: pointer to lpfc hba data structure.
3306 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3307 *
3308 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3309 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3310 * pool.
3311 *
3312 * Return code
3313 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3314 **/
James Smart09372822008-01-11 01:52:54 -05003315static int
James Smart87af33f2007-10-27 13:37:43 -04003316lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3317{
3318 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3319 kfree(buf_ptr);
3320 return 0;
3321}
3322
James Smarte59058c2008-08-24 21:49:00 -04003323/**
James Smart3621a712009-04-06 18:47:14 -04003324 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003325 * @phba: pointer to lpfc hba data structure.
3326 * @elsiocb: pointer to lpfc els command iocb data structure.
3327 *
3328 * This routine frees a command IOCB and its associated resources. The
3329 * command IOCB data structure contains the reference to various associated
3330 * resources, these fields must be set to NULL if the associated reference
3331 * not present:
3332 * context1 - reference to ndlp
3333 * context2 - reference to cmd
3334 * context2->next - reference to rsp
3335 * context3 - reference to bpl
3336 *
3337 * It first properly decrements the reference count held on ndlp for the
3338 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3339 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3340 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3341 * adds the DMA buffer the @phba data structure for the delayed release.
3342 * If reference to the Buffer Pointer List (BPL) is present, the
3343 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3344 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3345 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3346 *
3347 * Return code
3348 * 0 - Success (currently, always return 0)
3349 **/
James Smart87af33f2007-10-27 13:37:43 -04003350int
James Smart329f9bc2007-04-25 09:53:01 -04003351lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003352{
3353 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003354 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003355
James Smarta8adb832007-10-27 13:37:53 -04003356 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3357 if (ndlp) {
3358 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3359 lpfc_nlp_put(ndlp);
3360
3361 /* If the ndlp is not being used by another discovery
3362 * thread, free it.
3363 */
3364 if (!lpfc_nlp_not_used(ndlp)) {
3365 /* If ndlp is being used by another discovery
3366 * thread, just clear NLP_DEFER_RM
3367 */
3368 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3369 }
3370 }
3371 else
3372 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003373 elsiocb->context1 = NULL;
3374 }
dea31012005-04-17 16:05:31 -05003375 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3376 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003377 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3378 /* Firmware could still be in progress of DMAing
3379 * payload, so don't free data buffer till after
3380 * a hbeat.
3381 */
3382 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3383 buf_ptr = elsiocb->context2;
3384 elsiocb->context2 = NULL;
3385 if (buf_ptr) {
3386 buf_ptr1 = NULL;
3387 spin_lock_irq(&phba->hbalock);
3388 if (!list_empty(&buf_ptr->list)) {
3389 list_remove_head(&buf_ptr->list,
3390 buf_ptr1, struct lpfc_dmabuf,
3391 list);
3392 INIT_LIST_HEAD(&buf_ptr1->list);
3393 list_add_tail(&buf_ptr1->list,
3394 &phba->elsbuf);
3395 phba->elsbuf_cnt++;
3396 }
3397 INIT_LIST_HEAD(&buf_ptr->list);
3398 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3399 phba->elsbuf_cnt++;
3400 spin_unlock_irq(&phba->hbalock);
3401 }
3402 } else {
3403 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3404 lpfc_els_free_data(phba, buf_ptr1);
3405 }
dea31012005-04-17 16:05:31 -05003406 }
3407
3408 if (elsiocb->context3) {
3409 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003410 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003411 }
James Bottomley604a3e32005-10-29 10:28:33 -05003412 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003413 return 0;
3414}
3415
James Smarte59058c2008-08-24 21:49:00 -04003416/**
James Smart3621a712009-04-06 18:47:14 -04003417 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003418 * @phba: pointer to lpfc hba data structure.
3419 * @cmdiocb: pointer to lpfc command iocb data structure.
3420 * @rspiocb: pointer to lpfc response iocb data structure.
3421 *
3422 * This routine is the completion callback function to the Logout (LOGO)
3423 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3424 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3425 * release the ndlp if it has the last reference remaining (reference count
3426 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3427 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3428 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3429 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3430 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3431 * IOCB data structure.
3432 **/
dea31012005-04-17 16:05:31 -05003433static void
James Smart2e0fef82007-06-17 19:56:36 -05003434lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3435 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003436{
James Smart2e0fef82007-06-17 19:56:36 -05003437 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3438 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003439 IOCB_t *irsp;
3440
3441 irsp = &rspiocb->iocb;
3442 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3443 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3444 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003445 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003446 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3447 "0109 ACC to LOGO completes to NPort x%x "
3448 "Data: x%x x%x x%x\n",
3449 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3450 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003451
3452 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3453 /* NPort Recovery mode or node is just allocated */
3454 if (!lpfc_nlp_not_used(ndlp)) {
3455 /* If the ndlp is being used by another discovery
3456 * thread, just unregister the RPI.
3457 */
3458 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003459 } else {
3460 /* Indicate the node has already released, should
3461 * not reference to it from within lpfc_els_free_iocb.
3462 */
3463 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003464 }
dea31012005-04-17 16:05:31 -05003465 }
James Smart73d91e52011-10-10 21:32:10 -04003466
3467 /*
3468 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05003469 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04003470 */
dea31012005-04-17 16:05:31 -05003471 lpfc_els_free_iocb(phba, cmdiocb);
James Smartdf9e1b52011-12-13 13:22:17 -05003472
3473 /*
3474 * Remove the ndlp reference if it's a fabric node that has
3475 * sent us an unsolicted LOGO.
3476 */
3477 if (ndlp->nlp_type & NLP_FABRIC)
3478 lpfc_nlp_put(ndlp);
3479
dea31012005-04-17 16:05:31 -05003480 return;
3481}
3482
James Smarte59058c2008-08-24 21:49:00 -04003483/**
James Smart3621a712009-04-06 18:47:14 -04003484 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003485 * @phba: pointer to lpfc hba data structure.
3486 * @pmb: pointer to the driver internal queue element for mailbox command.
3487 *
3488 * This routine is the completion callback function for unregister default
3489 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3490 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3491 * decrements the ndlp reference count held for this completion callback
3492 * function. After that, it invokes the lpfc_nlp_not_used() to check
3493 * whether there is only one reference left on the ndlp. If so, it will
3494 * perform one more decrement and trigger the release of the ndlp.
3495 **/
James Smart858c9f62007-06-17 19:56:39 -05003496void
3497lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3498{
3499 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3500 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3501
3502 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003503 pmb->context2 = NULL;
3504
James Smart858c9f62007-06-17 19:56:39 -05003505 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3506 kfree(mp);
3507 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003508 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003509 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003510 /* This is the end of the default RPI cleanup logic for this
3511 * ndlp. If no other discovery threads are using this ndlp.
3512 * we should free all resources associated with it.
3513 */
3514 lpfc_nlp_not_used(ndlp);
3515 }
James Smart3772a992009-05-22 14:50:54 -04003516
James Smart858c9f62007-06-17 19:56:39 -05003517 return;
3518}
3519
James Smarte59058c2008-08-24 21:49:00 -04003520/**
James Smart3621a712009-04-06 18:47:14 -04003521 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003522 * @phba: pointer to lpfc hba data structure.
3523 * @cmdiocb: pointer to lpfc command iocb data structure.
3524 * @rspiocb: pointer to lpfc response iocb data structure.
3525 *
3526 * This routine is the completion callback function for ELS Response IOCB
3527 * command. In normal case, this callback function just properly sets the
3528 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3529 * field in the command IOCB is not NULL, the referred mailbox command will
3530 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3531 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3532 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3533 * routine shall be invoked trying to release the ndlp if no other threads
3534 * are currently referring it.
3535 **/
dea31012005-04-17 16:05:31 -05003536static void
James Smart858c9f62007-06-17 19:56:39 -05003537lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003538 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003539{
James Smart2e0fef82007-06-17 19:56:36 -05003540 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3541 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3542 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003543 IOCB_t *irsp;
3544 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003545 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003546 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003547 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003548
James Smart33ccf8d2006-08-17 11:57:58 -04003549 irsp = &rspiocb->iocb;
3550
dea31012005-04-17 16:05:31 -05003551 if (cmdiocb->context_un.mbox)
3552 mbox = cmdiocb->context_un.mbox;
3553
James Smartfa4066b2008-01-11 01:53:27 -05003554 /* First determine if this is a LS_RJT cmpl. Note, this callback
3555 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3556 */
James Smart87af33f2007-10-27 13:37:43 -04003557 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003558 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3559 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003560 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003561 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003562 */
3563 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3564 ls_rjt = 1;
3565 }
3566
dea31012005-04-17 16:05:31 -05003567 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003568 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003569 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003570 mp = (struct lpfc_dmabuf *) mbox->context1;
3571 if (mp) {
3572 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3573 kfree(mp);
3574 }
James Smart329f9bc2007-04-25 09:53:01 -04003575 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003576 }
James Smart58da1ff2008-04-07 10:15:56 -04003577 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3578 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003579 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003580 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003581 /* Indicate the node has already released,
3582 * should not reference to it from within
3583 * the routine lpfc_els_free_iocb.
3584 */
3585 cmdiocb->context1 = NULL;
3586 }
dea31012005-04-17 16:05:31 -05003587 goto out;
3588 }
3589
James Smart858c9f62007-06-17 19:56:39 -05003590 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003591 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003592 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003593 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003594 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003595 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3596 "0110 ELS response tag x%x completes "
3597 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3598 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3599 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3600 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3601 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003602 if (mbox) {
3603 if ((rspiocb->iocb.ulpStatus == 0)
3604 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003605 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003606 /* Increment reference count to ndlp to hold the
3607 * reference to ndlp for the callback function.
3608 */
James Smart329f9bc2007-04-25 09:53:01 -04003609 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003610 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003611 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3612 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3613 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3614 }
3615 else {
3616 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3617 ndlp->nlp_prev_state = ndlp->nlp_state;
3618 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003619 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003620 }
James Smart0b727fe2007-10-27 13:37:25 -04003621 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003622 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003623 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003624 else
3625 /* Decrement the ndlp reference count we
3626 * set for this failed mailbox command.
3627 */
3628 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003629
3630 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3631 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3632 "0138 ELS rsp: Cannot issue reg_login for x%x "
3633 "Data: x%x x%x x%x\n",
3634 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3635 ndlp->nlp_rpi);
3636
James Smartfa4066b2008-01-11 01:53:27 -05003637 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003638 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003639 /* Indicate node has already been released,
3640 * should not reference to it from within
3641 * the routine lpfc_els_free_iocb.
3642 */
3643 cmdiocb->context1 = NULL;
3644 }
dea31012005-04-17 16:05:31 -05003645 } else {
James Smart858c9f62007-06-17 19:56:39 -05003646 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3647 if (!lpfc_error_lost_link(irsp) &&
3648 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003649 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003650 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003651 /* Indicate node has already been
3652 * released, should not reference
3653 * to it from within the routine
3654 * lpfc_els_free_iocb.
3655 */
3656 cmdiocb->context1 = NULL;
3657 }
dea31012005-04-17 16:05:31 -05003658 }
3659 }
James Smart14691152006-12-02 13:34:28 -05003660 mp = (struct lpfc_dmabuf *) mbox->context1;
3661 if (mp) {
3662 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3663 kfree(mp);
3664 }
3665 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003666 }
3667out:
James Smart58da1ff2008-04-07 10:15:56 -04003668 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003669 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003670 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003671 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003672
3673 /* If the node is not being used by another discovery thread,
3674 * and we are sending a reject, we are done with it.
3675 * Release driver reference count here and free associated
3676 * resources.
3677 */
3678 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003679 if (lpfc_nlp_not_used(ndlp))
3680 /* Indicate node has already been released,
3681 * should not reference to it from within
3682 * the routine lpfc_els_free_iocb.
3683 */
3684 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003685 }
James Smart87af33f2007-10-27 13:37:43 -04003686
dea31012005-04-17 16:05:31 -05003687 lpfc_els_free_iocb(phba, cmdiocb);
3688 return;
3689}
3690
James Smarte59058c2008-08-24 21:49:00 -04003691/**
James Smart3621a712009-04-06 18:47:14 -04003692 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003693 * @vport: pointer to a host virtual N_Port data structure.
3694 * @flag: the els command code to be accepted.
3695 * @oldiocb: pointer to the original lpfc command iocb data structure.
3696 * @ndlp: pointer to a node-list data structure.
3697 * @mbox: pointer to the driver internal queue element for mailbox command.
3698 *
3699 * This routine prepares and issues an Accept (ACC) response IOCB
3700 * command. It uses the @flag to properly set up the IOCB field for the
3701 * specific ACC response command to be issued and invokes the
3702 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3703 * @mbox pointer is passed in, it will be put into the context_un.mbox
3704 * field of the IOCB for the completion callback function to issue the
3705 * mailbox command to the HBA later when callback is invoked.
3706 *
3707 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3708 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3709 * will be stored into the context1 field of the IOCB for the completion
3710 * callback function to the corresponding response ELS IOCB command.
3711 *
3712 * Return code
3713 * 0 - Successfully issued acc response
3714 * 1 - Failed to issue acc response
3715 **/
dea31012005-04-17 16:05:31 -05003716int
James Smart2e0fef82007-06-17 19:56:36 -05003717lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3718 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003719 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003720{
James Smart2e0fef82007-06-17 19:56:36 -05003721 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3722 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003723 IOCB_t *icmd;
3724 IOCB_t *oldcmd;
3725 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003726 struct lpfc_sli *psli;
3727 uint8_t *pcmd;
3728 uint16_t cmdsize;
3729 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003730 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003731
3732 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003733 oldcmd = &oldiocb->iocb;
3734
3735 switch (flag) {
3736 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003737 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003738 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3739 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003740 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003741 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003742 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003743 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003744 return 1;
dea31012005-04-17 16:05:31 -05003745 }
James Smart2e0fef82007-06-17 19:56:36 -05003746
dea31012005-04-17 16:05:31 -05003747 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003748 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3749 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003750 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3751 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003752 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003753
3754 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3755 "Issue ACC: did:x%x flg:x%x",
3756 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003757 break;
3758 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003759 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003760 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3761 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003762 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003763 return 1;
James Smart488d1462006-03-07 15:02:37 -05003764
dea31012005-04-17 16:05:31 -05003765 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003766 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3767 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003768 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3769
3770 if (mbox)
3771 elsiocb->context_un.mbox = mbox;
3772
3773 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003774 pcmd += sizeof(uint32_t);
3775 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003776
3777 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3778 "Issue ACC PLOGI: did:x%x flg:x%x",
3779 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003780 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003781 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003782 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003783 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003784 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3785 if (!elsiocb)
3786 return 1;
3787
3788 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003789 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3790 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04003791 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3792
3793 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003794 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003795 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3796 els_pkt_ptr = (ELS_PKT *) pcmd;
3797 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003798
3799 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3800 "Issue ACC PRLO: did:x%x flg:x%x",
3801 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003802 break;
dea31012005-04-17 16:05:31 -05003803 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003804 return 1;
dea31012005-04-17 16:05:31 -05003805 }
dea31012005-04-17 16:05:31 -05003806 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003807 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3808 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
James Smarte6446432012-05-09 21:16:42 -04003809 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
3810 "fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003811 elsiocb->iotag, elsiocb->iocb.ulpContext,
3812 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
James Smarte6446432012-05-09 21:16:42 -04003813 ndlp->nlp_rpi, vport->fc_flag);
dea31012005-04-17 16:05:31 -05003814 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003815 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003816 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003817 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003818 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3819 } else {
James Smart858c9f62007-06-17 19:56:39 -05003820 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003821 }
3822
3823 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003824 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003825 if (rc == IOCB_ERROR) {
3826 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003827 return 1;
dea31012005-04-17 16:05:31 -05003828 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003829 return 0;
dea31012005-04-17 16:05:31 -05003830}
3831
James Smarte59058c2008-08-24 21:49:00 -04003832/**
James Smart3621a712009-04-06 18:47:14 -04003833 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003834 * @vport: pointer to a virtual N_Port data structure.
3835 * @rejectError:
3836 * @oldiocb: pointer to the original lpfc command iocb data structure.
3837 * @ndlp: pointer to a node-list data structure.
3838 * @mbox: pointer to the driver internal queue element for mailbox command.
3839 *
3840 * This routine prepares and issue an Reject (RJT) response IOCB
3841 * command. If a @mbox pointer is passed in, it will be put into the
3842 * context_un.mbox field of the IOCB for the completion callback function
3843 * to issue to the HBA later.
3844 *
3845 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3846 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3847 * will be stored into the context1 field of the IOCB for the completion
3848 * callback function to the reject response ELS IOCB command.
3849 *
3850 * Return code
3851 * 0 - Successfully issued reject response
3852 * 1 - Failed to issue reject response
3853 **/
dea31012005-04-17 16:05:31 -05003854int
James Smart2e0fef82007-06-17 19:56:36 -05003855lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003856 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3857 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003858{
James Smart2e0fef82007-06-17 19:56:36 -05003859 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003860 IOCB_t *icmd;
3861 IOCB_t *oldcmd;
3862 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003863 struct lpfc_sli *psli;
3864 uint8_t *pcmd;
3865 uint16_t cmdsize;
3866 int rc;
3867
3868 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003869 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003870 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3871 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003872 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003873 return 1;
dea31012005-04-17 16:05:31 -05003874
3875 icmd = &elsiocb->iocb;
3876 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003877 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3878 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003879 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3880
3881 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003882 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003883 *((uint32_t *) (pcmd)) = rejectError;
3884
James Smart51ef4c22007-08-02 11:10:31 -04003885 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003886 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003887
dea31012005-04-17 16:05:31 -05003888 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003889 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3890 "0129 Xmit ELS RJT x%x response tag x%x "
3891 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3892 "rpi x%x\n",
3893 rejectError, elsiocb->iotag,
3894 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3895 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003896 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3897 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3898 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3899
dea31012005-04-17 16:05:31 -05003900 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003901 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003902 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003903
dea31012005-04-17 16:05:31 -05003904 if (rc == IOCB_ERROR) {
3905 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003906 return 1;
dea31012005-04-17 16:05:31 -05003907 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003908 return 0;
dea31012005-04-17 16:05:31 -05003909}
3910
James Smarte59058c2008-08-24 21:49:00 -04003911/**
James Smart3621a712009-04-06 18:47:14 -04003912 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003913 * @vport: pointer to a virtual N_Port data structure.
3914 * @oldiocb: pointer to the original lpfc command iocb data structure.
3915 * @ndlp: pointer to a node-list data structure.
3916 *
3917 * This routine prepares and issues an Accept (ACC) response to Address
3918 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3919 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3920 *
3921 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3922 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3923 * will be stored into the context1 field of the IOCB for the completion
3924 * callback function to the ADISC Accept response ELS IOCB command.
3925 *
3926 * Return code
3927 * 0 - Successfully issued acc adisc response
3928 * 1 - Failed to issue adisc acc response
3929 **/
dea31012005-04-17 16:05:31 -05003930int
James Smart2e0fef82007-06-17 19:56:36 -05003931lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3932 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003933{
James Smart2e0fef82007-06-17 19:56:36 -05003934 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003935 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003936 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003937 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003938 uint8_t *pcmd;
3939 uint16_t cmdsize;
3940 int rc;
3941
James Smart92d7f7b2007-06-17 19:56:38 -05003942 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003943 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3944 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003945 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003946 return 1;
dea31012005-04-17 16:05:31 -05003947
dea31012005-04-17 16:05:31 -05003948 icmd = &elsiocb->iocb;
3949 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003950 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3951 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04003952
3953 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003954 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3955 "0130 Xmit ADISC ACC response iotag x%x xri: "
3956 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3957 elsiocb->iotag, elsiocb->iocb.ulpContext,
3958 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3959 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003960 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3961
3962 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003963 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003964
3965 ap = (ADISC *) (pcmd);
3966 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003967 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3968 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003969 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003970
James Smart858c9f62007-06-17 19:56:39 -05003971 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3972 "Issue ACC ADISC: did:x%x flg:x%x",
3973 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3974
dea31012005-04-17 16:05:31 -05003975 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003976 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003977 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003978 if (rc == IOCB_ERROR) {
3979 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003980 return 1;
dea31012005-04-17 16:05:31 -05003981 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003982 return 0;
dea31012005-04-17 16:05:31 -05003983}
3984
James Smarte59058c2008-08-24 21:49:00 -04003985/**
James Smart3621a712009-04-06 18:47:14 -04003986 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003987 * @vport: pointer to a virtual N_Port data structure.
3988 * @oldiocb: pointer to the original lpfc command iocb data structure.
3989 * @ndlp: pointer to a node-list data structure.
3990 *
3991 * This routine prepares and issues an Accept (ACC) response to Process
3992 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3993 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3994 *
3995 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3996 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3997 * will be stored into the context1 field of the IOCB for the completion
3998 * callback function to the PRLI Accept response ELS IOCB command.
3999 *
4000 * Return code
4001 * 0 - Successfully issued acc prli response
4002 * 1 - Failed to issue acc prli response
4003 **/
dea31012005-04-17 16:05:31 -05004004int
James Smart2e0fef82007-06-17 19:56:36 -05004005lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04004006 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004007{
James Smart2e0fef82007-06-17 19:56:36 -05004008 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004009 PRLI *npr;
4010 lpfc_vpd_t *vpd;
4011 IOCB_t *icmd;
4012 IOCB_t *oldcmd;
4013 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004014 struct lpfc_sli *psli;
4015 uint8_t *pcmd;
4016 uint16_t cmdsize;
4017 int rc;
4018
4019 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05004020
James Smart92d7f7b2007-06-17 19:56:38 -05004021 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05004022 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05004023 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004024 if (!elsiocb)
4025 return 1;
dea31012005-04-17 16:05:31 -05004026
dea31012005-04-17 16:05:31 -05004027 icmd = &elsiocb->iocb;
4028 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004029 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4030 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4031
James Smart5b8bd0c2007-04-25 09:52:49 -04004032 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004033 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4034 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4035 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4036 elsiocb->iotag, elsiocb->iocb.ulpContext,
4037 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4038 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004039 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4040
4041 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05004042 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004043
4044 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05004045 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05004046
4047 npr = (PRLI *) pcmd;
4048 vpd = &phba->vpd;
4049 /*
James Smart0d2b6b82008-06-14 22:52:47 -04004050 * If the remote port is a target and our firmware version is 3.20 or
4051 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05004052 */
James Smart0d2b6b82008-06-14 22:52:47 -04004053 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4054 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05004055 npr->ConfmComplAllowed = 1;
4056 npr->Retry = 1;
4057 npr->TaskRetryIdReq = 1;
4058 }
4059
4060 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4061 npr->estabImagePair = 1;
4062 npr->readXferRdyDis = 1;
4063 npr->ConfmComplAllowed = 1;
4064
4065 npr->prliType = PRLI_FCP_TYPE;
4066 npr->initiatorFunc = 1;
4067
James Smart858c9f62007-06-17 19:56:39 -05004068 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4069 "Issue ACC PRLI: did:x%x flg:x%x",
4070 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4071
dea31012005-04-17 16:05:31 -05004072 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004073 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004074
James Smart3772a992009-05-22 14:50:54 -04004075 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004076 if (rc == IOCB_ERROR) {
4077 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004078 return 1;
dea31012005-04-17 16:05:31 -05004079 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004080 return 0;
dea31012005-04-17 16:05:31 -05004081}
4082
James Smarte59058c2008-08-24 21:49:00 -04004083/**
James Smart3621a712009-04-06 18:47:14 -04004084 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004085 * @vport: pointer to a virtual N_Port data structure.
4086 * @format: rnid command format.
4087 * @oldiocb: pointer to the original lpfc command iocb data structure.
4088 * @ndlp: pointer to a node-list data structure.
4089 *
4090 * This routine issues a Request Node Identification Data (RNID) Accept
4091 * (ACC) response. It constructs the RNID ACC response command according to
4092 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4093 * issue the response. Note that this command does not need to hold the ndlp
4094 * reference count for the callback. So, the ndlp reference count taken by
4095 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4096 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4097 * there is no ndlp reference available.
4098 *
4099 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4100 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4101 * will be stored into the context1 field of the IOCB for the completion
4102 * callback function. However, for the RNID Accept Response ELS command,
4103 * this is undone later by this routine after the IOCB is allocated.
4104 *
4105 * Return code
4106 * 0 - Successfully issued acc rnid response
4107 * 1 - Failed to issue acc rnid response
4108 **/
dea31012005-04-17 16:05:31 -05004109static int
James Smart2e0fef82007-06-17 19:56:36 -05004110lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004111 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004112{
James Smart2e0fef82007-06-17 19:56:36 -05004113 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004114 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004115 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004116 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004117 struct lpfc_sli *psli;
4118 uint8_t *pcmd;
4119 uint16_t cmdsize;
4120 int rc;
4121
4122 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004123 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4124 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004125 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004126 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004127
James Smart2e0fef82007-06-17 19:56:36 -05004128 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4129 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004130 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004131 return 1;
dea31012005-04-17 16:05:31 -05004132
dea31012005-04-17 16:05:31 -05004133 icmd = &elsiocb->iocb;
4134 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004135 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4136 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4137
James Smart5b8bd0c2007-04-25 09:52:49 -04004138 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004139 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4140 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4141 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004142 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004143 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004144 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004145
James Smart92d7f7b2007-06-17 19:56:38 -05004146 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004147 rn = (RNID *) (pcmd);
4148 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004149 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4150 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4151 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004152 switch (format) {
4153 case 0:
4154 rn->SpecificLen = 0;
4155 break;
4156 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004157 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004158 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004159 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004160 rn->un.topologyDisc.unitType = RNID_HBA;
4161 rn->un.topologyDisc.physPort = 0;
4162 rn->un.topologyDisc.attachedNodes = 0;
4163 break;
4164 default:
4165 rn->CommonLen = 0;
4166 rn->SpecificLen = 0;
4167 break;
4168 }
4169
James Smart858c9f62007-06-17 19:56:39 -05004170 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4171 "Issue ACC RNID: did:x%x flg:x%x",
4172 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4173
dea31012005-04-17 16:05:31 -05004174 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004175 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004176
James Smart3772a992009-05-22 14:50:54 -04004177 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004178 if (rc == IOCB_ERROR) {
4179 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004180 return 1;
dea31012005-04-17 16:05:31 -05004181 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004182 return 0;
dea31012005-04-17 16:05:31 -05004183}
4184
James Smarte59058c2008-08-24 21:49:00 -04004185/**
James Smart19ca7602010-11-20 23:11:55 -05004186 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4187 * @vport: pointer to a virtual N_Port data structure.
4188 * @iocb: pointer to the lpfc command iocb data structure.
4189 * @ndlp: pointer to a node-list data structure.
4190 *
4191 * Return
4192 **/
4193static void
4194lpfc_els_clear_rrq(struct lpfc_vport *vport,
4195 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4196{
4197 struct lpfc_hba *phba = vport->phba;
4198 uint8_t *pcmd;
4199 struct RRQ *rrq;
4200 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004201 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004202 struct lpfc_node_rrq *prrq;
4203
4204
4205 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4206 pcmd += sizeof(uint32_t);
4207 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004208 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b062011-04-16 11:03:17 -04004209 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004210
4211 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4212 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4213 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004214 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b062011-04-16 11:03:17 -04004215 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004216 rxid,
4217 iocb->iotag, iocb->iocb.ulpContext);
4218
4219 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4220 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4221 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004222 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b062011-04-16 11:03:17 -04004223 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004224 else
4225 xri = rxid;
4226 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004227 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004228 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004229 return;
4230}
4231
4232/**
James Smart12265f62010-10-22 11:05:53 -04004233 * lpfc_els_rsp_echo_acc - Issue echo acc response
4234 * @vport: pointer to a virtual N_Port data structure.
4235 * @data: pointer to echo data to return in the accept.
4236 * @oldiocb: pointer to the original lpfc command iocb data structure.
4237 * @ndlp: pointer to a node-list data structure.
4238 *
4239 * Return code
4240 * 0 - Successfully issued acc echo response
4241 * 1 - Failed to issue acc echo response
4242 **/
4243static int
4244lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4245 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4246{
4247 struct lpfc_hba *phba = vport->phba;
4248 struct lpfc_iocbq *elsiocb;
4249 struct lpfc_sli *psli;
4250 uint8_t *pcmd;
4251 uint16_t cmdsize;
4252 int rc;
4253
4254 psli = &phba->sli;
4255 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4256
James Smartbf086112011-08-21 21:48:13 -04004257 /* The accumulated length can exceed the BPL_SIZE. For
4258 * now, use this as the limit
4259 */
4260 if (cmdsize > LPFC_BPL_SIZE)
4261 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04004262 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4263 ndlp->nlp_DID, ELS_CMD_ACC);
4264 if (!elsiocb)
4265 return 1;
4266
James Smart7851fe22011-07-22 18:36:52 -04004267 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4268 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4269
James Smart12265f62010-10-22 11:05:53 -04004270 /* Xmit ECHO ACC response tag <ulpIoTag> */
4271 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4272 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4273 elsiocb->iotag, elsiocb->iocb.ulpContext);
4274 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4275 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4276 pcmd += sizeof(uint32_t);
4277 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4278
4279 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4280 "Issue ACC ECHO: did:x%x flg:x%x",
4281 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4282
4283 phba->fc_stat.elsXmitACC++;
4284 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04004285
4286 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4287 if (rc == IOCB_ERROR) {
4288 lpfc_els_free_iocb(phba, elsiocb);
4289 return 1;
4290 }
4291 return 0;
4292}
4293
4294/**
James Smart3621a712009-04-06 18:47:14 -04004295 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004296 * @vport: pointer to a host virtual N_Port data structure.
4297 *
4298 * This routine issues Address Discover (ADISC) ELS commands to those
4299 * N_Ports which are in node port recovery state and ADISC has not been issued
4300 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4301 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4302 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4303 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4304 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4305 * IOCBs quit for later pick up. On the other hand, after walking through
4306 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4307 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4308 * no more ADISC need to be sent.
4309 *
4310 * Return code
4311 * The number of N_Ports with adisc issued.
4312 **/
dea31012005-04-17 16:05:31 -05004313int
James Smart2e0fef82007-06-17 19:56:36 -05004314lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004315{
James Smart2e0fef82007-06-17 19:56:36 -05004316 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004317 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004318 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004319
James Smart685f0bf2007-04-25 09:53:08 -04004320 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004321 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004322 if (!NLP_CHK_NODE_ACT(ndlp))
4323 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004324 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4325 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4326 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004327 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004328 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004329 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004330 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004331 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4332 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004333 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004334 vport->num_disc_nodes++;
4335 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004336 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004337 spin_lock_irq(shost->host_lock);
4338 vport->fc_flag |= FC_NLP_MORE;
4339 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004340 break;
dea31012005-04-17 16:05:31 -05004341 }
4342 }
4343 }
4344 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004345 spin_lock_irq(shost->host_lock);
4346 vport->fc_flag &= ~FC_NLP_MORE;
4347 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004348 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004349 return sentadisc;
dea31012005-04-17 16:05:31 -05004350}
4351
James Smarte59058c2008-08-24 21:49:00 -04004352/**
James Smart3621a712009-04-06 18:47:14 -04004353 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004354 * @vport: pointer to a host virtual N_Port data structure.
4355 *
4356 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4357 * which are in node port recovery state, with a @vport. Each time an ELS
4358 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4359 * the per @vport number of discover count (num_disc_nodes) shall be
4360 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4361 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4362 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4363 * later pick up. On the other hand, after walking through all the ndlps with
4364 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4365 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4366 * PLOGI need to be sent.
4367 *
4368 * Return code
4369 * The number of N_Ports with plogi issued.
4370 **/
dea31012005-04-17 16:05:31 -05004371int
James Smart2e0fef82007-06-17 19:56:36 -05004372lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004373{
James Smart2e0fef82007-06-17 19:56:36 -05004374 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004375 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004376 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004377
James Smart2e0fef82007-06-17 19:56:36 -05004378 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4379 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004380 if (!NLP_CHK_NODE_ACT(ndlp))
4381 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004382 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4383 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4384 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4385 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4386 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004387 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4388 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004389 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004390 vport->num_disc_nodes++;
4391 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004392 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004393 spin_lock_irq(shost->host_lock);
4394 vport->fc_flag |= FC_NLP_MORE;
4395 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004396 break;
dea31012005-04-17 16:05:31 -05004397 }
4398 }
4399 }
James Smart87af33f2007-10-27 13:37:43 -04004400 if (sentplogi) {
4401 lpfc_set_disctmo(vport);
4402 }
4403 else {
James Smart2e0fef82007-06-17 19:56:36 -05004404 spin_lock_irq(shost->host_lock);
4405 vport->fc_flag &= ~FC_NLP_MORE;
4406 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004407 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004408 return sentplogi;
dea31012005-04-17 16:05:31 -05004409}
4410
James Smarte59058c2008-08-24 21:49:00 -04004411/**
James Smart3621a712009-04-06 18:47:14 -04004412 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004413 * @vport: pointer to a host virtual N_Port data structure.
4414 *
4415 * This routine cleans up any Registration State Change Notification
4416 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4417 * @vport together with the host_lock is used to prevent multiple thread
4418 * trying to access the RSCN array on a same @vport at the same time.
4419 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004420void
James Smart2e0fef82007-06-17 19:56:36 -05004421lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004422{
James Smart2e0fef82007-06-17 19:56:36 -05004423 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4424 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004425 int i;
4426
James Smart7f5f3d02008-02-08 18:50:14 -05004427 spin_lock_irq(shost->host_lock);
4428 if (vport->fc_rscn_flush) {
4429 /* Another thread is walking fc_rscn_id_list on this vport */
4430 spin_unlock_irq(shost->host_lock);
4431 return;
4432 }
4433 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4434 vport->fc_rscn_flush = 1;
4435 spin_unlock_irq(shost->host_lock);
4436
James Smart2e0fef82007-06-17 19:56:36 -05004437 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004438 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004439 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004440 }
James Smart2e0fef82007-06-17 19:56:36 -05004441 spin_lock_irq(shost->host_lock);
4442 vport->fc_rscn_id_cnt = 0;
4443 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4444 spin_unlock_irq(shost->host_lock);
4445 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004446 /* Indicate we are done walking this fc_rscn_id_list */
4447 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004448}
4449
James Smarte59058c2008-08-24 21:49:00 -04004450/**
James Smart3621a712009-04-06 18:47:14 -04004451 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004452 * @vport: pointer to a host virtual N_Port data structure.
4453 * @did: remote destination port identifier.
4454 *
4455 * This routine checks whether there is any pending Registration State
4456 * Configuration Notification (RSCN) to a @did on @vport.
4457 *
4458 * Return code
4459 * None zero - The @did matched with a pending rscn
4460 * 0 - not able to match @did with a pending rscn
4461 **/
dea31012005-04-17 16:05:31 -05004462int
James Smart2e0fef82007-06-17 19:56:36 -05004463lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004464{
4465 D_ID ns_did;
4466 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004467 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004468 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004469 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004470
4471 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004472
4473 /* Never match fabric nodes for RSCNs */
4474 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004475 return 0;
dea31012005-04-17 16:05:31 -05004476
4477 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004478 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004479 return did;
dea31012005-04-17 16:05:31 -05004480
James Smart7f5f3d02008-02-08 18:50:14 -05004481 spin_lock_irq(shost->host_lock);
4482 if (vport->fc_rscn_flush) {
4483 /* Another thread is walking fc_rscn_id_list on this vport */
4484 spin_unlock_irq(shost->host_lock);
4485 return 0;
4486 }
4487 /* Indicate we are walking fc_rscn_id_list on this vport */
4488 vport->fc_rscn_flush = 1;
4489 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004490 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004491 lp = vport->fc_rscn_id_list[i]->virt;
4492 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4493 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004494 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004495 rscn_did.un.word = be32_to_cpu(*lp++);
4496 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004497 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4498 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004499 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4500 && (ns_did.un.b.area == rscn_did.un.b.area)
4501 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004502 goto return_did_out;
dea31012005-04-17 16:05:31 -05004503 break;
James Smarteaf15d52008-12-04 22:39:29 -05004504 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004505 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4506 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004507 goto return_did_out;
dea31012005-04-17 16:05:31 -05004508 break;
James Smarteaf15d52008-12-04 22:39:29 -05004509 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004510 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004511 goto return_did_out;
dea31012005-04-17 16:05:31 -05004512 break;
James Smarteaf15d52008-12-04 22:39:29 -05004513 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004514 goto return_did_out;
dea31012005-04-17 16:05:31 -05004515 }
4516 }
James Smart92d7f7b2007-06-17 19:56:38 -05004517 }
James Smart7f5f3d02008-02-08 18:50:14 -05004518 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4519 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004520 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004521return_did_out:
4522 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4523 vport->fc_rscn_flush = 0;
4524 return did;
dea31012005-04-17 16:05:31 -05004525}
4526
James Smarte59058c2008-08-24 21:49:00 -04004527/**
James Smart3621a712009-04-06 18:47:14 -04004528 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004529 * @vport: pointer to a host virtual N_Port data structure.
4530 *
4531 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4532 * state machine for a @vport's nodes that are with pending RSCN (Registration
4533 * State Change Notification).
4534 *
4535 * Return code
4536 * 0 - Successful (currently alway return 0)
4537 **/
dea31012005-04-17 16:05:31 -05004538static int
James Smart2e0fef82007-06-17 19:56:36 -05004539lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004540{
James Smart685f0bf2007-04-25 09:53:08 -04004541 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004542
James Smart0d2b6b82008-06-14 22:52:47 -04004543 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004544 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004545 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004546 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4547 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004548 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004549 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004550 NLP_EVT_DEVICE_RECOVERY);
4551 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004552 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004553 return 0;
dea31012005-04-17 16:05:31 -05004554}
4555
James Smarte59058c2008-08-24 21:49:00 -04004556/**
James Smart3621a712009-04-06 18:47:14 -04004557 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004558 * @vport: pointer to a host virtual N_Port data structure.
4559 * @cmdiocb: pointer to lpfc command iocb data structure.
4560 *
4561 * lpfc_send_rscn_event sends an RSCN netlink event to management
4562 * applications.
4563 */
4564static void
4565lpfc_send_rscn_event(struct lpfc_vport *vport,
4566 struct lpfc_iocbq *cmdiocb)
4567{
4568 struct lpfc_dmabuf *pcmd;
4569 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4570 uint32_t *payload_ptr;
4571 uint32_t payload_len;
4572 struct lpfc_rscn_event_header *rscn_event_data;
4573
4574 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4575 payload_ptr = (uint32_t *) pcmd->virt;
4576 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4577
4578 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4579 payload_len, GFP_KERNEL);
4580 if (!rscn_event_data) {
4581 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4582 "0147 Failed to allocate memory for RSCN event\n");
4583 return;
4584 }
4585 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4586 rscn_event_data->payload_length = payload_len;
4587 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4588 payload_len);
4589
4590 fc_host_post_vendor_event(shost,
4591 fc_get_event_number(),
4592 sizeof(struct lpfc_els_event_header) + payload_len,
4593 (char *)rscn_event_data,
4594 LPFC_NL_VENDOR_ID);
4595
4596 kfree(rscn_event_data);
4597}
4598
4599/**
James Smart3621a712009-04-06 18:47:14 -04004600 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004601 * @vport: pointer to a host virtual N_Port data structure.
4602 * @cmdiocb: pointer to lpfc command iocb data structure.
4603 * @ndlp: pointer to a node-list data structure.
4604 *
4605 * This routine processes an unsolicited RSCN (Registration State Change
4606 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4607 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4608 * discover state machine is about to begin discovery, it just accepts the
4609 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4610 * contains N_Port IDs for other vports on this HBA, it just accepts the
4611 * RSCN and ignore processing it. If the state machine is in the recovery
4612 * state, the fc_rscn_id_list of this @vport is walked and the
4613 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4614 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4615 * routine is invoked to handle the RSCN event.
4616 *
4617 * Return code
4618 * 0 - Just sent the acc response
4619 * 1 - Sent the acc response and waited for name server completion
4620 **/
dea31012005-04-17 16:05:31 -05004621static int
James Smart2e0fef82007-06-17 19:56:36 -05004622lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004623 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004624{
James Smart2e0fef82007-06-17 19:56:36 -05004625 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4626 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004627 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004628 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004629 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004630 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004631 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004632 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004633 int i;
dea31012005-04-17 16:05:31 -05004634
4635 icmd = &cmdiocb->iocb;
4636 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4637 lp = (uint32_t *) pcmd->virt;
4638
James Smart92d7f7b2007-06-17 19:56:38 -05004639 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4640 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004641 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004642 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4643 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004644 vport->fc_flag, payload_len, *lp,
4645 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004646
4647 /* Send an RSCN event to the management application */
4648 lpfc_send_rscn_event(vport, cmdiocb);
4649
James Smartd2873e42006-08-18 17:46:43 -04004650 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004651 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004652 FCH_EVT_RSCN, lp[i]);
4653
dea31012005-04-17 16:05:31 -05004654 /* If we are about to begin discovery, just ACC the RSCN.
4655 * Discovery processing will satisfy it.
4656 */
James Smart2e0fef82007-06-17 19:56:36 -05004657 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004658 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4659 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4660 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4661
James Smart51ef4c22007-08-02 11:10:31 -04004662 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004663 return 0;
dea31012005-04-17 16:05:31 -05004664 }
4665
James Smart92d7f7b2007-06-17 19:56:38 -05004666 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4667 * just ACC and ignore it.
4668 */
4669 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004670 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004671 i = payload_len;
4672 datap = lp;
4673 while (i > 0) {
4674 nportid = *datap++;
4675 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4676 i -= sizeof(uint32_t);
4677 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004678 if (lpfc_find_vport_by_did(phba, nportid))
4679 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004680 }
4681 if (rscn_id == hba_id) {
4682 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004683 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004684 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004685 "Data: x%x x%x x%x x%x\n",
4686 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004687 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004688 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4689 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4690 ndlp->nlp_DID, vport->port_state,
4691 ndlp->nlp_flag);
4692
James Smart92d7f7b2007-06-17 19:56:38 -05004693 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004694 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004695 return 0;
4696 }
4697 }
4698
James Smart7f5f3d02008-02-08 18:50:14 -05004699 spin_lock_irq(shost->host_lock);
4700 if (vport->fc_rscn_flush) {
4701 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004702 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004703 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004704 /* Send back ACC */
4705 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004706 return 0;
4707 }
4708 /* Indicate we are walking fc_rscn_id_list on this vport */
4709 vport->fc_rscn_flush = 1;
4710 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004711 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004712 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004713 /* If we are already processing an RSCN, save the received
4714 * RSCN payload buffer, cmdiocb->context2 to process later.
4715 */
James Smart2e0fef82007-06-17 19:56:36 -05004716 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004717 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4718 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4719 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4720
James Smart09372822008-01-11 01:52:54 -05004721 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004722 vport->fc_flag |= FC_RSCN_DEFERRED;
4723 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004724 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004725 vport->fc_flag |= FC_RSCN_MODE;
4726 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004727 if (rscn_cnt) {
4728 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4729 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4730 }
4731 if ((rscn_cnt) &&
4732 (payload_len + length <= LPFC_BPL_SIZE)) {
4733 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004734 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004735 memcpy(((uint8_t *)cmd) + length, lp,
4736 payload_len);
4737 } else {
4738 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4739 vport->fc_rscn_id_cnt++;
4740 /* If we zero, cmdiocb->context2, the calling
4741 * routine will not try to free it.
4742 */
4743 cmdiocb->context2 = NULL;
4744 }
dea31012005-04-17 16:05:31 -05004745 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004746 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4747 "0235 Deferred RSCN "
4748 "Data: x%x x%x x%x\n",
4749 vport->fc_rscn_id_cnt, vport->fc_flag,
4750 vport->port_state);
dea31012005-04-17 16:05:31 -05004751 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004752 vport->fc_flag |= FC_RSCN_DISCOVERY;
4753 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004754 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004755 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4756 "0234 ReDiscovery RSCN "
4757 "Data: x%x x%x x%x\n",
4758 vport->fc_rscn_id_cnt, vport->fc_flag,
4759 vport->port_state);
dea31012005-04-17 16:05:31 -05004760 }
James Smart7f5f3d02008-02-08 18:50:14 -05004761 /* Indicate we are done walking fc_rscn_id_list on this vport */
4762 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004763 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004764 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004765 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004766 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004767 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004768 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004769 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004770 return 0;
dea31012005-04-17 16:05:31 -05004771 }
James Smart858c9f62007-06-17 19:56:39 -05004772 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4773 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4774 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4775
James Smart2e0fef82007-06-17 19:56:36 -05004776 spin_lock_irq(shost->host_lock);
4777 vport->fc_flag |= FC_RSCN_MODE;
4778 spin_unlock_irq(shost->host_lock);
4779 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004780 /* Indicate we are done walking fc_rscn_id_list on this vport */
4781 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004782 /*
4783 * If we zero, cmdiocb->context2, the calling routine will
4784 * not try to free it.
4785 */
4786 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004787 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004788 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004789 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004790 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004791 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004792 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004793}
4794
James Smarte59058c2008-08-24 21:49:00 -04004795/**
James Smart3621a712009-04-06 18:47:14 -04004796 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004797 * @vport: pointer to a host virtual N_Port data structure.
4798 *
4799 * This routine handles the Registration State Configuration Notification
4800 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4801 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4802 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4803 * NameServer shall be issued. If CT command to the NameServer fails to be
4804 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4805 * RSCN activities with the @vport.
4806 *
4807 * Return code
4808 * 0 - Cleaned up rscn on the @vport
4809 * 1 - Wait for plogi to name server before proceed
4810 **/
dea31012005-04-17 16:05:31 -05004811int
James Smart2e0fef82007-06-17 19:56:36 -05004812lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004813{
4814 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004815 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004816
James Smart92d7f7b2007-06-17 19:56:38 -05004817 /* Ignore RSCN if the port is being torn down. */
4818 if (vport->load_flag & FC_UNLOADING) {
4819 lpfc_els_flush_rscn(vport);
4820 return 0;
4821 }
4822
dea31012005-04-17 16:05:31 -05004823 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004824 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004825
4826 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004827 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4828 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4829 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4830 vport->port_state);
dea31012005-04-17 16:05:31 -05004831
4832 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004833 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004834 vport->num_disc_nodes = 0;
4835
James Smart2e0fef82007-06-17 19:56:36 -05004836 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004837 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4838 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004839 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004840 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004841 /* Wait for NameServer query cmpl before we can
4842 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004843 return 1;
dea31012005-04-17 16:05:31 -05004844 } else {
4845 /* If login to NameServer does not exist, issue one */
4846 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004847 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004848 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004849 /* Wait for NameServer login cmpl before we can
4850 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004851 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004852
James Smarte47c9092008-02-08 18:49:26 -05004853 if (ndlp) {
4854 ndlp = lpfc_enable_node(vport, ndlp,
4855 NLP_STE_PLOGI_ISSUE);
4856 if (!ndlp) {
4857 lpfc_els_flush_rscn(vport);
4858 return 0;
4859 }
4860 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004861 } else {
James Smarte47c9092008-02-08 18:49:26 -05004862 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4863 if (!ndlp) {
4864 lpfc_els_flush_rscn(vport);
4865 return 0;
4866 }
James Smart2e0fef82007-06-17 19:56:36 -05004867 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004868 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004869 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004870 }
James Smarte47c9092008-02-08 18:49:26 -05004871 ndlp->nlp_type |= NLP_FABRIC;
4872 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4873 /* Wait for NameServer login cmpl before we can
4874 * continue
4875 */
4876 return 1;
dea31012005-04-17 16:05:31 -05004877 }
4878
James Smart2e0fef82007-06-17 19:56:36 -05004879 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004880 return 0;
dea31012005-04-17 16:05:31 -05004881}
4882
James Smarte59058c2008-08-24 21:49:00 -04004883/**
James Smart3621a712009-04-06 18:47:14 -04004884 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004885 * @vport: pointer to a host virtual N_Port data structure.
4886 * @cmdiocb: pointer to lpfc command iocb data structure.
4887 * @ndlp: pointer to a node-list data structure.
4888 *
4889 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4890 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4891 * point topology. As an unsolicited FLOGI should not be received in a loop
4892 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4893 * lpfc_check_sparm() routine is invoked to check the parameters in the
4894 * unsolicited FLOGI. If parameters validation failed, the routine
4895 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4896 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4897 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4898 * will initiate PLOGI. The higher lexicographical value party shall has
4899 * higher priority (as the winning port) and will initiate PLOGI and
4900 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4901 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4902 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4903 *
4904 * Return code
4905 * 0 - Successfully processed the unsolicited flogi
4906 * 1 - Failed to process the unsolicited flogi
4907 **/
dea31012005-04-17 16:05:31 -05004908static int
James Smart2e0fef82007-06-17 19:56:36 -05004909lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004910 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004911{
James Smart2e0fef82007-06-17 19:56:36 -05004912 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4913 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004914 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4915 uint32_t *lp = (uint32_t *) pcmd->virt;
4916 IOCB_t *icmd = &cmdiocb->iocb;
4917 struct serv_parm *sp;
4918 LPFC_MBOXQ_t *mbox;
4919 struct ls_rjt stat;
4920 uint32_t cmd, did;
4921 int rc;
4922
4923 cmd = *lp++;
4924 sp = (struct serv_parm *) lp;
4925
4926 /* FLOGI received */
4927
James Smart2e0fef82007-06-17 19:56:36 -05004928 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004929
James Smart76a95d72010-11-20 23:11:48 -05004930 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004931 /* We should never receive a FLOGI in loop mode, ignore it */
4932 did = icmd->un.elsreq64.remoteID;
4933
4934 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4935 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004936 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4937 "0113 An FLOGI ELS command x%x was "
4938 "received from DID x%x in Loop Mode\n",
4939 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004940 return 1;
dea31012005-04-17 16:05:31 -05004941 }
4942
4943 did = Fabric_DID;
4944
James Smart341af102010-01-26 23:07:37 -05004945 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004946 /* For a FLOGI we accept, then if our portname is greater
4947 * then the remote portname we initiate Nport login.
4948 */
4949
James Smart2e0fef82007-06-17 19:56:36 -05004950 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004951 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004952
4953 if (!rc) {
James Smart1b511972011-12-13 13:23:09 -05004954 if (phba->sli_rev < LPFC_SLI_REV4) {
4955 mbox = mempool_alloc(phba->mbox_mem_pool,
4956 GFP_KERNEL);
4957 if (!mbox)
4958 return 1;
4959 lpfc_linkdown(phba);
4960 lpfc_init_link(phba, mbox,
4961 phba->cfg_topology,
4962 phba->cfg_link_speed);
4963 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
4964 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4965 mbox->vport = vport;
4966 rc = lpfc_sli_issue_mbox(phba, mbox,
4967 MBX_NOWAIT);
4968 lpfc_set_loopback_flag(phba);
4969 if (rc == MBX_NOT_FINISHED)
4970 mempool_free(mbox, phba->mbox_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004971 return 1;
James Smart1b511972011-12-13 13:23:09 -05004972 } else {
4973 /* abort the flogi coming back to ourselves
4974 * due to external loopback on the port.
4975 */
4976 lpfc_els_abort_flogi(phba);
4977 return 0;
dea31012005-04-17 16:05:31 -05004978 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004979 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004980 spin_lock_irq(shost->host_lock);
4981 vport->fc_flag |= FC_PT2PT_PLOGI;
4982 spin_unlock_irq(shost->host_lock);
James Smarte6446432012-05-09 21:16:42 -04004983 vport->fc_myDID = PT2PT_LocalID;
4984 } else
4985 vport->fc_myDID = PT2PT_RemoteID;
4986 vport->port_state = LPFC_FLOGI;
James Smart2e0fef82007-06-17 19:56:36 -05004987 spin_lock_irq(shost->host_lock);
4988 vport->fc_flag |= FC_PT2PT;
4989 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4990 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004991 } else {
4992 /* Reject this request because invalid parameters */
4993 stat.un.b.lsRjtRsvd0 = 0;
4994 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4995 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4996 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004997 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4998 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004999 return 1;
dea31012005-04-17 16:05:31 -05005000 }
5001
5002 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04005003 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005004
James Smarte6446432012-05-09 21:16:42 -04005005 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
5006 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5007 if (!mbox)
5008 goto fail;
5009
5010 lpfc_config_link(phba, mbox);
5011
5012 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5013 mbox->vport = vport;
5014 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5015 if (rc == MBX_NOT_FINISHED) {
5016 mempool_free(mbox, phba->mbox_mem_pool);
5017 goto fail;
5018 }
5019 }
5020
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005021 return 0;
James Smarte6446432012-05-09 21:16:42 -04005022fail:
5023 return 1;
dea31012005-04-17 16:05:31 -05005024}
5025
James Smarte59058c2008-08-24 21:49:00 -04005026/**
James Smart3621a712009-04-06 18:47:14 -04005027 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04005028 * @vport: pointer to a host virtual N_Port data structure.
5029 * @cmdiocb: pointer to lpfc command iocb data structure.
5030 * @ndlp: pointer to a node-list data structure.
5031 *
5032 * This routine processes Request Node Identification Data (RNID) IOCB
5033 * received as an ELS unsolicited event. Only when the RNID specified format
5034 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
5035 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
5036 * Accept (ACC) the RNID ELS command. All the other RNID formats are
5037 * rejected by invoking the lpfc_els_rsp_reject() routine.
5038 *
5039 * Return code
5040 * 0 - Successfully processed rnid iocb (currently always return 0)
5041 **/
dea31012005-04-17 16:05:31 -05005042static int
James Smart2e0fef82007-06-17 19:56:36 -05005043lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5044 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005045{
5046 struct lpfc_dmabuf *pcmd;
5047 uint32_t *lp;
5048 IOCB_t *icmd;
5049 RNID *rn;
5050 struct ls_rjt stat;
5051 uint32_t cmd, did;
5052
5053 icmd = &cmdiocb->iocb;
5054 did = icmd->un.elsreq64.remoteID;
5055 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5056 lp = (uint32_t *) pcmd->virt;
5057
5058 cmd = *lp++;
5059 rn = (RNID *) lp;
5060
5061 /* RNID received */
5062
5063 switch (rn->Format) {
5064 case 0:
5065 case RNID_TOPOLOGY_DISC:
5066 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05005067 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005068 break;
5069 default:
5070 /* Reject this request because format not supported */
5071 stat.un.b.lsRjtRsvd0 = 0;
5072 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5073 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5074 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005075 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5076 NULL);
dea31012005-04-17 16:05:31 -05005077 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005078 return 0;
dea31012005-04-17 16:05:31 -05005079}
5080
James Smarte59058c2008-08-24 21:49:00 -04005081/**
James Smart12265f62010-10-22 11:05:53 -04005082 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
5083 * @vport: pointer to a host virtual N_Port data structure.
5084 * @cmdiocb: pointer to lpfc command iocb data structure.
5085 * @ndlp: pointer to a node-list data structure.
5086 *
5087 * Return code
5088 * 0 - Successfully processed echo iocb (currently always return 0)
5089 **/
5090static int
5091lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5092 struct lpfc_nodelist *ndlp)
5093{
5094 uint8_t *pcmd;
5095
5096 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
5097
5098 /* skip over first word of echo command to find echo data */
5099 pcmd += sizeof(uint32_t);
5100
5101 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
5102 return 0;
5103}
5104
5105/**
James Smart3621a712009-04-06 18:47:14 -04005106 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04005107 * @vport: pointer to a host virtual N_Port data structure.
5108 * @cmdiocb: pointer to lpfc command iocb data structure.
5109 * @ndlp: pointer to a node-list data structure.
5110 *
5111 * This routine processes a Link Incident Report Registration(LIRR) IOCB
5112 * received as an ELS unsolicited event. Currently, this function just invokes
5113 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
5114 *
5115 * Return code
5116 * 0 - Successfully processed lirr iocb (currently always return 0)
5117 **/
dea31012005-04-17 16:05:31 -05005118static int
James Smart2e0fef82007-06-17 19:56:36 -05005119lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5120 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005121{
5122 struct ls_rjt stat;
5123
5124 /* For now, unconditionally reject this command */
5125 stat.un.b.lsRjtRsvd0 = 0;
5126 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5127 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5128 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005129 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005130 return 0;
5131}
5132
James Smarte59058c2008-08-24 21:49:00 -04005133/**
James Smart5ffc2662009-11-18 15:39:44 -05005134 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5135 * @vport: pointer to a host virtual N_Port data structure.
5136 * @cmdiocb: pointer to lpfc command iocb data structure.
5137 * @ndlp: pointer to a node-list data structure.
5138 *
5139 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5140 * received as an ELS unsolicited event. A request to RRQ shall only
5141 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5142 * Nx_Port N_Port_ID of the target Exchange is the same as the
5143 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5144 * not accepted, an LS_RJT with reason code "Unable to perform
5145 * command request" and reason code explanation "Invalid Originator
5146 * S_ID" shall be returned. For now, we just unconditionally accept
5147 * RRQ from the target.
5148 **/
5149static void
5150lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5151 struct lpfc_nodelist *ndlp)
5152{
5153 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05005154 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5155 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05005156}
5157
5158/**
James Smart12265f62010-10-22 11:05:53 -04005159 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5160 * @phba: pointer to lpfc hba data structure.
5161 * @pmb: pointer to the driver internal queue element for mailbox command.
5162 *
5163 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5164 * mailbox command. This callback function is to actually send the Accept
5165 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5166 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5167 * mailbox command, constructs the RPS response with the link statistics
5168 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5169 * response to the RPS.
5170 *
5171 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5172 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5173 * will be stored into the context1 field of the IOCB for the completion
5174 * callback function to the RPS Accept Response ELS IOCB command.
5175 *
5176 **/
5177static void
5178lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5179{
5180 MAILBOX_t *mb;
5181 IOCB_t *icmd;
5182 struct RLS_RSP *rls_rsp;
5183 uint8_t *pcmd;
5184 struct lpfc_iocbq *elsiocb;
5185 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005186 uint16_t oxid;
5187 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04005188 uint32_t cmdsize;
5189
5190 mb = &pmb->u.mb;
5191
5192 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005193 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5194 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04005195 pmb->context1 = NULL;
5196 pmb->context2 = NULL;
5197
5198 if (mb->mbxStatus) {
5199 mempool_free(pmb, phba->mbox_mem_pool);
5200 return;
5201 }
5202
5203 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04005204 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5205 lpfc_max_els_tries, ndlp,
5206 ndlp->nlp_DID, ELS_CMD_ACC);
5207
5208 /* Decrement the ndlp reference count from previous mbox command */
5209 lpfc_nlp_put(ndlp);
5210
James Smart37db57e2012-05-09 21:17:16 -04005211 if (!elsiocb) {
5212 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04005213 return;
James Smart37db57e2012-05-09 21:17:16 -04005214 }
James Smart12265f62010-10-22 11:05:53 -04005215
5216 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005217 icmd->ulpContext = rxid;
5218 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04005219
5220 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5221 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5222 pcmd += sizeof(uint32_t); /* Skip past command */
5223 rls_rsp = (struct RLS_RSP *)pcmd;
5224
5225 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5226 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5227 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5228 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5229 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5230 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04005231 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04005232 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5233 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5234 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5235 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5236 elsiocb->iotag, elsiocb->iocb.ulpContext,
5237 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5238 ndlp->nlp_rpi);
5239 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5240 phba->fc_stat.elsXmitACC++;
5241 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5242 lpfc_els_free_iocb(phba, elsiocb);
5243}
5244
5245/**
James Smart3621a712009-04-06 18:47:14 -04005246 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005247 * @phba: pointer to lpfc hba data structure.
5248 * @pmb: pointer to the driver internal queue element for mailbox command.
5249 *
5250 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5251 * mailbox command. This callback function is to actually send the Accept
5252 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5253 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5254 * mailbox command, constructs the RPS response with the link statistics
5255 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5256 * response to the RPS.
5257 *
5258 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5259 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5260 * will be stored into the context1 field of the IOCB for the completion
5261 * callback function to the RPS Accept Response ELS IOCB command.
5262 *
5263 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005264static void
James Smart329f9bc2007-04-25 09:53:01 -04005265lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005266{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005267 MAILBOX_t *mb;
5268 IOCB_t *icmd;
5269 RPS_RSP *rps_rsp;
5270 uint8_t *pcmd;
5271 struct lpfc_iocbq *elsiocb;
5272 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005273 uint16_t status;
5274 uint16_t oxid;
5275 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005276 uint32_t cmdsize;
5277
James Smart04c68492009-05-22 14:52:52 -04005278 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005279
5280 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005281 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5282 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07005283 pmb->context1 = NULL;
5284 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005285
5286 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005287 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005288 return;
5289 }
5290
5291 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005292 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005293 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5294 lpfc_max_els_tries, ndlp,
5295 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005296
5297 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005298 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005299
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005300 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005301 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005302
5303 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005304 icmd->ulpContext = rxid;
5305 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005306
5307 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5308 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005309 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005310 rps_rsp = (RPS_RSP *)pcmd;
5311
James Smart76a95d72010-11-20 23:11:48 -05005312 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005313 status = 0x10;
5314 else
5315 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005316 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005317 status |= 0x4;
5318
5319 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005320 rps_rsp->portStatus = cpu_to_be16(status);
5321 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5322 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5323 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5324 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5325 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5326 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005327 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005328 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5329 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5330 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5331 elsiocb->iotag, elsiocb->iocb.ulpContext,
5332 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5333 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005334 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005335 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005336 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005337 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005338 return;
5339}
5340
James Smarte59058c2008-08-24 21:49:00 -04005341/**
James Smart12265f62010-10-22 11:05:53 -04005342 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5343 * @vport: pointer to a host virtual N_Port data structure.
5344 * @cmdiocb: pointer to lpfc command iocb data structure.
5345 * @ndlp: pointer to a node-list data structure.
5346 *
5347 * This routine processes Read Port Status (RPL) IOCB received as an
5348 * ELS unsolicited event. It first checks the remote port state. If the
5349 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5350 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5351 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5352 * for reading the HBA link statistics. It is for the callback function,
5353 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5354 * to actually sending out RPL Accept (ACC) response.
5355 *
5356 * Return codes
5357 * 0 - Successfully processed rls iocb (currently always return 0)
5358 **/
5359static int
5360lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5361 struct lpfc_nodelist *ndlp)
5362{
5363 struct lpfc_hba *phba = vport->phba;
5364 LPFC_MBOXQ_t *mbox;
5365 struct lpfc_dmabuf *pcmd;
5366 struct ls_rjt stat;
5367
5368 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5369 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5370 /* reject the unsolicited RPS request and done with it */
5371 goto reject_out;
5372
5373 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5374
5375 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5376 if (mbox) {
5377 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005378 mbox->context1 = (void *)((unsigned long)
5379 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5380 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04005381 mbox->context2 = lpfc_nlp_get(ndlp);
5382 mbox->vport = vport;
5383 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5384 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5385 != MBX_NOT_FINISHED)
5386 /* Mbox completion will send ELS Response */
5387 return 0;
5388 /* Decrement reference count used for the failed mbox
5389 * command.
5390 */
5391 lpfc_nlp_put(ndlp);
5392 mempool_free(mbox, phba->mbox_mem_pool);
5393 }
5394reject_out:
5395 /* issue rejection response */
5396 stat.un.b.lsRjtRsvd0 = 0;
5397 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5398 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5399 stat.un.b.vendorUnique = 0;
5400 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5401 return 0;
5402}
5403
5404/**
5405 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5406 * @vport: pointer to a host virtual N_Port data structure.
5407 * @cmdiocb: pointer to lpfc command iocb data structure.
5408 * @ndlp: pointer to a node-list data structure.
5409 *
5410 * This routine processes Read Timout Value (RTV) IOCB received as an
5411 * ELS unsolicited event. It first checks the remote port state. If the
5412 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5413 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5414 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5415 * Value (RTV) unsolicited IOCB event.
5416 *
5417 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5418 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5419 * will be stored into the context1 field of the IOCB for the completion
5420 * callback function to the RPS Accept Response ELS IOCB command.
5421 *
5422 * Return codes
5423 * 0 - Successfully processed rtv iocb (currently always return 0)
5424 **/
5425static int
5426lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5427 struct lpfc_nodelist *ndlp)
5428{
5429 struct lpfc_hba *phba = vport->phba;
5430 struct ls_rjt stat;
5431 struct RTV_RSP *rtv_rsp;
5432 uint8_t *pcmd;
5433 struct lpfc_iocbq *elsiocb;
5434 uint32_t cmdsize;
5435
5436
5437 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5438 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5439 /* reject the unsolicited RPS request and done with it */
5440 goto reject_out;
5441
5442 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5443 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5444 lpfc_max_els_tries, ndlp,
5445 ndlp->nlp_DID, ELS_CMD_ACC);
5446
5447 if (!elsiocb)
5448 return 1;
5449
5450 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5451 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5452 pcmd += sizeof(uint32_t); /* Skip past command */
5453
5454 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04005455 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
5456 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04005457
5458 rtv_rsp = (struct RTV_RSP *)pcmd;
5459
5460 /* populate RTV payload */
5461 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5462 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5463 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5464 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5465 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5466
5467 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5468 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5469 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5470 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5471 "Data: x%x x%x x%x\n",
5472 elsiocb->iotag, elsiocb->iocb.ulpContext,
5473 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5474 ndlp->nlp_rpi,
5475 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5476 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5477 phba->fc_stat.elsXmitACC++;
5478 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5479 lpfc_els_free_iocb(phba, elsiocb);
5480 return 0;
5481
5482reject_out:
5483 /* issue rejection response */
5484 stat.un.b.lsRjtRsvd0 = 0;
5485 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5486 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5487 stat.un.b.vendorUnique = 0;
5488 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5489 return 0;
5490}
5491
5492/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005493 * @vport: pointer to a host virtual N_Port data structure.
5494 * @cmdiocb: pointer to lpfc command iocb data structure.
5495 * @ndlp: pointer to a node-list data structure.
5496 *
5497 * This routine processes Read Port Status (RPS) IOCB received as an
5498 * ELS unsolicited event. It first checks the remote port state. If the
5499 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5500 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5501 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5502 * for reading the HBA link statistics. It is for the callback function,
5503 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5504 * to actually sending out RPS Accept (ACC) response.
5505 *
5506 * Return codes
5507 * 0 - Successfully processed rps iocb (currently always return 0)
5508 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005509static int
James Smart2e0fef82007-06-17 19:56:36 -05005510lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5511 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005512{
James Smart2e0fef82007-06-17 19:56:36 -05005513 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005514 uint32_t *lp;
5515 uint8_t flag;
5516 LPFC_MBOXQ_t *mbox;
5517 struct lpfc_dmabuf *pcmd;
5518 RPS *rps;
5519 struct ls_rjt stat;
5520
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005521 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005522 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5523 /* reject the unsolicited RPS request and done with it */
5524 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005525
5526 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5527 lp = (uint32_t *) pcmd->virt;
5528 flag = (be32_to_cpu(*lp++) & 0xf);
5529 rps = (RPS *) lp;
5530
5531 if ((flag == 0) ||
5532 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005533 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005534 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005535
James Smart92d7f7b2007-06-17 19:56:38 -05005536 printk("Fix me....\n");
5537 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005538 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5539 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005540 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005541 mbox->context1 = (void *)((unsigned long)
5542 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5543 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04005544 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005545 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005546 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005547 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005548 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005549 /* Mbox completion will send ELS Response */
5550 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005551 /* Decrement reference count used for the failed mbox
5552 * command.
5553 */
James Smart329f9bc2007-04-25 09:53:01 -04005554 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005555 mempool_free(mbox, phba->mbox_mem_pool);
5556 }
5557 }
James Smart90160e02008-08-24 21:49:45 -04005558
5559reject_out:
5560 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005561 stat.un.b.lsRjtRsvd0 = 0;
5562 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5563 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5564 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005565 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005566 return 0;
5567}
5568
James Smart19ca7602010-11-20 23:11:55 -05005569/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5570 * @vport: pointer to a host virtual N_Port data structure.
5571 * @ndlp: pointer to a node-list data structure.
5572 * @did: DID of the target.
5573 * @rrq: Pointer to the rrq struct.
5574 *
5575 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5576 * Successful the the completion handler will clear the RRQ.
5577 *
5578 * Return codes
5579 * 0 - Successfully sent rrq els iocb.
5580 * 1 - Failed to send rrq els iocb.
5581 **/
5582static int
5583lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5584 uint32_t did, struct lpfc_node_rrq *rrq)
5585{
5586 struct lpfc_hba *phba = vport->phba;
5587 struct RRQ *els_rrq;
5588 IOCB_t *icmd;
5589 struct lpfc_iocbq *elsiocb;
5590 uint8_t *pcmd;
5591 uint16_t cmdsize;
5592 int ret;
5593
5594
5595 if (ndlp != rrq->ndlp)
5596 ndlp = rrq->ndlp;
5597 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5598 return 1;
5599
5600 /* If ndlp is not NULL, we will bump the reference count on it */
5601 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5602 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5603 ELS_CMD_RRQ);
5604 if (!elsiocb)
5605 return 1;
5606
5607 icmd = &elsiocb->iocb;
5608 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5609
5610 /* For RRQ request, remainder of payload is Exchange IDs */
5611 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5612 pcmd += sizeof(uint32_t);
5613 els_rrq = (struct RRQ *) pcmd;
5614
5615 bf_set(rrq_oxid, els_rrq, rrq->xritag);
5616 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5617 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5618 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5619 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5620
5621
5622 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5623 "Issue RRQ: did:x%x",
5624 did, rrq->xritag, rrq->rxid);
5625 elsiocb->context_un.rrq = rrq;
5626 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5627 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5628
5629 if (ret == IOCB_ERROR) {
5630 lpfc_els_free_iocb(phba, elsiocb);
5631 return 1;
5632 }
5633 return 0;
5634}
5635
5636/**
5637 * lpfc_send_rrq - Sends ELS RRQ if needed.
5638 * @phba: pointer to lpfc hba data structure.
5639 * @rrq: pointer to the active rrq.
5640 *
5641 * This routine will call the lpfc_issue_els_rrq if the rrq is
5642 * still active for the xri. If this function returns a failure then
5643 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5644 *
5645 * Returns 0 Success.
5646 * 1 Failure.
5647 **/
5648int
5649lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5650{
5651 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5652 rrq->nlp_DID);
5653 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5654 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5655 rrq->nlp_DID, rrq);
5656 else
5657 return 1;
5658}
5659
James Smarte59058c2008-08-24 21:49:00 -04005660/**
James Smart3621a712009-04-06 18:47:14 -04005661 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005662 * @vport: pointer to a host virtual N_Port data structure.
5663 * @cmdsize: size of the ELS command.
5664 * @oldiocb: pointer to the original lpfc command iocb data structure.
5665 * @ndlp: pointer to a node-list data structure.
5666 *
5667 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5668 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5669 *
5670 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5671 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5672 * will be stored into the context1 field of the IOCB for the completion
5673 * callback function to the RPL Accept Response ELS command.
5674 *
5675 * Return code
5676 * 0 - Successfully issued ACC RPL ELS command
5677 * 1 - Failed to issue ACC RPL ELS command
5678 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005679static int
James Smart2e0fef82007-06-17 19:56:36 -05005680lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5681 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005682{
James Smart2e0fef82007-06-17 19:56:36 -05005683 struct lpfc_hba *phba = vport->phba;
5684 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005685 RPL_RSP rpl_rsp;
5686 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005687 uint8_t *pcmd;
5688
James Smart2e0fef82007-06-17 19:56:36 -05005689 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5690 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005691
James Smart488d1462006-03-07 15:02:37 -05005692 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005693 return 1;
James Smart488d1462006-03-07 15:02:37 -05005694
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005695 icmd = &elsiocb->iocb;
5696 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005697 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5698 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005699
5700 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5701 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005702 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005703 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5704 pcmd += sizeof(uint16_t);
5705
5706 /* Setup the RPL ACC payload */
5707 rpl_rsp.listLen = be32_to_cpu(1);
5708 rpl_rsp.index = 0;
5709 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005710 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5711 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005712 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005713 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005714 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005715 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5716 "0120 Xmit ELS RPL ACC response tag x%x "
5717 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5718 "rpi x%x\n",
5719 elsiocb->iotag, elsiocb->iocb.ulpContext,
5720 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5721 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005722 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005723 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005724 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5725 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005726 lpfc_els_free_iocb(phba, elsiocb);
5727 return 1;
5728 }
5729 return 0;
5730}
5731
James Smarte59058c2008-08-24 21:49:00 -04005732/**
James Smart3621a712009-04-06 18:47:14 -04005733 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005734 * @vport: pointer to a host virtual N_Port data structure.
5735 * @cmdiocb: pointer to lpfc command iocb data structure.
5736 * @ndlp: pointer to a node-list data structure.
5737 *
5738 * This routine processes Read Port List (RPL) IOCB received as an ELS
5739 * unsolicited event. It first checks the remote port state. If the remote
5740 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5741 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5742 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5743 * to accept the RPL.
5744 *
5745 * Return code
5746 * 0 - Successfully processed rpl iocb (currently always return 0)
5747 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005748static int
James Smart2e0fef82007-06-17 19:56:36 -05005749lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5750 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005751{
5752 struct lpfc_dmabuf *pcmd;
5753 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005754 uint32_t maxsize;
5755 uint16_t cmdsize;
5756 RPL *rpl;
5757 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005758
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005759 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5760 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005761 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005762 stat.un.b.lsRjtRsvd0 = 0;
5763 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5764 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5765 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005766 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5767 NULL);
James Smart90160e02008-08-24 21:49:45 -04005768 /* rejected the unsolicited RPL request and done with it */
5769 return 0;
dea31012005-04-17 16:05:31 -05005770 }
5771
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005772 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5773 lp = (uint32_t *) pcmd->virt;
5774 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005775 maxsize = be32_to_cpu(rpl->maxsize);
5776
5777 /* We support only one port */
5778 if ((rpl->index == 0) &&
5779 ((maxsize == 0) ||
5780 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5781 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005782 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005783 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5784 }
James Smart2e0fef82007-06-17 19:56:36 -05005785 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005786
5787 return 0;
5788}
5789
James Smarte59058c2008-08-24 21:49:00 -04005790/**
James Smart3621a712009-04-06 18:47:14 -04005791 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005792 * @vport: pointer to a virtual N_Port data structure.
5793 * @cmdiocb: pointer to lpfc command iocb data structure.
5794 * @ndlp: pointer to a node-list data structure.
5795 *
5796 * This routine processes Fibre Channel Address Resolution Protocol
5797 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5798 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5799 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5800 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5801 * remote PortName is compared against the FC PortName stored in the @vport
5802 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5803 * compared against the FC NodeName stored in the @vport data structure.
5804 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5805 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5806 * invoked to send out FARP Response to the remote node. Before sending the
5807 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5808 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5809 * routine is invoked to log into the remote port first.
5810 *
5811 * Return code
5812 * 0 - Either the FARP Match Mode not supported or successfully processed
5813 **/
dea31012005-04-17 16:05:31 -05005814static int
James Smart2e0fef82007-06-17 19:56:36 -05005815lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5816 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005817{
5818 struct lpfc_dmabuf *pcmd;
5819 uint32_t *lp;
5820 IOCB_t *icmd;
5821 FARP *fp;
5822 uint32_t cmd, cnt, did;
5823
5824 icmd = &cmdiocb->iocb;
5825 did = icmd->un.elsreq64.remoteID;
5826 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5827 lp = (uint32_t *) pcmd->virt;
5828
5829 cmd = *lp++;
5830 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005831 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005832 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5833 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005834 /* We will only support match on WWPN or WWNN */
5835 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005836 return 0;
dea31012005-04-17 16:05:31 -05005837 }
5838
5839 cnt = 0;
5840 /* If this FARP command is searching for my portname */
5841 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005842 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005843 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005844 cnt = 1;
5845 }
5846
5847 /* If this FARP command is searching for my nodename */
5848 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005849 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005850 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005851 cnt = 1;
5852 }
5853
5854 if (cnt) {
5855 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5856 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5857 /* Log back into the node before sending the FARP. */
5858 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005859 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005860 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005861 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005862 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005863 }
5864
5865 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005866 if (fp->Rflags & FARP_REQUEST_FARPR)
5867 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005868 }
5869 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005870 return 0;
dea31012005-04-17 16:05:31 -05005871}
5872
James Smarte59058c2008-08-24 21:49:00 -04005873/**
James Smart3621a712009-04-06 18:47:14 -04005874 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005875 * @vport: pointer to a host virtual N_Port data structure.
5876 * @cmdiocb: pointer to lpfc command iocb data structure.
5877 * @ndlp: pointer to a node-list data structure.
5878 *
5879 * This routine processes Fibre Channel Address Resolution Protocol
5880 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5881 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5882 * the FARP response request.
5883 *
5884 * Return code
5885 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5886 **/
dea31012005-04-17 16:05:31 -05005887static int
James Smart2e0fef82007-06-17 19:56:36 -05005888lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5889 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005890{
5891 struct lpfc_dmabuf *pcmd;
5892 uint32_t *lp;
5893 IOCB_t *icmd;
5894 uint32_t cmd, did;
5895
5896 icmd = &cmdiocb->iocb;
5897 did = icmd->un.elsreq64.remoteID;
5898 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5899 lp = (uint32_t *) pcmd->virt;
5900
5901 cmd = *lp++;
5902 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005903 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5904 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005905 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005906 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005907
5908 return 0;
5909}
5910
James Smarte59058c2008-08-24 21:49:00 -04005911/**
James Smart3621a712009-04-06 18:47:14 -04005912 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005913 * @vport: pointer to a host virtual N_Port data structure.
5914 * @cmdiocb: pointer to lpfc command iocb data structure.
5915 * @fan_ndlp: pointer to a node-list data structure.
5916 *
5917 * This routine processes a Fabric Address Notification (FAN) IOCB
5918 * command received as an ELS unsolicited event. The FAN ELS command will
5919 * only be processed on a physical port (i.e., the @vport represents the
5920 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5921 * compared against those in the phba data structure. If any of those is
5922 * different, the lpfc_initial_flogi() routine is invoked to initialize
5923 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5924 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5925 * is invoked to register login to the fabric.
5926 *
5927 * Return code
5928 * 0 - Successfully processed fan iocb (currently always return 0).
5929 **/
dea31012005-04-17 16:05:31 -05005930static int
James Smart2e0fef82007-06-17 19:56:36 -05005931lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5932 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005933{
James Smart2e0fef82007-06-17 19:56:36 -05005934 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005935 uint32_t *lp;
5936 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005937
James Smart0d2b6b82008-06-14 22:52:47 -04005938 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5939 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5940 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005941 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005942 if ((vport == phba->pport) &&
5943 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005944 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005945 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005946 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005947 sizeof(struct lpfc_name)))) {
5948 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05005949 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005950 } else {
5951 /* FAN verified - skip FLOGI */
5952 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005953 if (phba->sli_rev < LPFC_SLI_REV4)
5954 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05005955 else {
5956 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5957 "3138 Need register VFI: (x%x/%x)\n",
5958 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04005959 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05005960 }
dea31012005-04-17 16:05:31 -05005961 }
dea31012005-04-17 16:05:31 -05005962 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005963 return 0;
dea31012005-04-17 16:05:31 -05005964}
5965
James Smarte59058c2008-08-24 21:49:00 -04005966/**
James Smart3621a712009-04-06 18:47:14 -04005967 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005968 * @ptr: holder for the timer function associated data.
5969 *
5970 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5971 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5972 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5973 * up the worker thread. It is for the worker thread to invoke the routine
5974 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5975 **/
dea31012005-04-17 16:05:31 -05005976void
5977lpfc_els_timeout(unsigned long ptr)
5978{
James Smart2e0fef82007-06-17 19:56:36 -05005979 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5980 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005981 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005982 unsigned long iflag;
5983
James Smart2e0fef82007-06-17 19:56:36 -05005984 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005985 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5986 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005987 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005988 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005989
James Smart5e9d9b82008-06-14 22:52:53 -04005990 if (!tmo_posted)
5991 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005992 return;
5993}
5994
James Smart2a9bf3d2010-06-07 15:24:45 -04005995
James Smarte59058c2008-08-24 21:49:00 -04005996/**
James Smart3621a712009-04-06 18:47:14 -04005997 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005998 * @vport: pointer to a virtual N_Port data structure.
5999 *
6000 * This routine is the actual handler function that processes an ELS timeout
6001 * event. It walks the ELS ring to get and abort all the IOCBs (except the
6002 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
6003 * invoking the lpfc_sli_issue_abort_iotag() routine.
6004 **/
dea31012005-04-17 16:05:31 -05006005void
James Smart2e0fef82007-06-17 19:56:36 -05006006lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006007{
James Smart2e0fef82007-06-17 19:56:36 -05006008 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006009 struct lpfc_sli_ring *pring;
6010 struct lpfc_iocbq *tmp_iocb, *piocb;
6011 IOCB_t *cmd = NULL;
6012 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05006013 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05006014 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05006015 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04006016 LIST_HEAD(txcmplq_completions);
6017 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05006018
James Smart2a9bf3d2010-06-07 15:24:45 -04006019
dea31012005-04-17 16:05:31 -05006020 timeout = (uint32_t)(phba->fc_ratov << 1);
6021
6022 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006023
James Smart2a9bf3d2010-06-07 15:24:45 -04006024 spin_lock_irq(&phba->hbalock);
6025 list_splice_init(&pring->txcmplq, &txcmplq_completions);
6026 spin_unlock_irq(&phba->hbalock);
6027
6028 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05006029 cmd = &piocb->iocb;
6030
James Smart2e0fef82007-06-17 19:56:36 -05006031 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
6032 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
6033 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05006034 continue;
James Smart2e0fef82007-06-17 19:56:36 -05006035
6036 if (piocb->vport != vport)
6037 continue;
6038
dea31012005-04-17 16:05:31 -05006039 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05006040 if (pcmd)
6041 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05006042
James Smart92d7f7b2007-06-17 19:56:38 -05006043 if (els_command == ELS_CMD_FARP ||
6044 els_command == ELS_CMD_FARPR ||
6045 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05006046 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05006047
dea31012005-04-17 16:05:31 -05006048 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05006049 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05006050 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05006051 else
dea31012005-04-17 16:05:31 -05006052 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05006053 continue;
6054 }
6055
James Smart2e0fef82007-06-17 19:56:36 -05006056 remote_ID = 0xffffffff;
6057 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05006058 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05006059 else {
6060 struct lpfc_nodelist *ndlp;
6061 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04006062 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05006063 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05006064 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006065 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05006066 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006067 spin_lock_irq(&phba->hbalock);
6068 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05006069 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04006070
James Smart2a9bf3d2010-06-07 15:24:45 -04006071 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
6072 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6073 "0127 ELS timeout Data: x%x x%x x%x "
6074 "x%x\n", els_command,
6075 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
6076 spin_lock_irq(&phba->hbalock);
6077 list_del_init(&piocb->dlist);
6078 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6079 spin_unlock_irq(&phba->hbalock);
6080 }
6081
James Smart2e0fef82007-06-17 19:56:36 -05006082 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
6083 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05006084}
6085
James Smarte59058c2008-08-24 21:49:00 -04006086/**
James Smart3621a712009-04-06 18:47:14 -04006087 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04006088 * @vport: pointer to a host virtual N_Port data structure.
6089 *
6090 * This routine is used to clean up all the outstanding ELS commands on a
6091 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
6092 * routine. After that, it walks the ELS transmit queue to remove all the
6093 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
6094 * the IOCBs with a non-NULL completion callback function, the callback
6095 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6096 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
6097 * callback function, the IOCB will simply be released. Finally, it walks
6098 * the ELS transmit completion queue to issue an abort IOCB to any transmit
6099 * completion queue IOCB that is associated with the @vport and is not
6100 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
6101 * part of the discovery state machine) out to HBA by invoking the
6102 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
6103 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
6104 * the IOCBs are aborted when this function returns.
6105 **/
dea31012005-04-17 16:05:31 -05006106void
James Smart2e0fef82007-06-17 19:56:36 -05006107lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006108{
James Smart2534ba72007-04-25 09:52:20 -04006109 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05006110 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04006111 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006112 struct lpfc_iocbq *tmp_iocb, *piocb;
6113 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006114
6115 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05006116
James Smart2e0fef82007-06-17 19:56:36 -05006117 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006118 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6119 cmd = &piocb->iocb;
6120
6121 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6122 continue;
6123 }
6124
6125 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04006126 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6127 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6128 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6129 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05006130 continue;
dea31012005-04-17 16:05:31 -05006131
James Smart2e0fef82007-06-17 19:56:36 -05006132 if (piocb->vport != vport)
6133 continue;
6134
James Smart2534ba72007-04-25 09:52:20 -04006135 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04006136 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05006137 }
6138
6139 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05006140 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6141 continue;
6142 }
dea31012005-04-17 16:05:31 -05006143
James Smart2e0fef82007-06-17 19:56:36 -05006144 if (piocb->vport != vport)
6145 continue;
6146
James Smart07951072007-04-25 09:51:38 -04006147 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05006148 }
James Smart2e0fef82007-06-17 19:56:36 -05006149 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04006150
James Smarta257bf92009-04-06 18:48:10 -04006151 /* Cancell all the IOCBs from the completions list */
6152 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6153 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04006154
dea31012005-04-17 16:05:31 -05006155 return;
6156}
6157
James Smarte59058c2008-08-24 21:49:00 -04006158/**
James Smart3621a712009-04-06 18:47:14 -04006159 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04006160 * @phba: pointer to lpfc hba data structure.
6161 *
6162 * This routine is used to clean up all the outstanding ELS commands on a
6163 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6164 * routine. After that, it walks the ELS transmit queue to remove all the
6165 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6166 * the IOCBs with the completion callback function associated, the callback
6167 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6168 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6169 * callback function associated, the IOCB will simply be released. Finally,
6170 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6171 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6172 * management plane IOCBs that are not part of the discovery state machine)
6173 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6174 **/
James Smart549e55c2007-08-02 11:09:51 -04006175void
6176lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6177{
6178 LIST_HEAD(completions);
6179 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6180 struct lpfc_iocbq *tmp_iocb, *piocb;
6181 IOCB_t *cmd = NULL;
6182
6183 lpfc_fabric_abort_hba(phba);
6184 spin_lock_irq(&phba->hbalock);
6185 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6186 cmd = &piocb->iocb;
6187 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6188 continue;
6189 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6190 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6191 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6192 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6193 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6194 continue;
6195 list_move_tail(&piocb->list, &completions);
6196 pring->txq_cnt--;
6197 }
6198 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6199 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6200 continue;
6201 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6202 }
6203 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04006204
6205 /* Cancel all the IOCBs from the completions list */
6206 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6207 IOERR_SLI_ABORTED);
6208
James Smart549e55c2007-08-02 11:09:51 -04006209 return;
6210}
6211
James Smarte59058c2008-08-24 21:49:00 -04006212/**
James Smart3621a712009-04-06 18:47:14 -04006213 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04006214 * @phba: Pointer to hba context object.
6215 * @cmdiocbp: Pointer to command iocb which reported error.
6216 * @rspiocbp: Pointer to response iocb which reported error.
6217 *
6218 * This function sends an event when there is an ELS command
6219 * failure.
6220 **/
6221void
6222lpfc_send_els_failure_event(struct lpfc_hba *phba,
6223 struct lpfc_iocbq *cmdiocbp,
6224 struct lpfc_iocbq *rspiocbp)
6225{
6226 struct lpfc_vport *vport = cmdiocbp->vport;
6227 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6228 struct lpfc_lsrjt_event lsrjt_event;
6229 struct lpfc_fabric_event_header fabric_event;
6230 struct ls_rjt stat;
6231 struct lpfc_nodelist *ndlp;
6232 uint32_t *pcmd;
6233
6234 ndlp = cmdiocbp->context1;
6235 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6236 return;
6237
6238 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6239 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6240 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6241 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6242 sizeof(struct lpfc_name));
6243 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6244 sizeof(struct lpfc_name));
6245 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6246 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006247 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006248 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6249 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6250 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6251 fc_host_post_vendor_event(shost,
6252 fc_get_event_number(),
6253 sizeof(lsrjt_event),
6254 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006255 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006256 return;
6257 }
6258 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6259 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6260 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6261 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6262 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6263 else
6264 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6265 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6266 sizeof(struct lpfc_name));
6267 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6268 sizeof(struct lpfc_name));
6269 fc_host_post_vendor_event(shost,
6270 fc_get_event_number(),
6271 sizeof(fabric_event),
6272 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006273 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006274 return;
6275 }
6276
6277}
6278
6279/**
James Smart3621a712009-04-06 18:47:14 -04006280 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006281 * @vport: Pointer to vport object.
6282 * @ndlp: Pointer FC node object.
6283 * @cmd: ELS command code.
6284 *
6285 * This function posts an event when there is an incoming
6286 * unsolicited ELS command.
6287 **/
6288static void
6289lpfc_send_els_event(struct lpfc_vport *vport,
6290 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006291 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006292{
James Smartddcc50f2008-12-04 22:38:46 -05006293 struct lpfc_els_event_header *els_data = NULL;
6294 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006295 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6296
James Smartddcc50f2008-12-04 22:38:46 -05006297 if (*payload == ELS_CMD_LOGO) {
6298 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6299 if (!logo_data) {
6300 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6301 "0148 Failed to allocate memory "
6302 "for LOGO event\n");
6303 return;
6304 }
6305 els_data = &logo_data->header;
6306 } else {
6307 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6308 GFP_KERNEL);
6309 if (!els_data) {
6310 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6311 "0149 Failed to allocate memory "
6312 "for ELS event\n");
6313 return;
6314 }
6315 }
6316 els_data->event_type = FC_REG_ELS_EVENT;
6317 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006318 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006319 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006320 break;
6321 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006322 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006323 break;
6324 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006325 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6326 break;
6327 case ELS_CMD_LOGO:
6328 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6329 /* Copy the WWPN in the LOGO payload */
6330 memcpy(logo_data->logo_wwpn, &payload[2],
6331 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006332 break;
6333 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006334 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006335 return;
6336 }
James Smartddcc50f2008-12-04 22:38:46 -05006337 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6338 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6339 if (*payload == ELS_CMD_LOGO) {
6340 fc_host_post_vendor_event(shost,
6341 fc_get_event_number(),
6342 sizeof(struct lpfc_logo_event),
6343 (char *)logo_data,
6344 LPFC_NL_VENDOR_ID);
6345 kfree(logo_data);
6346 } else {
6347 fc_host_post_vendor_event(shost,
6348 fc_get_event_number(),
6349 sizeof(struct lpfc_els_event_header),
6350 (char *)els_data,
6351 LPFC_NL_VENDOR_ID);
6352 kfree(els_data);
6353 }
James Smartea2151b2008-09-07 11:52:10 -04006354
6355 return;
6356}
6357
6358
6359/**
James Smart3621a712009-04-06 18:47:14 -04006360 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006361 * @phba: pointer to lpfc hba data structure.
6362 * @pring: pointer to a SLI ring.
6363 * @vport: pointer to a host virtual N_Port data structure.
6364 * @elsiocb: pointer to lpfc els command iocb data structure.
6365 *
6366 * This routine is used for processing the IOCB associated with a unsolicited
6367 * event. It first determines whether there is an existing ndlp that matches
6368 * the DID from the unsolicited IOCB. If not, it will create a new one with
6369 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6370 * IOCB is then used to invoke the proper routine and to set up proper state
6371 * of the discovery state machine.
6372 **/
James Smarted957682007-06-17 19:56:37 -05006373static void
6374lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006375 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006376{
James Smart87af33f2007-10-27 13:37:43 -04006377 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006378 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006379 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006380 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05006381 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006382 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006383
James Smarte47c9092008-02-08 18:49:26 -05006384 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006385 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006386
dea31012005-04-17 16:05:31 -05006387 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006388 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6389 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006390 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006391 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006392
James Smart858c9f62007-06-17 19:56:39 -05006393 did = icmd->un.rcvels.remoteID;
6394 if (icmd->ulpStatus) {
6395 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6396 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6397 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006398 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006399 }
dea31012005-04-17 16:05:31 -05006400
6401 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006402 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006403 goto dropit;
dea31012005-04-17 16:05:31 -05006404
James Smartc8685952009-11-18 15:39:16 -05006405 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006406 if (vport->load_flag & FC_UNLOADING)
6407 goto dropit;
6408
James Smart92494142011-02-16 12:39:44 -05006409 /* If NPort discovery is delayed drop incoming ELS */
6410 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6411 (cmd != ELS_CMD_PLOGI))
6412 goto dropit;
6413
James Smart2e0fef82007-06-17 19:56:36 -05006414 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006415 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006416 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006417 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006418 if (!ndlp)
dea31012005-04-17 16:05:31 -05006419 goto dropit;
dea31012005-04-17 16:05:31 -05006420
James Smart2e0fef82007-06-17 19:56:36 -05006421 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006422 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006423 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006424 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006425 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006426 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6427 ndlp = lpfc_enable_node(vport, ndlp,
6428 NLP_STE_UNUSED_NODE);
6429 if (!ndlp)
6430 goto dropit;
6431 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6432 newnode = 1;
6433 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6434 ndlp->nlp_type |= NLP_FABRIC;
6435 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6436 /* This is similar to the new node path */
6437 ndlp = lpfc_nlp_get(ndlp);
6438 if (!ndlp)
6439 goto dropit;
6440 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6441 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006442 }
dea31012005-04-17 16:05:31 -05006443
6444 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006445
James Smart329f9bc2007-04-25 09:53:01 -04006446 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006447 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006448
6449 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6450 cmd &= ELS_CMD_MASK;
6451 }
6452 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006453 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6454 "0112 ELS command x%x received from NPORT x%x "
6455 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006456 switch (cmd) {
6457 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006458 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6459 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6460 did, vport->port_state, ndlp->nlp_flag);
6461
dea31012005-04-17 16:05:31 -05006462 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006463 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6464
James Smartddcc50f2008-12-04 22:38:46 -05006465 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05006466
6467 /* If Nport discovery is delayed, reject PLOGIs */
6468 if (vport->fc_flag & FC_DISC_DELAYED) {
6469 rjt_err = LSRJT_UNABLE_TPC;
6470 break;
6471 }
James Smart858c9f62007-06-17 19:56:39 -05006472 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006473 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6474 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6475 rjt_err = LSRJT_UNABLE_TPC;
6476 break;
6477 }
6478 /* We get here, and drop thru, if we are PT2PT with
6479 * another NPort and the other side has initiated
6480 * the PLOGI before responding to our FLOGI.
6481 */
dea31012005-04-17 16:05:31 -05006482 }
James Smart87af33f2007-10-27 13:37:43 -04006483
6484 shost = lpfc_shost_from_vport(vport);
6485 spin_lock_irq(shost->host_lock);
6486 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6487 spin_unlock_irq(shost->host_lock);
6488
James Smart2e0fef82007-06-17 19:56:36 -05006489 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6490 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006491
dea31012005-04-17 16:05:31 -05006492 break;
6493 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006494 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6495 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6496 did, vport->port_state, ndlp->nlp_flag);
6497
dea31012005-04-17 16:05:31 -05006498 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006499 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006500 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006501 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006502 break;
6503 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006504 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6505 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6506 did, vport->port_state, ndlp->nlp_flag);
6507
dea31012005-04-17 16:05:31 -05006508 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006509 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006510 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006511 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006512 break;
6513 }
James Smart2e0fef82007-06-17 19:56:36 -05006514 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006515 break;
6516 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006517 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6518 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6519 did, vport->port_state, ndlp->nlp_flag);
6520
dea31012005-04-17 16:05:31 -05006521 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006522 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006523 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006524 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006525 break;
6526 }
James Smart2e0fef82007-06-17 19:56:36 -05006527 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006528 break;
6529 case ELS_CMD_RSCN:
6530 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006531 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006532 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006533 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006534 break;
6535 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006536 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6537 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6538 did, vport->port_state, ndlp->nlp_flag);
6539
James Smartddcc50f2008-12-04 22:38:46 -05006540 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006541 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006542 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006543 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006544 break;
6545 }
James Smart2e0fef82007-06-17 19:56:36 -05006546 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6547 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006548 break;
6549 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006550 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6551 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6552 did, vport->port_state, ndlp->nlp_flag);
6553
dea31012005-04-17 16:05:31 -05006554 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006555 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006556 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006557 break;
6558 }
James Smart2e0fef82007-06-17 19:56:36 -05006559 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6560 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006561 break;
6562 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006563 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6564 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6565 did, vport->port_state, ndlp->nlp_flag);
6566
dea31012005-04-17 16:05:31 -05006567 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006568 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006569 break;
6570 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006571 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6572 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6573 did, vport->port_state, ndlp->nlp_flag);
6574
dea31012005-04-17 16:05:31 -05006575 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006576 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006577 break;
6578 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006579 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6580 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6581 did, vport->port_state, ndlp->nlp_flag);
6582
dea31012005-04-17 16:05:31 -05006583 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006584 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006585 break;
dea31012005-04-17 16:05:31 -05006586 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006587 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6588 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6589 did, vport->port_state, ndlp->nlp_flag);
6590
dea31012005-04-17 16:05:31 -05006591 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006592 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006593 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006594 break;
6595 }
James Smart2e0fef82007-06-17 19:56:36 -05006596 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006597 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006598 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006599 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6600 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6601 did, vport->port_state, ndlp->nlp_flag);
6602
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006603 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006604 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006605 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006606 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006607 break;
James Smart12265f62010-10-22 11:05:53 -04006608 case ELS_CMD_RLS:
6609 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6610 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6611 did, vport->port_state, ndlp->nlp_flag);
6612
6613 phba->fc_stat.elsRcvRLS++;
6614 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6615 if (newnode)
6616 lpfc_nlp_put(ndlp);
6617 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006618 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006619 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6620 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6621 did, vport->port_state, ndlp->nlp_flag);
6622
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006623 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006624 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006625 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006626 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006627 break;
6628 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006629 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6630 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6631 did, vport->port_state, ndlp->nlp_flag);
6632
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006633 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006634 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006635 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006636 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006637 break;
dea31012005-04-17 16:05:31 -05006638 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006639 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6640 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6641 did, vport->port_state, ndlp->nlp_flag);
6642
dea31012005-04-17 16:05:31 -05006643 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006644 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006645 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006646 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006647 break;
James Smart12265f62010-10-22 11:05:53 -04006648 case ELS_CMD_RTV:
6649 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6650 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6651 did, vport->port_state, ndlp->nlp_flag);
6652 phba->fc_stat.elsRcvRTV++;
6653 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6654 if (newnode)
6655 lpfc_nlp_put(ndlp);
6656 break;
James Smart5ffc2662009-11-18 15:39:44 -05006657 case ELS_CMD_RRQ:
6658 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6659 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6660 did, vport->port_state, ndlp->nlp_flag);
6661
6662 phba->fc_stat.elsRcvRRQ++;
6663 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6664 if (newnode)
6665 lpfc_nlp_put(ndlp);
6666 break;
James Smart12265f62010-10-22 11:05:53 -04006667 case ELS_CMD_ECHO:
6668 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6669 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6670 did, vport->port_state, ndlp->nlp_flag);
6671
6672 phba->fc_stat.elsRcvECHO++;
6673 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6674 if (newnode)
6675 lpfc_nlp_put(ndlp);
6676 break;
dea31012005-04-17 16:05:31 -05006677 default:
James Smart858c9f62007-06-17 19:56:39 -05006678 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6679 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6680 cmd, did, vport->port_state);
6681
dea31012005-04-17 16:05:31 -05006682 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006683 rjt_err = LSRJT_CMD_UNSUPPORTED;
dea31012005-04-17 16:05:31 -05006684
6685 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006686 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6687 "0115 Unknown ELS command x%x "
6688 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006689 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006690 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006691 break;
6692 }
6693
6694 /* check if need to LS_RJT received ELS cmd */
6695 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006696 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006697 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006698 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006699 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6700 NULL);
dea31012005-04-17 16:05:31 -05006701 }
6702
James Smartd7c255b2008-08-24 21:50:00 -04006703 lpfc_nlp_put(elsiocb->context1);
6704 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006705 return;
6706
6707dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006708 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006709 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6710 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006711 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006712 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006713 phba->fc_stat.elsRcvDrop++;
6714}
6715
James Smarte59058c2008-08-24 21:49:00 -04006716/**
James Smart3621a712009-04-06 18:47:14 -04006717 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006718 * @phba: pointer to lpfc hba data structure.
6719 * @pring: pointer to a SLI ring.
6720 * @elsiocb: pointer to lpfc els iocb data structure.
6721 *
6722 * This routine is used to process an unsolicited event received from a SLI
6723 * (Service Level Interface) ring. The actual processing of the data buffer
6724 * associated with the unsolicited event is done by invoking the routine
6725 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6726 * SLI ring on which the unsolicited event was received.
6727 **/
James Smarted957682007-06-17 19:56:37 -05006728void
6729lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6730 struct lpfc_iocbq *elsiocb)
6731{
6732 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006733 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006734 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006735 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6736 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006737
James Smartd7c255b2008-08-24 21:50:00 -04006738 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006739 elsiocb->context2 = NULL;
6740 elsiocb->context3 = NULL;
6741
6742 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6743 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6744 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6745 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006746 phba->fc_stat.NoRcvBuf++;
6747 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006748 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006749 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006750 return;
6751 }
6752
James Smart92d7f7b2007-06-17 19:56:38 -05006753 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6754 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6755 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6756 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6757 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006758 else
6759 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04006760 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05006761 }
James Smart6d368e52011-05-24 11:44:12 -04006762
James Smart7f5f3d02008-02-08 18:50:14 -05006763 /* If there are no BDEs associated
6764 * with this IOCB, there is nothing to do.
6765 */
James Smarted957682007-06-17 19:56:37 -05006766 if (icmd->ulpBdeCount == 0)
6767 return;
6768
James Smart7f5f3d02008-02-08 18:50:14 -05006769 /* type of ELS cmd is first 32bit word
6770 * in packet
6771 */
James Smarted957682007-06-17 19:56:37 -05006772 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006773 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006774 } else {
6775 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6776 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006777 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6778 paddr);
James Smarted957682007-06-17 19:56:37 -05006779 }
6780
James Smart92d7f7b2007-06-17 19:56:38 -05006781 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6782 /*
6783 * The different unsolicited event handlers would tell us
6784 * if they are done with "mp" by setting context2 to NULL.
6785 */
dea31012005-04-17 16:05:31 -05006786 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006787 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6788 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006789 }
James Smarted957682007-06-17 19:56:37 -05006790
6791 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006792 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006793 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006794 elsiocb->context2 = bdeBuf2;
6795 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006796 /* free mp if we are done with it */
6797 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006798 lpfc_in_buf_free(phba, elsiocb->context2);
6799 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006800 }
dea31012005-04-17 16:05:31 -05006801 }
dea31012005-04-17 16:05:31 -05006802}
James Smart92d7f7b2007-06-17 19:56:38 -05006803
James Smarte59058c2008-08-24 21:49:00 -04006804/**
James Smart3621a712009-04-06 18:47:14 -04006805 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006806 * @phba: pointer to lpfc hba data structure.
6807 * @vport: pointer to a virtual N_Port data structure.
6808 *
6809 * This routine issues a Port Login (PLOGI) to the Name Server with
6810 * State Change Request (SCR) for a @vport. This routine will create an
6811 * ndlp for the Name Server associated to the @vport if such node does
6812 * not already exist. The PLOGI to Name Server is issued by invoking the
6813 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6814 * (FDMI) is configured to the @vport, a FDMI node will be created and
6815 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6816 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006817void
6818lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6819{
6820 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05006821 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6822
6823 /*
6824 * If lpfc_delay_discovery parameter is set and the clean address
6825 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6826 * discovery.
6827 */
6828 spin_lock_irq(shost->host_lock);
6829 if (vport->fc_flag & FC_DISC_DELAYED) {
6830 spin_unlock_irq(shost->host_lock);
6831 mod_timer(&vport->delayed_disc_tmo,
6832 jiffies + HZ * phba->fc_ratov);
6833 return;
6834 }
6835 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006836
6837 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6838 if (!ndlp) {
6839 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6840 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006841 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05006842 lpfc_disc_start(vport);
6843 return;
6844 }
6845 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006846 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6847 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006848 return;
6849 }
6850 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006851 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6852 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6853 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006854 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05006855 lpfc_disc_start(vport);
6856 return;
6857 }
6858 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6859 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6860 "0348 NameServer login: node freed\n");
6861 return;
6862 }
James Smart92d7f7b2007-06-17 19:56:38 -05006863 }
James Smart58da1ff2008-04-07 10:15:56 -04006864 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006865
6866 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6867
6868 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6869 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006870 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6871 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006872 return;
6873 }
6874
James Smart3de2a652007-08-02 11:09:59 -04006875 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05006876 /* If this is the first time, allocate an ndlp and initialize
6877 * it. Otherwise, make sure the node is enabled and then do the
6878 * login.
6879 */
6880 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
6881 if (!ndlp_fdmi) {
6882 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6883 GFP_KERNEL);
6884 if (ndlp_fdmi) {
6885 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6886 ndlp_fdmi->nlp_type |= NLP_FABRIC;
6887 } else
6888 return;
6889 }
6890 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
6891 ndlp_fdmi = lpfc_enable_node(vport,
6892 ndlp_fdmi,
6893 NLP_STE_NPR_NODE);
6894
James Smart92d7f7b2007-06-17 19:56:38 -05006895 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04006896 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05006897 NLP_STE_PLOGI_ISSUE);
6898 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006899 }
6900 }
James Smart92d7f7b2007-06-17 19:56:38 -05006901}
6902
James Smarte59058c2008-08-24 21:49:00 -04006903/**
James Smart3621a712009-04-06 18:47:14 -04006904 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006905 * @phba: pointer to lpfc hba data structure.
6906 * @pmb: pointer to the driver internal queue element for mailbox command.
6907 *
6908 * This routine is the completion callback function to register new vport
6909 * mailbox command. If the new vport mailbox command completes successfully,
6910 * the fabric registration login shall be performed on physical port (the
6911 * new vport created is actually a physical port, with VPI 0) or the port
6912 * login to Name Server for State Change Request (SCR) will be performed
6913 * on virtual port (real virtual port, with VPI greater than 0).
6914 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006915static void
6916lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6917{
6918 struct lpfc_vport *vport = pmb->vport;
6919 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6920 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006921 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006922 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006923
James Smart09372822008-01-11 01:52:54 -05006924 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006925 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006926 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006927
6928 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006929 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006930 "0915 Register VPI failed : Status: x%x"
6931 " upd bit: x%x \n", mb->mbxStatus,
6932 mb->un.varRegVpi.upd);
6933 if (phba->sli_rev == LPFC_SLI_REV4 &&
6934 mb->un.varRegVpi.upd)
6935 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006936
6937 switch (mb->mbxStatus) {
6938 case 0x11: /* unsupported feature */
6939 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006940 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006941 /* giving up on vport registration */
6942 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6943 spin_lock_irq(shost->host_lock);
6944 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6945 spin_unlock_irq(shost->host_lock);
6946 lpfc_can_disctmo(vport);
6947 break;
James Smart695a8142010-01-26 23:08:03 -05006948 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6949 case 0x20:
6950 spin_lock_irq(shost->host_lock);
6951 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6952 spin_unlock_irq(shost->host_lock);
6953 lpfc_init_vpi(phba, pmb, vport->vpi);
6954 pmb->vport = vport;
6955 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6956 rc = lpfc_sli_issue_mbox(phba, pmb,
6957 MBX_NOWAIT);
6958 if (rc == MBX_NOT_FINISHED) {
6959 lpfc_printf_vlog(vport,
6960 KERN_ERR, LOG_MBOX,
6961 "2732 Failed to issue INIT_VPI"
6962 " mailbox command\n");
6963 } else {
6964 lpfc_nlp_put(ndlp);
6965 return;
6966 }
6967
James Smart92d7f7b2007-06-17 19:56:38 -05006968 default:
6969 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04006970 if (phba->sli_rev == LPFC_SLI_REV4)
6971 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006972 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006973 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006974 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006975 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006976 if (vport->port_type == LPFC_PHYSICAL_PORT
6977 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05006978 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05006979 else
6980 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006981 break;
6982 }
James Smart92d7f7b2007-06-17 19:56:38 -05006983 } else {
James Smart695a8142010-01-26 23:08:03 -05006984 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006985 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006986 spin_unlock_irq(shost->host_lock);
6987 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006988 if (phba->sli_rev < LPFC_SLI_REV4)
6989 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006990 else {
James Smartfc2b9892010-02-26 14:15:29 -05006991 /*
6992 * If the physical port is instantiated using
6993 * FDISC, do not start vport discovery.
6994 */
6995 if (vport->port_state != LPFC_FDISC)
6996 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006997 lpfc_do_scr_ns_plogi(phba, vport);
6998 }
6999 } else
James Smart92d7f7b2007-06-17 19:56:38 -05007000 lpfc_do_scr_ns_plogi(phba, vport);
7001 }
James Smart38b92ef2010-08-04 16:11:39 -04007002mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05007003 /* Now, we decrement the ndlp reference count held for this
7004 * callback function
7005 */
7006 lpfc_nlp_put(ndlp);
7007
James Smart92d7f7b2007-06-17 19:56:38 -05007008 mempool_free(pmb, phba->mbox_mem_pool);
7009 return;
7010}
7011
James Smarte59058c2008-08-24 21:49:00 -04007012/**
James Smart3621a712009-04-06 18:47:14 -04007013 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04007014 * @phba: pointer to lpfc hba data structure.
7015 * @vport: pointer to a host virtual N_Port data structure.
7016 * @ndlp: pointer to a node-list data structure.
7017 *
7018 * This routine registers the @vport as a new virtual port with a HBA.
7019 * It is done through a registering vpi mailbox command.
7020 **/
James Smart695a8142010-01-26 23:08:03 -05007021void
James Smart92d7f7b2007-06-17 19:56:38 -05007022lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
7023 struct lpfc_nodelist *ndlp)
7024{
James Smart09372822008-01-11 01:52:54 -05007025 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007026 LPFC_MBOXQ_t *mbox;
7027
7028 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7029 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04007030 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05007031 mbox->vport = vport;
7032 mbox->context2 = lpfc_nlp_get(ndlp);
7033 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04007034 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05007035 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05007036 /* mailbox command not success, decrement ndlp
7037 * reference count for this command
7038 */
7039 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007040 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05007041
James Smarte8b62012007-08-02 11:10:09 -04007042 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7043 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05007044 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007045 }
7046 } else {
James Smarte8b62012007-08-02 11:10:09 -04007047 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7048 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05007049 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007050 }
James Smartfa4066b2008-01-11 01:53:27 -05007051 return;
7052
7053mbox_err_exit:
7054 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7055 spin_lock_irq(shost->host_lock);
7056 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
7057 spin_unlock_irq(shost->host_lock);
7058 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007059}
7060
James Smarte59058c2008-08-24 21:49:00 -04007061/**
James Smart0c9ab6f2010-02-26 14:15:57 -05007062 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05007063 * @phba: pointer to lpfc hba data structure.
7064 *
James Smart0c9ab6f2010-02-26 14:15:57 -05007065 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05007066 **/
7067void
James Smart0c9ab6f2010-02-26 14:15:57 -05007068lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05007069{
7070 struct lpfc_vport **vports;
7071 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05007072 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05007073 int i;
James Smart695a8142010-01-26 23:08:03 -05007074
7075 /* Treat this failure as linkdown for all vports */
7076 link_state = phba->link_state;
7077 lpfc_linkdown(phba);
7078 phba->link_state = link_state;
7079
7080 vports = lpfc_create_vport_work_array(phba);
7081
7082 if (vports) {
7083 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
7084 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
7085 if (ndlp)
7086 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
7087 lpfc_els_flush_cmd(vports[i]);
7088 }
7089 lpfc_destroy_vport_work_array(phba, vports);
7090 }
James Smart0c9ab6f2010-02-26 14:15:57 -05007091}
7092
7093/**
7094 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7095 * @phba: pointer to lpfc hba data structure.
7096 *
7097 * This routine abort all pending discovery commands and
7098 * start a timer to retry FLOGI for the physical port
7099 * discovery.
7100 **/
7101void
7102lpfc_retry_pport_discovery(struct lpfc_hba *phba)
7103{
7104 struct lpfc_nodelist *ndlp;
7105 struct Scsi_Host *shost;
7106
7107 /* Cancel the all vports retry delay retry timers */
7108 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05007109
7110 /* If fabric require FLOGI, then re-instantiate physical login */
7111 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
7112 if (!ndlp)
7113 return;
7114
James Smart695a8142010-01-26 23:08:03 -05007115 shost = lpfc_shost_from_vport(phba->pport);
7116 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
7117 spin_lock_irq(shost->host_lock);
7118 ndlp->nlp_flag |= NLP_DELAY_TMO;
7119 spin_unlock_irq(shost->host_lock);
7120 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7121 phba->pport->port_state = LPFC_FLOGI;
7122 return;
7123}
7124
7125/**
7126 * lpfc_fabric_login_reqd - Check if FLOGI required.
7127 * @phba: pointer to lpfc hba data structure.
7128 * @cmdiocb: pointer to FDISC command iocb.
7129 * @rspiocb: pointer to FDISC response iocb.
7130 *
7131 * This routine checks if a FLOGI is reguired for FDISC
7132 * to succeed.
7133 **/
7134static int
7135lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7136 struct lpfc_iocbq *cmdiocb,
7137 struct lpfc_iocbq *rspiocb)
7138{
7139
7140 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7141 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7142 return 0;
7143 else
7144 return 1;
7145}
7146
7147/**
James Smart3621a712009-04-06 18:47:14 -04007148 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007149 * @phba: pointer to lpfc hba data structure.
7150 * @cmdiocb: pointer to lpfc command iocb data structure.
7151 * @rspiocb: pointer to lpfc response iocb data structure.
7152 *
7153 * This routine is the completion callback function to a Fabric Discover
7154 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7155 * single threaded, each FDISC completion callback function will reset
7156 * the discovery timer for all vports such that the timers will not get
7157 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7158 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7159 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7160 * assigned to the vport has been changed with the completion of the FDISC
7161 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7162 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7163 * routine is invoked to register new vport with the HBA. Otherwise, the
7164 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7165 * Server for State Change Request (SCR).
7166 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007167static void
7168lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7169 struct lpfc_iocbq *rspiocb)
7170{
7171 struct lpfc_vport *vport = cmdiocb->vport;
7172 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7173 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7174 struct lpfc_nodelist *np;
7175 struct lpfc_nodelist *next_np;
7176 IOCB_t *irsp = &rspiocb->iocb;
7177 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05007178 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7179 struct serv_parm *sp;
7180 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05007181
James Smarte8b62012007-08-02 11:10:09 -04007182 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7183 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7184 irsp->ulpStatus, irsp->un.ulpWord[4],
7185 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05007186 /* Since all FDISCs are being single threaded, we
7187 * must reset the discovery timer for ALL vports
7188 * waiting to send FDISC when one completes.
7189 */
7190 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7191 lpfc_set_disctmo(piocb->vport);
7192 }
7193
James Smart858c9f62007-06-17 19:56:39 -05007194 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7195 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7196 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7197
James Smart92d7f7b2007-06-17 19:56:38 -05007198 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05007199
7200 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7201 lpfc_retry_pport_discovery(phba);
7202 goto out;
7203 }
7204
James Smart92d7f7b2007-06-17 19:56:38 -05007205 /* Check for retry */
7206 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7207 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007208 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04007209 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart6b5151f2012-01-18 16:24:06 -05007210 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04007211 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04007212 goto fdisc_failed;
7213 }
James Smartd7c255b2008-08-24 21:50:00 -04007214 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05007215 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04007216 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04007217 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05007218 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04007219 vport->fc_flag |= FC_PUBLIC_LOOP;
7220 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007221
James Smartd7c255b2008-08-24 21:50:00 -04007222 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7223 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05007224 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7225 sp = prsp->virt + sizeof(uint32_t);
7226 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7227 memcpy(&vport->fabric_portname, &sp->portName,
7228 sizeof(struct lpfc_name));
7229 memcpy(&vport->fabric_nodename, &sp->nodeName,
7230 sizeof(struct lpfc_name));
7231 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04007232 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7233 /* If our NportID changed, we need to ensure all
7234 * remaining NPORTs get unreg_login'ed so we can
7235 * issue unreg_vpi.
7236 */
7237 list_for_each_entry_safe(np, next_np,
7238 &vport->fc_nodes, nlp_listp) {
7239 if (!NLP_CHK_NODE_ACT(ndlp) ||
7240 (np->nlp_state != NLP_STE_NPR_NODE) ||
7241 !(np->nlp_flag & NLP_NPR_ADISC))
7242 continue;
James Smart09372822008-01-11 01:52:54 -05007243 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007244 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007245 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007246 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007247 }
James Smart78730cf2010-04-06 15:06:30 -04007248 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007249
7250 if (phba->sli_rev == LPFC_SLI_REV4)
7251 lpfc_sli4_unreg_all_rpis(vport);
7252
James Smartd7c255b2008-08-24 21:50:00 -04007253 lpfc_mbx_unreg_vpi(vport);
7254 spin_lock_irq(shost->host_lock);
7255 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007256 if (phba->sli_rev == LPFC_SLI_REV4)
7257 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007258 else
7259 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007260 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007261 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7262 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7263 /*
7264 * Driver needs to re-reg VPI in order for f/w
7265 * to update the MAC address.
7266 */
7267 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007268 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007269 }
7270
James Smartecfd03c2010-02-12 14:41:27 -05007271 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7272 lpfc_issue_init_vpi(vport);
7273 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007274 lpfc_register_new_vport(phba, vport, ndlp);
7275 else
7276 lpfc_do_scr_ns_plogi(phba, vport);
7277 goto out;
7278fdisc_failed:
7279 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7280 /* Cancel discovery timer */
7281 lpfc_can_disctmo(vport);
7282 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007283out:
7284 lpfc_els_free_iocb(phba, cmdiocb);
7285}
7286
James Smarte59058c2008-08-24 21:49:00 -04007287/**
James Smart3621a712009-04-06 18:47:14 -04007288 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007289 * @vport: pointer to a virtual N_Port data structure.
7290 * @ndlp: pointer to a node-list data structure.
7291 * @retry: number of retries to the command IOCB.
7292 *
7293 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7294 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7295 * routine to issue the IOCB, which makes sure only one outstanding fabric
7296 * IOCB will be sent off HBA at any given time.
7297 *
7298 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7299 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7300 * will be stored into the context1 field of the IOCB for the completion
7301 * callback function to the FDISC ELS command.
7302 *
7303 * Return code
7304 * 0 - Successfully issued fdisc iocb command
7305 * 1 - Failed to issue fdisc iocb command
7306 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007307static int
James Smart92d7f7b2007-06-17 19:56:38 -05007308lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7309 uint8_t retry)
7310{
7311 struct lpfc_hba *phba = vport->phba;
7312 IOCB_t *icmd;
7313 struct lpfc_iocbq *elsiocb;
7314 struct serv_parm *sp;
7315 uint8_t *pcmd;
7316 uint16_t cmdsize;
7317 int did = ndlp->nlp_DID;
7318 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007319
James Smart5ffc2662009-11-18 15:39:44 -05007320 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05007321 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007322 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7323 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7324 ELS_CMD_FDISC);
7325 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007326 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007327 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7328 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007329 return 1;
7330 }
7331
7332 icmd = &elsiocb->iocb;
7333 icmd->un.elsreq64.myID = 0;
7334 icmd->un.elsreq64.fl = 1;
7335
James Smart73d91e52011-10-10 21:32:10 -04007336 /*
7337 * SLI3 ports require a different context type value than SLI4.
7338 * Catch SLI3 ports here and override the prep.
7339 */
7340 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04007341 icmd->ulpCt_h = 1;
7342 icmd->ulpCt_l = 0;
7343 }
James Smart92d7f7b2007-06-17 19:56:38 -05007344
7345 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7346 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7347 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7348 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7349 sp = (struct serv_parm *) pcmd;
7350 /* Setup CSPs accordingly for Fabric */
7351 sp->cmn.e_d_tov = 0;
7352 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05007353 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007354 sp->cls1.classValid = 0;
7355 sp->cls2.seqDelivery = 1;
7356 sp->cls3.seqDelivery = 1;
7357
7358 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7359 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7360 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7361 pcmd += sizeof(uint32_t); /* Port Name */
7362 memcpy(pcmd, &vport->fc_portname, 8);
7363 pcmd += sizeof(uint32_t); /* Node Name */
7364 pcmd += sizeof(uint32_t); /* Node Name */
7365 memcpy(pcmd, &vport->fc_nodename, 8);
7366
7367 lpfc_set_disctmo(vport);
7368
7369 phba->fc_stat.elsXmitFDISC++;
7370 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7371
James Smart858c9f62007-06-17 19:56:39 -05007372 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7373 "Issue FDISC: did:x%x",
7374 did, 0, 0);
7375
James Smart92d7f7b2007-06-17 19:56:38 -05007376 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7377 if (rc == IOCB_ERROR) {
7378 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007379 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007380 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7381 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007382 return 1;
7383 }
7384 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007385 return 0;
7386}
7387
James Smarte59058c2008-08-24 21:49:00 -04007388/**
James Smart3621a712009-04-06 18:47:14 -04007389 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007390 * @phba: pointer to lpfc hba data structure.
7391 * @cmdiocb: pointer to lpfc command iocb data structure.
7392 * @rspiocb: pointer to lpfc response iocb data structure.
7393 *
7394 * This routine is the completion callback function to the issuing of a LOGO
7395 * ELS command off a vport. It frees the command IOCB and then decrement the
7396 * reference count held on ndlp for this completion function, indicating that
7397 * the reference to the ndlp is no long needed. Note that the
7398 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7399 * callback function and an additional explicit ndlp reference decrementation
7400 * will trigger the actual release of the ndlp.
7401 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007402static void
7403lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7404 struct lpfc_iocbq *rspiocb)
7405{
7406 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007407 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007408 struct lpfc_nodelist *ndlp;
James Smart9589b062011-04-16 11:03:17 -04007409 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05007410
James Smart9589b062011-04-16 11:03:17 -04007411 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007412 irsp = &rspiocb->iocb;
7413 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7414 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7415 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007416
7417 lpfc_els_free_iocb(phba, cmdiocb);
7418 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007419
7420 /* Trigger the release of the ndlp after logo */
7421 lpfc_nlp_put(ndlp);
James Smart9589b062011-04-16 11:03:17 -04007422
7423 /* NPIV LOGO completes to NPort <nlp_DID> */
7424 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7425 "2928 NPIV LOGO completes to NPort x%x "
7426 "Data: x%x x%x x%x x%x\n",
7427 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
7428 irsp->ulpTimeout, vport->num_disc_nodes);
7429
7430 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
7431 spin_lock_irq(shost->host_lock);
7432 vport->fc_flag &= ~FC_FABRIC;
7433 spin_unlock_irq(shost->host_lock);
7434 }
James Smart92d7f7b2007-06-17 19:56:38 -05007435}
7436
James Smarte59058c2008-08-24 21:49:00 -04007437/**
James Smart3621a712009-04-06 18:47:14 -04007438 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007439 * @vport: pointer to a virtual N_Port data structure.
7440 * @ndlp: pointer to a node-list data structure.
7441 *
7442 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7443 *
7444 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7445 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7446 * will be stored into the context1 field of the IOCB for the completion
7447 * callback function to the LOGO ELS command.
7448 *
7449 * Return codes
7450 * 0 - Successfully issued logo off the @vport
7451 * 1 - Failed to issue logo off the @vport
7452 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007453int
7454lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7455{
7456 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7457 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007458 IOCB_t *icmd;
7459 struct lpfc_iocbq *elsiocb;
7460 uint8_t *pcmd;
7461 uint16_t cmdsize;
7462
7463 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7464 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7465 ELS_CMD_LOGO);
7466 if (!elsiocb)
7467 return 1;
7468
7469 icmd = &elsiocb->iocb;
7470 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7471 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7472 pcmd += sizeof(uint32_t);
7473
7474 /* Fill in LOGO payload */
7475 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7476 pcmd += sizeof(uint32_t);
7477 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7478
James Smart858c9f62007-06-17 19:56:39 -05007479 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7480 "Issue LOGO npiv did:x%x flg:x%x",
7481 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7482
James Smart92d7f7b2007-06-17 19:56:38 -05007483 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7484 spin_lock_irq(shost->host_lock);
7485 ndlp->nlp_flag |= NLP_LOGO_SND;
7486 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007487 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7488 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007489 spin_lock_irq(shost->host_lock);
7490 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7491 spin_unlock_irq(shost->host_lock);
7492 lpfc_els_free_iocb(phba, elsiocb);
7493 return 1;
7494 }
7495 return 0;
7496}
7497
James Smarte59058c2008-08-24 21:49:00 -04007498/**
James Smart3621a712009-04-06 18:47:14 -04007499 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007500 * @ptr: holder for the timer function associated data.
7501 *
7502 * This routine is invoked by the fabric iocb block timer after
7503 * timeout. It posts the fabric iocb block timeout event by setting the
7504 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7505 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7506 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7507 * posted event WORKER_FABRIC_BLOCK_TMO.
7508 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007509void
7510lpfc_fabric_block_timeout(unsigned long ptr)
7511{
7512 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7513 unsigned long iflags;
7514 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007515
James Smart92d7f7b2007-06-17 19:56:38 -05007516 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7517 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7518 if (!tmo_posted)
7519 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7520 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7521
James Smart5e9d9b82008-06-14 22:52:53 -04007522 if (!tmo_posted)
7523 lpfc_worker_wake_up(phba);
7524 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007525}
7526
James Smarte59058c2008-08-24 21:49:00 -04007527/**
James Smart3621a712009-04-06 18:47:14 -04007528 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007529 * @phba: pointer to lpfc hba data structure.
7530 *
7531 * This routine issues one fabric iocb from the driver internal list to
7532 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7533 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7534 * remove one pending fabric iocb from the driver internal list and invokes
7535 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7536 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007537static void
7538lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7539{
7540 struct lpfc_iocbq *iocb;
7541 unsigned long iflags;
7542 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007543 IOCB_t *cmd;
7544
7545repeat:
7546 iocb = NULL;
7547 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007548 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007549 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7550 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7551 list);
7552 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007553 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007554 atomic_inc(&phba->fabric_iocb_count);
7555 }
7556 spin_unlock_irqrestore(&phba->hbalock, iflags);
7557 if (iocb) {
7558 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7559 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7560 iocb->iocb_flag |= LPFC_IO_FABRIC;
7561
James Smart858c9f62007-06-17 19:56:39 -05007562 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7563 "Fabric sched1: ste:x%x",
7564 iocb->vport->port_state, 0, 0);
7565
James Smart3772a992009-05-22 14:50:54 -04007566 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007567
7568 if (ret == IOCB_ERROR) {
7569 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7570 iocb->fabric_iocb_cmpl = NULL;
7571 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7572 cmd = &iocb->iocb;
7573 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7574 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7575 iocb->iocb_cmpl(phba, iocb, iocb);
7576
7577 atomic_dec(&phba->fabric_iocb_count);
7578 goto repeat;
7579 }
7580 }
7581
7582 return;
7583}
7584
James Smarte59058c2008-08-24 21:49:00 -04007585/**
James Smart3621a712009-04-06 18:47:14 -04007586 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007587 * @phba: pointer to lpfc hba data structure.
7588 *
7589 * This routine unblocks the issuing fabric iocb command. The function
7590 * will clear the fabric iocb block bit and then invoke the routine
7591 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7592 * from the driver internal fabric iocb list.
7593 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007594void
7595lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7596{
7597 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7598
7599 lpfc_resume_fabric_iocbs(phba);
7600 return;
7601}
7602
James Smarte59058c2008-08-24 21:49:00 -04007603/**
James Smart3621a712009-04-06 18:47:14 -04007604 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007605 * @phba: pointer to lpfc hba data structure.
7606 *
7607 * This routine blocks the issuing fabric iocb for a specified amount of
7608 * time (currently 100 ms). This is done by set the fabric iocb block bit
7609 * and set up a timeout timer for 100ms. When the block bit is set, no more
7610 * fabric iocb will be issued out of the HBA.
7611 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007612static void
7613lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7614{
7615 int blocked;
7616
7617 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007618 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007619 if (!blocked)
7620 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7621
7622 return;
7623}
7624
James Smarte59058c2008-08-24 21:49:00 -04007625/**
James Smart3621a712009-04-06 18:47:14 -04007626 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007627 * @phba: pointer to lpfc hba data structure.
7628 * @cmdiocb: pointer to lpfc command iocb data structure.
7629 * @rspiocb: pointer to lpfc response iocb data structure.
7630 *
7631 * This routine is the callback function that is put to the fabric iocb's
7632 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7633 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7634 * function first restores and invokes the original iocb's callback function
7635 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7636 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7637 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007638static void
7639lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7640 struct lpfc_iocbq *rspiocb)
7641{
7642 struct ls_rjt stat;
7643
7644 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7645 BUG();
7646
7647 switch (rspiocb->iocb.ulpStatus) {
7648 case IOSTAT_NPORT_RJT:
7649 case IOSTAT_FABRIC_RJT:
7650 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7651 lpfc_block_fabric_iocbs(phba);
7652 }
7653 break;
7654
7655 case IOSTAT_NPORT_BSY:
7656 case IOSTAT_FABRIC_BSY:
7657 lpfc_block_fabric_iocbs(phba);
7658 break;
7659
7660 case IOSTAT_LS_RJT:
7661 stat.un.lsRjtError =
7662 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7663 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7664 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7665 lpfc_block_fabric_iocbs(phba);
7666 break;
7667 }
7668
7669 if (atomic_read(&phba->fabric_iocb_count) == 0)
7670 BUG();
7671
7672 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7673 cmdiocb->fabric_iocb_cmpl = NULL;
7674 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7675 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7676
7677 atomic_dec(&phba->fabric_iocb_count);
7678 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007679 /* Post any pending iocbs to HBA */
7680 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007681 }
7682}
7683
James Smarte59058c2008-08-24 21:49:00 -04007684/**
James Smart3621a712009-04-06 18:47:14 -04007685 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007686 * @phba: pointer to lpfc hba data structure.
7687 * @iocb: pointer to lpfc command iocb data structure.
7688 *
7689 * This routine is used as the top-level API for issuing a fabric iocb command
7690 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7691 * function makes sure that only one fabric bound iocb will be outstanding at
7692 * any given time. As such, this function will first check to see whether there
7693 * is already an outstanding fabric iocb on the wire. If so, it will put the
7694 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7695 * issued later. Otherwise, it will issue the iocb on the wire and update the
7696 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7697 *
7698 * Note, this implementation has a potential sending out fabric IOCBs out of
7699 * order. The problem is caused by the construction of the "ready" boolen does
7700 * not include the condition that the internal fabric IOCB list is empty. As
7701 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7702 * ahead of the fabric IOCBs in the internal list.
7703 *
7704 * Return code
7705 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7706 * IOCB_ERROR - failed to issue fabric iocb
7707 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007708static int
James Smart92d7f7b2007-06-17 19:56:38 -05007709lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7710{
7711 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007712 int ready;
7713 int ret;
7714
7715 if (atomic_read(&phba->fabric_iocb_count) > 1)
7716 BUG();
7717
7718 spin_lock_irqsave(&phba->hbalock, iflags);
7719 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7720 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7721
James Smart7f5f3d02008-02-08 18:50:14 -05007722 if (ready)
7723 /* Increment fabric iocb count to hold the position */
7724 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007725 spin_unlock_irqrestore(&phba->hbalock, iflags);
7726 if (ready) {
7727 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7728 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7729 iocb->iocb_flag |= LPFC_IO_FABRIC;
7730
James Smart858c9f62007-06-17 19:56:39 -05007731 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7732 "Fabric sched2: ste:x%x",
7733 iocb->vport->port_state, 0, 0);
7734
James Smart3772a992009-05-22 14:50:54 -04007735 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007736
7737 if (ret == IOCB_ERROR) {
7738 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7739 iocb->fabric_iocb_cmpl = NULL;
7740 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7741 atomic_dec(&phba->fabric_iocb_count);
7742 }
7743 } else {
7744 spin_lock_irqsave(&phba->hbalock, iflags);
7745 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7746 spin_unlock_irqrestore(&phba->hbalock, iflags);
7747 ret = IOCB_SUCCESS;
7748 }
7749 return ret;
7750}
7751
James Smarte59058c2008-08-24 21:49:00 -04007752/**
James Smart3621a712009-04-06 18:47:14 -04007753 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007754 * @vport: pointer to a virtual N_Port data structure.
7755 *
7756 * This routine aborts all the IOCBs associated with a @vport from the
7757 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7758 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7759 * list, removes each IOCB associated with the @vport off the list, set the
7760 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7761 * associated with the IOCB.
7762 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007763static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007764{
7765 LIST_HEAD(completions);
7766 struct lpfc_hba *phba = vport->phba;
7767 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007768
7769 spin_lock_irq(&phba->hbalock);
7770 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7771 list) {
7772
7773 if (piocb->vport != vport)
7774 continue;
7775
7776 list_move_tail(&piocb->list, &completions);
7777 }
7778 spin_unlock_irq(&phba->hbalock);
7779
James Smarta257bf92009-04-06 18:48:10 -04007780 /* Cancel all the IOCBs from the completions list */
7781 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7782 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007783}
7784
James Smarte59058c2008-08-24 21:49:00 -04007785/**
James Smart3621a712009-04-06 18:47:14 -04007786 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007787 * @ndlp: pointer to a node-list data structure.
7788 *
7789 * This routine aborts all the IOCBs associated with an @ndlp from the
7790 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7791 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7792 * list, removes each IOCB associated with the @ndlp off the list, set the
7793 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7794 * associated with the IOCB.
7795 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007796void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7797{
7798 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007799 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007800 struct lpfc_iocbq *tmp_iocb, *piocb;
7801 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007802
7803 spin_lock_irq(&phba->hbalock);
7804 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7805 list) {
7806 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7807
7808 list_move_tail(&piocb->list, &completions);
7809 }
7810 }
7811 spin_unlock_irq(&phba->hbalock);
7812
James Smarta257bf92009-04-06 18:48:10 -04007813 /* Cancel all the IOCBs from the completions list */
7814 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7815 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007816}
7817
James Smarte59058c2008-08-24 21:49:00 -04007818/**
James Smart3621a712009-04-06 18:47:14 -04007819 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007820 * @phba: pointer to lpfc hba data structure.
7821 *
7822 * This routine aborts all the IOCBs currently on the driver internal
7823 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7824 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7825 * list, removes IOCBs off the list, set the status feild to
7826 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7827 * the IOCB.
7828 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007829void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7830{
7831 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007832
7833 spin_lock_irq(&phba->hbalock);
7834 list_splice_init(&phba->fabric_iocb_list, &completions);
7835 spin_unlock_irq(&phba->hbalock);
7836
James Smarta257bf92009-04-06 18:48:10 -04007837 /* Cancel all the IOCBs from the completions list */
7838 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7839 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007840}
James Smart6fb120a2009-05-22 14:52:59 -04007841
7842/**
James Smart1151e3e2011-02-16 12:39:35 -05007843 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7844 * @vport: pointer to lpfc vport data structure.
7845 *
7846 * This routine is invoked by the vport cleanup for deletions and the cleanup
7847 * for an ndlp on removal.
7848 **/
7849void
7850lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
7851{
7852 struct lpfc_hba *phba = vport->phba;
7853 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7854 unsigned long iflag = 0;
7855
7856 spin_lock_irqsave(&phba->hbalock, iflag);
7857 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7858 list_for_each_entry_safe(sglq_entry, sglq_next,
7859 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7860 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
7861 sglq_entry->ndlp = NULL;
7862 }
7863 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7864 spin_unlock_irqrestore(&phba->hbalock, iflag);
7865 return;
7866}
7867
7868/**
James Smart6fb120a2009-05-22 14:52:59 -04007869 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7870 * @phba: pointer to lpfc hba data structure.
7871 * @axri: pointer to the els xri abort wcqe structure.
7872 *
7873 * This routine is invoked by the worker thread to process a SLI4 slow-path
7874 * ELS aborted xri.
7875 **/
7876void
7877lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7878 struct sli4_wcqe_xri_aborted *axri)
7879{
7880 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05007881 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04007882 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05007883
James Smart6fb120a2009-05-22 14:52:59 -04007884 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7885 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05007886 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04007887 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007888
James Smart0f65ff62010-02-26 14:14:23 -05007889 spin_lock_irqsave(&phba->hbalock, iflag);
7890 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007891 list_for_each_entry_safe(sglq_entry, sglq_next,
7892 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7893 if (sglq_entry->sli4_xritag == xri) {
7894 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05007895 ndlp = sglq_entry->ndlp;
7896 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04007897 list_add_tail(&sglq_entry->list,
7898 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007899 sglq_entry->state = SGL_FREED;
7900 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007901 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart19ca7602010-11-20 23:11:55 -05007902 lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04007903
7904 /* Check if TXQ queue needs to be serviced */
7905 if (pring->txq_cnt)
7906 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007907 return;
7908 }
7909 }
James Smart0f65ff62010-02-26 14:14:23 -05007910 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04007911 lxri = lpfc_sli4_xri_inrange(phba, xri);
7912 if (lxri == NO_XRI) {
7913 spin_unlock_irqrestore(&phba->hbalock, iflag);
7914 return;
7915 }
7916 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05007917 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7918 spin_unlock_irqrestore(&phba->hbalock, iflag);
7919 return;
7920 }
7921 sglq_entry->state = SGL_XRI_ABORTED;
7922 spin_unlock_irqrestore(&phba->hbalock, iflag);
7923 return;
James Smart6fb120a2009-05-22 14:52:59 -04007924}