blob: 2ecd719cc2aa25008b9fe10ccc1046bb1c199733 [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 Smart92d7f7b2007-06-17 19:56:38 -0500710 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart5248a742011-07-22 18:37:06 -0400711 /*
712 * If VPI is unreged, driver need to do INIT_VPI
713 * before re-registering
714 */
James Smartecfd03c2010-02-12 14:41:27 -0500715 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
716 spin_unlock_irq(shost->host_lock);
717 }
James Smart38b92ef2010-08-04 16:11:39 -0400718 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
719 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
720 /*
721 * Driver needs to re-reg VPI in order for f/w
722 * to update the MAC address.
723 */
James Smart9589b062011-04-16 11:03:17 -0400724 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400725 lpfc_register_new_vport(phba, vport, ndlp);
726 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500727 }
728
James Smart6fb120a2009-05-22 14:52:59 -0400729 if (phba->sli_rev < LPFC_SLI_REV4) {
730 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
731 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
732 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
733 lpfc_register_new_vport(phba, vport, ndlp);
734 else
735 lpfc_issue_fabric_reglogin(vport);
736 } else {
737 ndlp->nlp_type |= NLP_FABRIC;
738 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500739 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
740 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400741 lpfc_start_fdiscs(phba);
742 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500743 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500744 lpfc_issue_init_vpi(vport);
James Smart1b511972011-12-13 13:23:09 -0500745 else {
746 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
747 "3135 Need register VFI: (x%x/%x)\n",
748 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -0400749 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -0500750 }
James Smart92d7f7b2007-06-17 19:56:38 -0500751 }
dea31012005-04-17 16:05:31 -0500752 return 0;
dea31012005-04-17 16:05:31 -0500753}
James Smart1b511972011-12-13 13:23:09 -0500754
James Smarte59058c2008-08-24 21:49:00 -0400755/**
James Smart3621a712009-04-06 18:47:14 -0400756 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400757 * @vport: pointer to a host virtual N_Port data structure.
758 * @ndlp: pointer to a node-list data structure.
759 * @sp: pointer to service parameter data structure.
760 *
761 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
762 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
763 * in a point-to-point topology. First, the @vport's N_Port Name is compared
764 * with the received N_Port Name: if the @vport's N_Port Name is greater than
765 * the received N_Port Name lexicographically, this node shall assign local
766 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
767 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
768 * this node shall just wait for the remote node to issue PLOGI and assign
769 * N_Port IDs.
770 *
771 * Return code
772 * 0 - Success
773 * -ENXIO - Fail
774 **/
dea31012005-04-17 16:05:31 -0500775static int
James Smart2e0fef82007-06-17 19:56:36 -0500776lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
777 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500778{
James Smart2e0fef82007-06-17 19:56:36 -0500779 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
780 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500781 LPFC_MBOXQ_t *mbox;
782 int rc;
783
James Smart2e0fef82007-06-17 19:56:36 -0500784 spin_lock_irq(shost->host_lock);
785 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
786 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500787
788 phba->fc_edtov = FF_DEF_EDTOV;
789 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500790 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500791 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500792 if (rc >= 0) {
793 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500794 spin_lock_irq(shost->host_lock);
795 vport->fc_flag |= FC_PT2PT_PLOGI;
796 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500797
798 /*
799 * N_Port ID cannot be 0, set our to LocalID the other
800 * side will be RemoteID.
801 */
802
803 /* not equal */
804 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500805 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500806
807 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
808 if (!mbox)
809 goto fail;
810
811 lpfc_config_link(phba, mbox);
812
813 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500814 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400815 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500816 if (rc == MBX_NOT_FINISHED) {
817 mempool_free(mbox, phba->mbox_mem_pool);
818 goto fail;
819 }
James Smarte47c9092008-02-08 18:49:26 -0500820 /* Decrement ndlp reference count indicating that ndlp can be
821 * safely released when other references to it are done.
822 */
James Smart329f9bc2007-04-25 09:53:01 -0400823 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500824
James Smart2e0fef82007-06-17 19:56:36 -0500825 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500826 if (!ndlp) {
827 /*
828 * Cannot find existing Fabric ndlp, so allocate a
829 * new one
830 */
831 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
832 if (!ndlp)
833 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500834 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500835 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
836 ndlp = lpfc_enable_node(vport, ndlp,
837 NLP_STE_UNUSED_NODE);
838 if(!ndlp)
839 goto fail;
dea31012005-04-17 16:05:31 -0500840 }
841
842 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500843 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500844 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500845 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500846 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500847 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
848 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500849 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500850 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500851 } else
852 /* This side will wait for the PLOGI, decrement ndlp reference
853 * count indicating that ndlp can be released when other
854 * references to it are done.
855 */
James Smart329f9bc2007-04-25 09:53:01 -0400856 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500857
James Smart09372822008-01-11 01:52:54 -0500858 /* If we are pt2pt with another NPort, force NPIV off! */
859 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
860
James Smart2e0fef82007-06-17 19:56:36 -0500861 spin_lock_irq(shost->host_lock);
862 vport->fc_flag |= FC_PT2PT;
863 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500864
865 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500866 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500867 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500868fail:
dea31012005-04-17 16:05:31 -0500869 return -ENXIO;
870}
871
James Smarte59058c2008-08-24 21:49:00 -0400872/**
James Smart3621a712009-04-06 18:47:14 -0400873 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400874 * @phba: pointer to lpfc hba data structure.
875 * @cmdiocb: pointer to lpfc command iocb data structure.
876 * @rspiocb: pointer to lpfc response iocb data structure.
877 *
878 * This routine is the top-level completion callback function for issuing
879 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
880 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
881 * retry has been made (either immediately or delayed with lpfc_els_retry()
882 * returning 1), the command IOCB will be released and function returned.
883 * If the retry attempt has been given up (possibly reach the maximum
884 * number of retries), one additional decrement of ndlp reference shall be
885 * invoked before going out after releasing the command IOCB. This will
886 * actually release the remote node (Note, lpfc_els_free_iocb() will also
887 * invoke one decrement of ndlp reference count). If no error reported in
888 * the IOCB status, the command Port ID field is used to determine whether
889 * this is a point-to-point topology or a fabric topology: if the Port ID
890 * field is assigned, it is a fabric topology; otherwise, it is a
891 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
892 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
893 * specific topology completion conditions.
894 **/
dea31012005-04-17 16:05:31 -0500895static void
James Smart329f9bc2007-04-25 09:53:01 -0400896lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
897 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500898{
James Smart2e0fef82007-06-17 19:56:36 -0500899 struct lpfc_vport *vport = cmdiocb->vport;
900 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500901 IOCB_t *irsp = &rspiocb->iocb;
902 struct lpfc_nodelist *ndlp = cmdiocb->context1;
903 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
904 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500905 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500906 int rc;
907
908 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500909 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500910 /* One additional decrement on node reference count to
911 * trigger the release of the node
912 */
James Smart329f9bc2007-04-25 09:53:01 -0400913 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500914 goto out;
915 }
916
James Smart858c9f62007-06-17 19:56:39 -0500917 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
918 "FLOGI cmpl: status:x%x/x%x state:x%x",
919 irsp->ulpStatus, irsp->un.ulpWord[4],
920 vport->port_state);
921
dea31012005-04-17 16:05:31 -0500922 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500923 /*
James Smarta93ff372010-10-22 11:06:08 -0400924 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500925 * due to new FCF discovery
926 */
927 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart80c17842012-03-01 22:35:45 -0500928 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
929 if (phba->link_state < LPFC_LINK_UP)
930 goto stop_rr_fcf_flogi;
931 if ((phba->fcoe_cvl_eventtag_attn ==
932 phba->fcoe_cvl_eventtag) &&
933 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
934 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))
935 goto stop_rr_fcf_flogi;
936 else
937 phba->fcoe_cvl_eventtag_attn =
938 phba->fcoe_cvl_eventtag;
James Smart0c9ab6f2010-02-26 14:15:57 -0500939 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400940 "2611 FLOGI failed on FCF (x%x), "
941 "status:x%x/x%x, tmo:x%x, perform "
942 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -0400943 phba->fcf.current_rec.fcf_indx,
944 irsp->ulpStatus, irsp->un.ulpWord[4],
945 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -0400946 lpfc_sli4_set_fcf_flogi_fail(phba,
947 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500948 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -0400949 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
950 if (rc)
951 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500952 }
953
James Smart80c17842012-03-01 22:35:45 -0500954stop_rr_fcf_flogi:
James Smart38b92ef2010-08-04 16:11:39 -0400955 /* FLOGI failure */
956 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
957 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
958 irsp->ulpStatus, irsp->un.ulpWord[4],
959 irsp->ulpTimeout);
960
dea31012005-04-17 16:05:31 -0500961 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500962 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500963 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500964
James Smart76a95d72010-11-20 23:11:48 -0500965 /* FLOGI failure */
966 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
967 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
968 irsp->ulpStatus, irsp->un.ulpWord[4],
969 irsp->ulpTimeout);
970
dea31012005-04-17 16:05:31 -0500971 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500972 spin_lock_irq(shost->host_lock);
973 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
974 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500975
James Smart329f9bc2007-04-25 09:53:01 -0400976 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500977 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
978 * alpa map would take too long otherwise.
979 */
James Smart1b511972011-12-13 13:23:09 -0500980 if (phba->alpa_map[0] == 0)
James Smart3de2a652007-08-02 11:09:59 -0400981 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -0500982 if ((phba->sli_rev == LPFC_SLI_REV4) &&
983 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
984 (vport->fc_prevDID != vport->fc_myDID))) {
985 if (vport->fc_flag & FC_VFI_REGISTERED)
986 lpfc_sli4_unreg_all_rpis(vport);
987 lpfc_issue_reg_vfi(vport);
988 lpfc_nlp_put(ndlp);
989 goto out;
dea31012005-04-17 16:05:31 -0500990 }
dea31012005-04-17 16:05:31 -0500991 goto flogifail;
992 }
James Smart695a8142010-01-26 23:08:03 -0500993 spin_lock_irq(shost->host_lock);
994 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400995 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500996 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500997
998 /*
999 * The FLogI succeeded. Sync the data for the CPU before
1000 * accessing it.
1001 */
1002 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1003
1004 sp = prsp->virt + sizeof(uint32_t);
1005
1006 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -04001007 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001008 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -04001009 "Data: x%x x%x x%x x%x\n",
1010 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1011 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -05001012
James Smart2e0fef82007-06-17 19:56:36 -05001013 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -05001014 /*
1015 * If Common Service Parameters indicate Nport
1016 * we are point to point, if Fport we are Fabric.
1017 */
1018 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -05001019 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -05001020 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001021 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -04001022 else {
1023 lpfc_printf_vlog(vport, KERN_ERR,
1024 LOG_FIP | LOG_ELS,
1025 "2831 FLOGI response with cleared Fabric "
1026 "bit fcf_index 0x%x "
1027 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1028 "Fabric Name "
1029 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1030 phba->fcf.current_rec.fcf_indx,
1031 phba->fcf.current_rec.switch_name[0],
1032 phba->fcf.current_rec.switch_name[1],
1033 phba->fcf.current_rec.switch_name[2],
1034 phba->fcf.current_rec.switch_name[3],
1035 phba->fcf.current_rec.switch_name[4],
1036 phba->fcf.current_rec.switch_name[5],
1037 phba->fcf.current_rec.switch_name[6],
1038 phba->fcf.current_rec.switch_name[7],
1039 phba->fcf.current_rec.fabric_name[0],
1040 phba->fcf.current_rec.fabric_name[1],
1041 phba->fcf.current_rec.fabric_name[2],
1042 phba->fcf.current_rec.fabric_name[3],
1043 phba->fcf.current_rec.fabric_name[4],
1044 phba->fcf.current_rec.fabric_name[5],
1045 phba->fcf.current_rec.fabric_name[6],
1046 phba->fcf.current_rec.fabric_name[7]);
1047 lpfc_nlp_put(ndlp);
1048 spin_lock_irq(&phba->hbalock);
1049 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001050 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -04001051 spin_unlock_irq(&phba->hbalock);
1052 goto out;
1053 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001054 if (!rc) {
1055 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -04001056 if (phba->hba_flag & HBA_FIP_SUPPORT)
1057 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1058 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001059 "2769 FLOGI to FCF (x%x) "
1060 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -04001061 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001062 spin_lock_irq(&phba->hbalock);
1063 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001064 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -05001065 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001066 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001067 }
dea31012005-04-17 16:05:31 -05001068 }
1069
1070flogifail:
James Smart329f9bc2007-04-25 09:53:01 -04001071 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001072
James Smart858c9f62007-06-17 19:56:39 -05001073 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001074 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001075 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001076
1077 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001078 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001079 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1080 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
1081 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
1082 (phba->link_state != LPFC_CLEAR_LA)) {
1083 /* If FLOGI failed enable link interrupt. */
1084 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001085 }
dea31012005-04-17 16:05:31 -05001086out:
1087 lpfc_els_free_iocb(phba, cmdiocb);
1088}
1089
James Smarte59058c2008-08-24 21:49:00 -04001090/**
James Smart3621a712009-04-06 18:47:14 -04001091 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001092 * @vport: pointer to a host virtual N_Port data structure.
1093 * @ndlp: pointer to a node-list data structure.
1094 * @retry: number of retries to the command IOCB.
1095 *
1096 * This routine issues a Fabric Login (FLOGI) Request ELS command
1097 * for a @vport. The initiator service parameters are put into the payload
1098 * of the FLOGI Request IOCB and the top-level callback function pointer
1099 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1100 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1101 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1102 *
1103 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1104 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1105 * will be stored into the context1 field of the IOCB for the completion
1106 * callback function to the FLOGI ELS command.
1107 *
1108 * Return code
1109 * 0 - successfully issued flogi iocb for @vport
1110 * 1 - failed to issue flogi iocb for @vport
1111 **/
dea31012005-04-17 16:05:31 -05001112static int
James Smart2e0fef82007-06-17 19:56:36 -05001113lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001114 uint8_t retry)
1115{
James Smart2e0fef82007-06-17 19:56:36 -05001116 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001117 struct serv_parm *sp;
1118 IOCB_t *icmd;
1119 struct lpfc_iocbq *elsiocb;
1120 struct lpfc_sli_ring *pring;
1121 uint8_t *pcmd;
1122 uint16_t cmdsize;
1123 uint32_t tmo;
1124 int rc;
1125
1126 pring = &phba->sli.ring[LPFC_ELS_RING];
1127
James Smart92d7f7b2007-06-17 19:56:38 -05001128 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001129 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1130 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001131
James Smart488d1462006-03-07 15:02:37 -05001132 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001133 return 1;
dea31012005-04-17 16:05:31 -05001134
1135 icmd = &elsiocb->iocb;
1136 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1137
1138 /* For FLOGI request, remainder of payload is service parameters */
1139 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001140 pcmd += sizeof(uint32_t);
1141 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001142 sp = (struct serv_parm *) pcmd;
1143
1144 /* Setup CSPs accordingly for Fabric */
1145 sp->cmn.e_d_tov = 0;
1146 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001147 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001148 sp->cls1.classValid = 0;
1149 sp->cls2.seqDelivery = 1;
1150 sp->cls3.seqDelivery = 1;
1151 if (sp->cmn.fcphLow < FC_PH3)
1152 sp->cmn.fcphLow = FC_PH3;
1153 if (sp->cmn.fcphHigh < FC_PH3)
1154 sp->cmn.fcphHigh = FC_PH3;
1155
James Smartc31098c2011-04-16 11:03:33 -04001156 if (phba->sli_rev == LPFC_SLI_REV4) {
1157 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1158 LPFC_SLI_INTF_IF_TYPE_0) {
1159 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1160 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1161 /* FLOGI needs to be 3 for WQE FCFI */
1162 /* Set the fcfi to the fcfi we registered with */
1163 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1164 }
James Smart5248a742011-07-22 18:37:06 -04001165 } else {
1166 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1167 sp->cmn.request_multiple_Nport = 1;
1168 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1169 icmd->ulpCt_h = 1;
1170 icmd->ulpCt_l = 0;
1171 } else
1172 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001173 }
1174
James Smart76a95d72010-11-20 23:11:48 -05001175 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001176 icmd->un.elsreq64.myID = 0;
1177 icmd->un.elsreq64.fl = 1;
1178 }
1179
dea31012005-04-17 16:05:31 -05001180 tmo = phba->fc_ratov;
1181 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001182 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001183 phba->fc_ratov = tmo;
1184
1185 phba->fc_stat.elsXmitFLOGI++;
1186 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001187
1188 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1189 "Issue FLOGI: opt:x%x",
1190 phba->sli3_options, 0, 0);
1191
James Smart92d7f7b2007-06-17 19:56:38 -05001192 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001193 if (rc == IOCB_ERROR) {
1194 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001195 return 1;
dea31012005-04-17 16:05:31 -05001196 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001197 return 0;
dea31012005-04-17 16:05:31 -05001198}
1199
James Smarte59058c2008-08-24 21:49:00 -04001200/**
James Smart3621a712009-04-06 18:47:14 -04001201 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001202 * @phba: pointer to lpfc hba data structure.
1203 *
1204 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1205 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1206 * list and issues an abort IOCB commond on each outstanding IOCB that
1207 * contains a active Fabric_DID ndlp. Note that this function is to issue
1208 * the abort IOCB command on all the outstanding IOCBs, thus when this
1209 * function returns, it does not guarantee all the IOCBs are actually aborted.
1210 *
1211 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001212 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001213 **/
dea31012005-04-17 16:05:31 -05001214int
James Smart2e0fef82007-06-17 19:56:36 -05001215lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001216{
1217 struct lpfc_sli_ring *pring;
1218 struct lpfc_iocbq *iocb, *next_iocb;
1219 struct lpfc_nodelist *ndlp;
1220 IOCB_t *icmd;
1221
1222 /* Abort outstanding I/O on NPort <nlp_DID> */
1223 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001224 "0201 Abort outstanding I/O on NPort x%x\n",
1225 Fabric_DID);
dea31012005-04-17 16:05:31 -05001226
1227 pring = &phba->sli.ring[LPFC_ELS_RING];
1228
1229 /*
1230 * Check the txcmplq for an iocb that matches the nport the driver is
1231 * searching for.
1232 */
James Smart2e0fef82007-06-17 19:56:36 -05001233 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001234 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1235 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001236 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001237 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001238 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1239 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001240 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001241 }
1242 }
James Smart2e0fef82007-06-17 19:56:36 -05001243 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001244
1245 return 0;
1246}
1247
James Smarte59058c2008-08-24 21:49:00 -04001248/**
James Smart3621a712009-04-06 18:47:14 -04001249 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001250 * @vport: pointer to a host virtual N_Port data structure.
1251 *
1252 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1253 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1254 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1255 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1256 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1257 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1258 * @vport.
1259 *
1260 * Return code
1261 * 0 - failed to issue initial flogi for @vport
1262 * 1 - successfully issued initial flogi for @vport
1263 **/
dea31012005-04-17 16:05:31 -05001264int
James Smart2e0fef82007-06-17 19:56:36 -05001265lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001266{
James Smart2e0fef82007-06-17 19:56:36 -05001267 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001268 struct lpfc_nodelist *ndlp;
1269
James Smart98c9ea52007-10-27 13:37:33 -04001270 vport->port_state = LPFC_FLOGI;
1271 lpfc_set_disctmo(vport);
1272
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001273 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001274 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001275 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001276 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001277 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1278 if (!ndlp)
1279 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001280 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001281 /* Set the node type */
1282 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001283 /* Put ndlp onto node list */
1284 lpfc_enqueue_node(vport, ndlp);
1285 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1286 /* re-setup ndlp without removing from node list */
1287 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1288 if (!ndlp)
1289 return 0;
dea31012005-04-17 16:05:31 -05001290 }
James Smart87af33f2007-10-27 13:37:43 -04001291
James Smart5ac6b302010-10-22 11:05:36 -04001292 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001293 /* This decrement of reference count to node shall kick off
1294 * the release of the node.
1295 */
James Smart329f9bc2007-04-25 09:53:01 -04001296 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001297 return 0;
1298 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001299 return 1;
dea31012005-04-17 16:05:31 -05001300}
1301
James Smarte59058c2008-08-24 21:49:00 -04001302/**
James Smart3621a712009-04-06 18:47:14 -04001303 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001304 * @vport: pointer to a host virtual N_Port data structure.
1305 *
1306 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1307 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1308 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1309 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1310 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1311 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1312 * @vport.
1313 *
1314 * Return code
1315 * 0 - failed to issue initial fdisc for @vport
1316 * 1 - successfully issued initial fdisc for @vport
1317 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001318int
1319lpfc_initial_fdisc(struct lpfc_vport *vport)
1320{
1321 struct lpfc_hba *phba = vport->phba;
1322 struct lpfc_nodelist *ndlp;
1323
1324 /* First look for the Fabric ndlp */
1325 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1326 if (!ndlp) {
1327 /* Cannot find existing Fabric ndlp, so allocate a new one */
1328 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1329 if (!ndlp)
1330 return 0;
1331 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001332 /* Put ndlp onto node list */
1333 lpfc_enqueue_node(vport, ndlp);
1334 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1335 /* re-setup ndlp without removing from node list */
1336 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1337 if (!ndlp)
1338 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001339 }
James Smarte47c9092008-02-08 18:49:26 -05001340
James Smart92d7f7b2007-06-17 19:56:38 -05001341 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001342 /* decrement node reference count to trigger the release of
1343 * the node.
1344 */
James Smart92d7f7b2007-06-17 19:56:38 -05001345 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001346 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001347 }
1348 return 1;
1349}
James Smart87af33f2007-10-27 13:37:43 -04001350
James Smarte59058c2008-08-24 21:49:00 -04001351/**
James Smart3621a712009-04-06 18:47:14 -04001352 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001353 * @vport: pointer to a host virtual N_Port data structure.
1354 *
1355 * This routine checks whether there are more remaining Port Logins
1356 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1357 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1358 * to issue ELS PLOGIs up to the configured discover threads with the
1359 * @vport (@vport->cfg_discovery_threads). The function also decrement
1360 * the @vport's num_disc_node by 1 if it is not already 0.
1361 **/
James Smart87af33f2007-10-27 13:37:43 -04001362void
James Smart2e0fef82007-06-17 19:56:36 -05001363lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001364{
1365 int sentplogi;
1366
James Smart2e0fef82007-06-17 19:56:36 -05001367 if (vport->num_disc_nodes)
1368 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001369
1370 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001371 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1372 "0232 Continue discovery with %d PLOGIs to go "
1373 "Data: x%x x%x x%x\n",
1374 vport->num_disc_nodes, vport->fc_plogi_cnt,
1375 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001376 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001377 if (vport->fc_flag & FC_NLP_MORE)
1378 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1379 sentplogi = lpfc_els_disc_plogi(vport);
1380
dea31012005-04-17 16:05:31 -05001381 return;
1382}
1383
James Smarte59058c2008-08-24 21:49:00 -04001384/**
James Smart3621a712009-04-06 18:47:14 -04001385 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001386 * @phba: pointer to lpfc hba data structure.
1387 * @prsp: pointer to response IOCB payload.
1388 * @ndlp: pointer to a node-list data structure.
1389 *
1390 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1391 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1392 * The following cases are considered N_Port confirmed:
1393 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1394 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1395 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1396 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1397 * 1) if there is a node on vport list other than the @ndlp with the same
1398 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1399 * on that node to release the RPI associated with the node; 2) if there is
1400 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1401 * into, a new node shall be allocated (or activated). In either case, the
1402 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1403 * be released and the new_ndlp shall be put on to the vport node list and
1404 * its pointer returned as the confirmed node.
1405 *
1406 * Note that before the @ndlp got "released", the keepDID from not-matching
1407 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1408 * of the @ndlp. This is because the release of @ndlp is actually to put it
1409 * into an inactive state on the vport node list and the vport node list
1410 * management algorithm does not allow two node with a same DID.
1411 *
1412 * Return code
1413 * pointer to the PLOGI N_Port @ndlp
1414 **/
James Smart488d1462006-03-07 15:02:37 -05001415static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001416lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001417 struct lpfc_nodelist *ndlp)
1418{
James Smart2e0fef82007-06-17 19:56:36 -05001419 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001420 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001421 struct lpfc_rport_data *rdata;
1422 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001423 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001424 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001425 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001426 int put_node;
1427 int put_rport;
James Smart19ca7602010-11-20 23:11:55 -05001428 struct lpfc_node_rrqs rrq;
James Smart488d1462006-03-07 15:02:37 -05001429
James Smart2fb9bd82006-12-02 13:33:57 -05001430 /* Fabric nodes can have the same WWPN so we don't bother searching
1431 * by WWPN. Just return the ndlp that was given to us.
1432 */
1433 if (ndlp->nlp_type & NLP_FABRIC)
1434 return ndlp;
1435
James Smart92d7f7b2007-06-17 19:56:38 -05001436 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001437 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001438
James Smart685f0bf2007-04-25 09:53:08 -04001439 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001440 * we have for that ndlp. If not, we have some work to do.
1441 */
James Smart2e0fef82007-06-17 19:56:36 -05001442 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001443
James Smarte47c9092008-02-08 18:49:26 -05001444 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001445 return ndlp;
James Smart19ca7602010-11-20 23:11:55 -05001446 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
James Smart488d1462006-03-07 15:02:37 -05001447
1448 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001449 rc = memcmp(&ndlp->nlp_portname, name,
1450 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001451 if (!rc)
1452 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001453 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1454 if (!new_ndlp)
1455 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001456 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001457 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001458 rc = memcmp(&ndlp->nlp_portname, name,
1459 sizeof(struct lpfc_name));
1460 if (!rc)
1461 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001462 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1463 NLP_STE_UNUSED_NODE);
1464 if (!new_ndlp)
1465 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001466 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001467 if (phba->sli_rev == LPFC_SLI_REV4)
1468 memcpy(&rrq.xri_bitmap,
1469 &new_ndlp->active_rrqs.xri_bitmap,
1470 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1471 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001472 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001473 if (phba->sli_rev == LPFC_SLI_REV4)
1474 memcpy(&rrq.xri_bitmap,
1475 &new_ndlp->active_rrqs.xri_bitmap,
1476 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1477 }
James Smart488d1462006-03-07 15:02:37 -05001478
James Smart2e0fef82007-06-17 19:56:36 -05001479 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001480 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001481 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001482 if (phba->sli_rev == LPFC_SLI_REV4)
1483 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1484 &ndlp->active_rrqs.xri_bitmap,
1485 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart0ff10d42008-01-11 01:52:36 -05001486
1487 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1488 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1489 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1490
James Smarte47c9092008-02-08 18:49:26 -05001491 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001492 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001493
James Smart2e0fef82007-06-17 19:56:36 -05001494 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001495 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1496 /* The new_ndlp is replacing ndlp totally, so we need
1497 * to put ndlp on UNUSED list and try to free it.
1498 */
James Smart0ff10d42008-01-11 01:52:36 -05001499
1500 /* Fix up the rport accordingly */
1501 rport = ndlp->rport;
1502 if (rport) {
1503 rdata = rport->dd_data;
1504 if (rdata->pnode == ndlp) {
1505 lpfc_nlp_put(ndlp);
1506 ndlp->rport = NULL;
1507 rdata->pnode = lpfc_nlp_get(new_ndlp);
1508 new_ndlp->rport = rport;
1509 }
1510 new_ndlp->nlp_type = ndlp->nlp_type;
1511 }
James Smart58da1ff2008-04-07 10:15:56 -04001512 /* We shall actually free the ndlp with both nlp_DID and
1513 * nlp_portname fields equals 0 to avoid any ndlp on the
1514 * nodelist never to be used.
1515 */
1516 if (ndlp->nlp_DID == 0) {
1517 spin_lock_irq(&phba->ndlp_lock);
1518 NLP_SET_FREE_REQ(ndlp);
1519 spin_unlock_irq(&phba->ndlp_lock);
1520 }
James Smart0ff10d42008-01-11 01:52:36 -05001521
James Smart58da1ff2008-04-07 10:15:56 -04001522 /* Two ndlps cannot have the same did on the nodelist */
1523 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001524 if (phba->sli_rev == LPFC_SLI_REV4)
1525 memcpy(&ndlp->active_rrqs.xri_bitmap,
1526 &rrq.xri_bitmap,
1527 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001528 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001529 }
James Smart92795652006-07-06 15:50:02 -04001530 else {
James Smart2e0fef82007-06-17 19:56:36 -05001531 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001532 /* Two ndlps cannot have the same did */
1533 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001534 if (phba->sli_rev == LPFC_SLI_REV4)
1535 memcpy(&ndlp->active_rrqs.xri_bitmap,
1536 &rrq.xri_bitmap,
1537 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart38b92ef2010-08-04 16:11:39 -04001538 /* Since we are swapping the ndlp passed in with the new one
1539 * and the did has already been swapped, copy over the
1540 * state and names.
1541 */
1542 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1543 sizeof(struct lpfc_name));
1544 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1545 sizeof(struct lpfc_name));
1546 new_ndlp->nlp_state = ndlp->nlp_state;
James Smarteff4a012012-01-18 16:25:25 -05001547 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart38b92ef2010-08-04 16:11:39 -04001548 /* Fix up the rport accordingly */
1549 rport = ndlp->rport;
1550 if (rport) {
1551 rdata = rport->dd_data;
1552 put_node = rdata->pnode != NULL;
1553 put_rport = ndlp->rport != NULL;
1554 rdata->pnode = NULL;
1555 ndlp->rport = NULL;
1556 if (put_node)
1557 lpfc_nlp_put(ndlp);
1558 if (put_rport)
1559 put_device(&rport->dev);
1560 }
James Smart92795652006-07-06 15:50:02 -04001561 }
James Smart488d1462006-03-07 15:02:37 -05001562 return new_ndlp;
1563}
1564
James Smarte59058c2008-08-24 21:49:00 -04001565/**
James Smart3621a712009-04-06 18:47:14 -04001566 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001567 * @vport: pointer to a host virtual N_Port data structure.
1568 *
1569 * This routine checks whether more Registration State Change
1570 * Notifications (RSCNs) came in while the discovery state machine was in
1571 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1572 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1573 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1574 * handling the RSCNs.
1575 **/
James Smart87af33f2007-10-27 13:37:43 -04001576void
1577lpfc_end_rscn(struct lpfc_vport *vport)
1578{
1579 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1580
1581 if (vport->fc_flag & FC_RSCN_MODE) {
1582 /*
1583 * Check to see if more RSCNs came in while we were
1584 * processing this one.
1585 */
1586 if (vport->fc_rscn_id_cnt ||
1587 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1588 lpfc_els_handle_rscn(vport);
1589 else {
1590 spin_lock_irq(shost->host_lock);
1591 vport->fc_flag &= ~FC_RSCN_MODE;
1592 spin_unlock_irq(shost->host_lock);
1593 }
1594 }
1595}
1596
James Smarte59058c2008-08-24 21:49:00 -04001597/**
James Smart19ca7602010-11-20 23:11:55 -05001598 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1599 * @phba: pointer to lpfc hba data structure.
1600 * @cmdiocb: pointer to lpfc command iocb data structure.
1601 * @rspiocb: pointer to lpfc response iocb data structure.
1602 *
1603 * This routine will call the clear rrq function to free the rrq and
1604 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1605 * exist then the clear_rrq is still called because the rrq needs to
1606 * be freed.
1607 **/
1608
1609static void
1610lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1611 struct lpfc_iocbq *rspiocb)
1612{
1613 struct lpfc_vport *vport = cmdiocb->vport;
1614 IOCB_t *irsp;
1615 struct lpfc_nodelist *ndlp;
1616 struct lpfc_node_rrq *rrq;
1617
1618 /* we pass cmdiocb to state machine which needs rspiocb as well */
1619 rrq = cmdiocb->context_un.rrq;
1620 cmdiocb->context_un.rsp_iocb = rspiocb;
1621
1622 irsp = &rspiocb->iocb;
1623 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1624 "RRQ cmpl: status:x%x/x%x did:x%x",
1625 irsp->ulpStatus, irsp->un.ulpWord[4],
1626 irsp->un.elsreq64.remoteID);
1627
1628 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1629 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1630 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1631 "2882 RRQ completes to NPort x%x "
1632 "with no ndlp. Data: x%x x%x x%x\n",
1633 irsp->un.elsreq64.remoteID,
1634 irsp->ulpStatus, irsp->un.ulpWord[4],
1635 irsp->ulpIoTag);
1636 goto out;
1637 }
1638
1639 /* rrq completes to NPort <nlp_DID> */
1640 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1641 "2880 RRQ completes to NPort x%x "
1642 "Data: x%x x%x x%x x%x x%x\n",
1643 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1644 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1645
1646 if (irsp->ulpStatus) {
1647 /* Check for retry */
1648 /* RRQ failed Don't print the vport to vport rjts */
1649 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1650 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1651 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1652 (phba)->pport->cfg_log_verbose & LOG_ELS)
1653 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1654 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1655 ndlp->nlp_DID, irsp->ulpStatus,
1656 irsp->un.ulpWord[4]);
1657 }
1658out:
1659 if (rrq)
1660 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1661 lpfc_els_free_iocb(phba, cmdiocb);
1662 return;
1663}
1664/**
James Smart3621a712009-04-06 18:47:14 -04001665 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001666 * @phba: pointer to lpfc hba data structure.
1667 * @cmdiocb: pointer to lpfc command iocb data structure.
1668 * @rspiocb: pointer to lpfc response iocb data structure.
1669 *
1670 * This routine is the completion callback function for issuing the Port
1671 * Login (PLOGI) command. For PLOGI completion, there must be an active
1672 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001673 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001674 * ignored and command IOCB released. The PLOGI response IOCB status is
1675 * checked for error conditons. If there is error status reported, PLOGI
1676 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1677 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1678 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1679 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1680 * there are additional N_Port nodes with the vport that need to perform
1681 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1682 * PLOGIs.
1683 **/
dea31012005-04-17 16:05:31 -05001684static void
James Smart2e0fef82007-06-17 19:56:36 -05001685lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1686 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001687{
James Smart2e0fef82007-06-17 19:56:36 -05001688 struct lpfc_vport *vport = cmdiocb->vport;
1689 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001690 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001691 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001692 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001693 int disc, rc, did, type;
1694
dea31012005-04-17 16:05:31 -05001695 /* we pass cmdiocb to state machine which needs rspiocb as well */
1696 cmdiocb->context_un.rsp_iocb = rspiocb;
1697
1698 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001699 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1700 "PLOGI cmpl: status:x%x/x%x did:x%x",
1701 irsp->ulpStatus, irsp->un.ulpWord[4],
1702 irsp->un.elsreq64.remoteID);
1703
James Smart2e0fef82007-06-17 19:56:36 -05001704 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001705 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001706 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1707 "0136 PLOGI completes to NPort x%x "
1708 "with no ndlp. Data: x%x x%x x%x\n",
1709 irsp->un.elsreq64.remoteID,
1710 irsp->ulpStatus, irsp->un.ulpWord[4],
1711 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001712 goto out;
James Smarted957682007-06-17 19:56:37 -05001713 }
dea31012005-04-17 16:05:31 -05001714
1715 /* Since ndlp can be freed in the disc state machine, note if this node
1716 * is being used during discovery.
1717 */
James Smart2e0fef82007-06-17 19:56:36 -05001718 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001719 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001720 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001721 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001722 rc = 0;
1723
1724 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001725 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1726 "0102 PLOGI completes to NPort x%x "
1727 "Data: x%x x%x x%x x%x x%x\n",
1728 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1729 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001730 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001731 if (lpfc_els_chk_latt(vport)) {
1732 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001733 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001734 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001735 goto out;
1736 }
1737
1738 /* ndlp could be freed in DSM, save these values now */
1739 type = ndlp->nlp_type;
1740 did = ndlp->nlp_DID;
1741
1742 if (irsp->ulpStatus) {
1743 /* Check for retry */
1744 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1745 /* ELS command is being retried */
1746 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001747 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001748 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001749 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001750 }
1751 goto out;
1752 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001753 /* PLOGI failed Don't print the vport to vport rjts */
1754 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1755 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1756 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1757 (phba)->pport->cfg_log_verbose & LOG_ELS)
1758 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001759 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1760 ndlp->nlp_DID, irsp->ulpStatus,
1761 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001762 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001763 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001764 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001765 else
James Smart2e0fef82007-06-17 19:56:36 -05001766 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001767 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001768 } else {
1769 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001770 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001771 cmdiocb->context2)->list.next,
1772 struct lpfc_dmabuf, list);
1773 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001774 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001775 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001776 }
1777
James Smart2e0fef82007-06-17 19:56:36 -05001778 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001779 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001780 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001781
James Smart2e0fef82007-06-17 19:56:36 -05001782 if (vport->num_disc_nodes == 0) {
1783 spin_lock_irq(shost->host_lock);
1784 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1785 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001786
James Smart2e0fef82007-06-17 19:56:36 -05001787 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001788 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001789 }
1790 }
1791
1792out:
1793 lpfc_els_free_iocb(phba, cmdiocb);
1794 return;
1795}
1796
James Smarte59058c2008-08-24 21:49:00 -04001797/**
James Smart3621a712009-04-06 18:47:14 -04001798 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001799 * @vport: pointer to a host virtual N_Port data structure.
1800 * @did: destination port identifier.
1801 * @retry: number of retries to the command IOCB.
1802 *
1803 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1804 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1805 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1806 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1807 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1808 *
1809 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1810 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1811 * will be stored into the context1 field of the IOCB for the completion
1812 * callback function to the PLOGI ELS command.
1813 *
1814 * Return code
1815 * 0 - Successfully issued a plogi for @vport
1816 * 1 - failed to issue a plogi for @vport
1817 **/
dea31012005-04-17 16:05:31 -05001818int
James Smart2e0fef82007-06-17 19:56:36 -05001819lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001820{
James Smart2e0fef82007-06-17 19:56:36 -05001821 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001822 struct serv_parm *sp;
1823 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001824 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001825 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001826 struct lpfc_sli *psli;
1827 uint8_t *pcmd;
1828 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001829 int ret;
dea31012005-04-17 16:05:31 -05001830
1831 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001832
James Smart98c9ea52007-10-27 13:37:33 -04001833 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001834 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1835 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001836
James Smarte47c9092008-02-08 18:49:26 -05001837 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001838 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001839 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001840 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001841 if (!elsiocb)
1842 return 1;
dea31012005-04-17 16:05:31 -05001843
1844 icmd = &elsiocb->iocb;
1845 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1846
1847 /* For PLOGI request, remainder of payload is service parameters */
1848 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001849 pcmd += sizeof(uint32_t);
1850 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001851 sp = (struct serv_parm *) pcmd;
1852
James Smart5ac6b302010-10-22 11:05:36 -04001853 /*
1854 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1855 * to device on remote loops work.
1856 */
1857 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1858 sp->cmn.altBbCredit = 1;
1859
dea31012005-04-17 16:05:31 -05001860 if (sp->cmn.fcphLow < FC_PH_4_3)
1861 sp->cmn.fcphLow = FC_PH_4_3;
1862
1863 if (sp->cmn.fcphHigh < FC_PH3)
1864 sp->cmn.fcphHigh = FC_PH3;
1865
James Smart858c9f62007-06-17 19:56:39 -05001866 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1867 "Issue PLOGI: did:x%x",
1868 did, 0, 0);
1869
dea31012005-04-17 16:05:31 -05001870 phba->fc_stat.elsXmitPLOGI++;
1871 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001872 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001873
1874 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001875 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001876 return 1;
dea31012005-04-17 16:05:31 -05001877 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001878 return 0;
dea31012005-04-17 16:05:31 -05001879}
1880
James Smarte59058c2008-08-24 21:49:00 -04001881/**
James Smart3621a712009-04-06 18:47:14 -04001882 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001883 * @phba: pointer to lpfc hba data structure.
1884 * @cmdiocb: pointer to lpfc command iocb data structure.
1885 * @rspiocb: pointer to lpfc response iocb data structure.
1886 *
1887 * This routine is the completion callback function for a Process Login
1888 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1889 * status. If there is error status reported, PRLI retry shall be attempted
1890 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1891 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1892 * ndlp to mark the PRLI completion.
1893 **/
dea31012005-04-17 16:05:31 -05001894static void
James Smart2e0fef82007-06-17 19:56:36 -05001895lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1896 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001897{
James Smart2e0fef82007-06-17 19:56:36 -05001898 struct lpfc_vport *vport = cmdiocb->vport;
1899 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001900 IOCB_t *irsp;
1901 struct lpfc_sli *psli;
1902 struct lpfc_nodelist *ndlp;
1903
1904 psli = &phba->sli;
1905 /* we pass cmdiocb to state machine which needs rspiocb as well */
1906 cmdiocb->context_un.rsp_iocb = rspiocb;
1907
1908 irsp = &(rspiocb->iocb);
1909 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001910 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001911 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001912 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001913
James Smart858c9f62007-06-17 19:56:39 -05001914 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1915 "PRLI cmpl: status:x%x/x%x did:x%x",
1916 irsp->ulpStatus, irsp->un.ulpWord[4],
1917 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001918 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001919 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1920 "0103 PRLI completes to NPort x%x "
1921 "Data: x%x x%x x%x x%x\n",
1922 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1923 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001924
James Smart2e0fef82007-06-17 19:56:36 -05001925 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001926 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001927 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001928 goto out;
1929
1930 if (irsp->ulpStatus) {
1931 /* Check for retry */
1932 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1933 /* ELS command is being retried */
1934 goto out;
1935 }
1936 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001937 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1938 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1939 ndlp->nlp_DID, irsp->ulpStatus,
1940 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001941 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001942 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001943 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001944 else
James Smart2e0fef82007-06-17 19:56:36 -05001945 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001946 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001947 } else
dea31012005-04-17 16:05:31 -05001948 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001949 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001950 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001951out:
1952 lpfc_els_free_iocb(phba, cmdiocb);
1953 return;
1954}
1955
James Smarte59058c2008-08-24 21:49:00 -04001956/**
James Smart3621a712009-04-06 18:47:14 -04001957 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001958 * @vport: pointer to a host virtual N_Port data structure.
1959 * @ndlp: pointer to a node-list data structure.
1960 * @retry: number of retries to the command IOCB.
1961 *
1962 * This routine issues a Process Login (PRLI) ELS command for the
1963 * @vport. The PRLI service parameters are set up in the payload of the
1964 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1965 * is put to the IOCB completion callback func field before invoking the
1966 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1967 *
1968 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1969 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1970 * will be stored into the context1 field of the IOCB for the completion
1971 * callback function to the PRLI ELS command.
1972 *
1973 * Return code
1974 * 0 - successfully issued prli iocb command for @vport
1975 * 1 - failed to issue prli iocb command for @vport
1976 **/
dea31012005-04-17 16:05:31 -05001977int
James Smart2e0fef82007-06-17 19:56:36 -05001978lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001979 uint8_t retry)
1980{
James Smart2e0fef82007-06-17 19:56:36 -05001981 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1982 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001983 PRLI *npr;
1984 IOCB_t *icmd;
1985 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001986 uint8_t *pcmd;
1987 uint16_t cmdsize;
1988
James Smart92d7f7b2007-06-17 19:56:38 -05001989 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001990 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1991 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001992 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001993 return 1;
dea31012005-04-17 16:05:31 -05001994
1995 icmd = &elsiocb->iocb;
1996 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1997
1998 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001999 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05002000 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05002001 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002002
2003 /* For PRLI, remainder of payload is PRLI parameter page */
2004 npr = (PRLI *) pcmd;
2005 /*
2006 * If our firmware version is 3.20 or later,
2007 * set the following bits for FC-TAPE support.
2008 */
2009 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2010 npr->ConfmComplAllowed = 1;
2011 npr->Retry = 1;
2012 npr->TaskRetryIdReq = 1;
2013 }
2014 npr->estabImagePair = 1;
2015 npr->readXferRdyDis = 1;
2016
2017 /* For FCP support */
2018 npr->prliType = PRLI_FCP_TYPE;
2019 npr->initiatorFunc = 1;
2020
James Smart858c9f62007-06-17 19:56:39 -05002021 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2022 "Issue PRLI: did:x%x",
2023 ndlp->nlp_DID, 0, 0);
2024
dea31012005-04-17 16:05:31 -05002025 phba->fc_stat.elsXmitPRLI++;
2026 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05002027 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002028 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002029 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002030 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2031 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002032 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002033 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002034 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002035 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002036 return 1;
dea31012005-04-17 16:05:31 -05002037 }
James Smart2e0fef82007-06-17 19:56:36 -05002038 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002039 return 0;
dea31012005-04-17 16:05:31 -05002040}
2041
James Smarte59058c2008-08-24 21:49:00 -04002042/**
James Smart3621a712009-04-06 18:47:14 -04002043 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002044 * @vport: pointer to a host virtual N_Port data structure.
2045 *
2046 * This routine performs Registration State Change Notification (RSCN)
2047 * discovery for a @vport. If the @vport's node port recovery count is not
2048 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2049 * the nodes that need recovery. If none of the PLOGI were needed through
2050 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2051 * invoked to check and handle possible more RSCN came in during the period
2052 * of processing the current ones.
2053 **/
2054static void
2055lpfc_rscn_disc(struct lpfc_vport *vport)
2056{
2057 lpfc_can_disctmo(vport);
2058
2059 /* RSCN discovery */
2060 /* go thru NPR nodes and issue ELS PLOGIs */
2061 if (vport->fc_npr_cnt)
2062 if (lpfc_els_disc_plogi(vport))
2063 return;
2064
2065 lpfc_end_rscn(vport);
2066}
2067
2068/**
James Smart3621a712009-04-06 18:47:14 -04002069 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002070 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2071 *
2072 * This function is called when the final ADISC is completed during discovery.
2073 * This function handles clearing link attention or issuing reg_vpi depending
2074 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2075 * discovery.
2076 * This function is called with no locks held.
2077 **/
2078static void
2079lpfc_adisc_done(struct lpfc_vport *vport)
2080{
2081 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2082 struct lpfc_hba *phba = vport->phba;
2083
2084 /*
2085 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2086 * and continue discovery.
2087 */
2088 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002089 !(vport->fc_flag & FC_RSCN_MODE) &&
2090 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04002091 lpfc_issue_reg_vpi(phba, vport);
2092 return;
2093 }
2094 /*
2095 * For SLI2, we need to set port_state to READY
2096 * and continue discovery.
2097 */
2098 if (vport->port_state < LPFC_VPORT_READY) {
2099 /* If we get here, there is nothing to ADISC */
2100 if (vport->port_type == LPFC_PHYSICAL_PORT)
2101 lpfc_issue_clear_la(phba, vport);
2102 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2103 vport->num_disc_nodes = 0;
2104 /* go thru NPR list, issue ELS PLOGIs */
2105 if (vport->fc_npr_cnt)
2106 lpfc_els_disc_plogi(vport);
2107 if (!vport->num_disc_nodes) {
2108 spin_lock_irq(shost->host_lock);
2109 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2110 spin_unlock_irq(shost->host_lock);
2111 lpfc_can_disctmo(vport);
2112 lpfc_end_rscn(vport);
2113 }
2114 }
2115 vport->port_state = LPFC_VPORT_READY;
2116 } else
2117 lpfc_rscn_disc(vport);
2118}
2119
2120/**
James Smart3621a712009-04-06 18:47:14 -04002121 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002122 * @vport: pointer to a host virtual N_Port data structure.
2123 *
2124 * This routine determines whether there are more ndlps on a @vport
2125 * node list need to have Address Discover (ADISC) issued. If so, it will
2126 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2127 * remaining nodes which need to have ADISC sent.
2128 **/
James Smart0ff10d42008-01-11 01:52:36 -05002129void
James Smart2e0fef82007-06-17 19:56:36 -05002130lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002131{
2132 int sentadisc;
2133
James Smart2e0fef82007-06-17 19:56:36 -05002134 if (vport->num_disc_nodes)
2135 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002136 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002137 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2138 "0210 Continue discovery with %d ADISCs to go "
2139 "Data: x%x x%x x%x\n",
2140 vport->num_disc_nodes, vport->fc_adisc_cnt,
2141 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002142 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002143 if (vport->fc_flag & FC_NLP_MORE) {
2144 lpfc_set_disctmo(vport);
2145 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2146 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002147 }
James Smart90160e02008-08-24 21:49:45 -04002148 if (!vport->num_disc_nodes)
2149 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002150 return;
2151}
2152
James Smarte59058c2008-08-24 21:49:00 -04002153/**
James Smart3621a712009-04-06 18:47:14 -04002154 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002155 * @phba: pointer to lpfc hba data structure.
2156 * @cmdiocb: pointer to lpfc command iocb data structure.
2157 * @rspiocb: pointer to lpfc response iocb data structure.
2158 *
2159 * This routine is the completion function for issuing the Address Discover
2160 * (ADISC) command. It first checks to see whether link went down during
2161 * the discovery process. If so, the node will be marked as node port
2162 * recovery for issuing discover IOCB by the link attention handler and
2163 * exit. Otherwise, the response status is checked. If error was reported
2164 * in the response status, the ADISC command shall be retried by invoking
2165 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2166 * the response status, the state machine is invoked to set transition
2167 * with respect to NLP_EVT_CMPL_ADISC event.
2168 **/
dea31012005-04-17 16:05:31 -05002169static void
James Smart2e0fef82007-06-17 19:56:36 -05002170lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2171 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002172{
James Smart2e0fef82007-06-17 19:56:36 -05002173 struct lpfc_vport *vport = cmdiocb->vport;
2174 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002175 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002176 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002177 int disc;
dea31012005-04-17 16:05:31 -05002178
2179 /* we pass cmdiocb to state machine which needs rspiocb as well */
2180 cmdiocb->context_un.rsp_iocb = rspiocb;
2181
2182 irsp = &(rspiocb->iocb);
2183 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002184
James Smart858c9f62007-06-17 19:56:39 -05002185 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2186 "ADISC cmpl: status:x%x/x%x did:x%x",
2187 irsp->ulpStatus, irsp->un.ulpWord[4],
2188 ndlp->nlp_DID);
2189
dea31012005-04-17 16:05:31 -05002190 /* Since ndlp can be freed in the disc state machine, note if this node
2191 * is being used during discovery.
2192 */
James Smart2e0fef82007-06-17 19:56:36 -05002193 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002194 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002195 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002196 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002197 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002198 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2199 "0104 ADISC completes to NPort x%x "
2200 "Data: x%x x%x x%x x%x x%x\n",
2201 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2202 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002203 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002204 if (lpfc_els_chk_latt(vport)) {
2205 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002206 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002207 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002208 goto out;
2209 }
2210
2211 if (irsp->ulpStatus) {
2212 /* Check for retry */
2213 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2214 /* ELS command is being retried */
2215 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002216 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002217 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002218 spin_unlock_irq(shost->host_lock);
2219 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002220 }
2221 goto out;
2222 }
2223 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002224 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2225 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2226 ndlp->nlp_DID, irsp->ulpStatus,
2227 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002228 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002229 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002230 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002231 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002232 } else
dea31012005-04-17 16:05:31 -05002233 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002234 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002235 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002236
James Smart90160e02008-08-24 21:49:45 -04002237 /* Check to see if there are more ADISCs to be sent */
2238 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002239 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002240out:
2241 lpfc_els_free_iocb(phba, cmdiocb);
2242 return;
2243}
2244
James Smarte59058c2008-08-24 21:49:00 -04002245/**
James Smart3621a712009-04-06 18:47:14 -04002246 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002247 * @vport: pointer to a virtual N_Port data structure.
2248 * @ndlp: pointer to a node-list data structure.
2249 * @retry: number of retries to the command IOCB.
2250 *
2251 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2252 * @vport. It prepares the payload of the ADISC ELS command, updates the
2253 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2254 * to issue the ADISC ELS command.
2255 *
2256 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2257 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2258 * will be stored into the context1 field of the IOCB for the completion
2259 * callback function to the ADISC ELS command.
2260 *
2261 * Return code
2262 * 0 - successfully issued adisc
2263 * 1 - failed to issue adisc
2264 **/
dea31012005-04-17 16:05:31 -05002265int
James Smart2e0fef82007-06-17 19:56:36 -05002266lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002267 uint8_t retry)
2268{
James Smart2e0fef82007-06-17 19:56:36 -05002269 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2270 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002271 ADISC *ap;
2272 IOCB_t *icmd;
2273 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002274 uint8_t *pcmd;
2275 uint16_t cmdsize;
2276
James Smart92d7f7b2007-06-17 19:56:38 -05002277 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002278 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2279 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002280 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002281 return 1;
dea31012005-04-17 16:05:31 -05002282
2283 icmd = &elsiocb->iocb;
2284 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2285
2286 /* For ADISC request, remainder of payload is service parameters */
2287 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002288 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002289
2290 /* Fill in ADISC payload */
2291 ap = (ADISC *) pcmd;
2292 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002293 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2294 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002295 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002296
James Smart858c9f62007-06-17 19:56:39 -05002297 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2298 "Issue ADISC: did:x%x",
2299 ndlp->nlp_DID, 0, 0);
2300
dea31012005-04-17 16:05:31 -05002301 phba->fc_stat.elsXmitADISC++;
2302 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002303 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002304 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002305 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002306 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2307 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002308 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002309 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002310 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002311 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002312 return 1;
dea31012005-04-17 16:05:31 -05002313 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002314 return 0;
dea31012005-04-17 16:05:31 -05002315}
2316
James Smarte59058c2008-08-24 21:49:00 -04002317/**
James Smart3621a712009-04-06 18:47:14 -04002318 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002319 * @phba: pointer to lpfc hba data structure.
2320 * @cmdiocb: pointer to lpfc command iocb data structure.
2321 * @rspiocb: pointer to lpfc response iocb data structure.
2322 *
2323 * This routine is the completion function for issuing the ELS Logout (LOGO)
2324 * command. If no error status was reported from the LOGO response, the
2325 * state machine of the associated ndlp shall be invoked for transition with
2326 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2327 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2328 **/
dea31012005-04-17 16:05:31 -05002329static void
James Smart2e0fef82007-06-17 19:56:36 -05002330lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2331 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002332{
James Smart2e0fef82007-06-17 19:56:36 -05002333 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2334 struct lpfc_vport *vport = ndlp->vport;
2335 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002336 IOCB_t *irsp;
2337 struct lpfc_sli *psli;
James Smart92494142011-02-16 12:39:44 -05002338 struct lpfcMboxq *mbox;
dea31012005-04-17 16:05:31 -05002339
2340 psli = &phba->sli;
2341 /* we pass cmdiocb to state machine which needs rspiocb as well */
2342 cmdiocb->context_un.rsp_iocb = rspiocb;
2343
2344 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002345 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002346 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002347 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002348
James Smart858c9f62007-06-17 19:56:39 -05002349 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2350 "LOGO cmpl: status:x%x/x%x did:x%x",
2351 irsp->ulpStatus, irsp->un.ulpWord[4],
2352 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002353 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002354 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2355 "0105 LOGO completes to NPort x%x "
2356 "Data: x%x x%x x%x x%x\n",
2357 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2358 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002359 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002360 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002361 goto out;
2362
James Smart92d7f7b2007-06-17 19:56:38 -05002363 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2364 /* NLP_EVT_DEVICE_RM should unregister the RPI
2365 * which should abort all outstanding IOs.
2366 */
2367 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2368 NLP_EVT_DEVICE_RM);
2369 goto out;
2370 }
2371
dea31012005-04-17 16:05:31 -05002372 if (irsp->ulpStatus) {
2373 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002374 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002375 /* ELS command is being retried */
2376 goto out;
dea31012005-04-17 16:05:31 -05002377 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002378 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2379 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2380 ndlp->nlp_DID, irsp->ulpStatus,
2381 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002382 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002383 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002384 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002385 else
James Smart2e0fef82007-06-17 19:56:36 -05002386 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002387 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002388 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002389 /* Good status, call state machine.
2390 * This will unregister the rpi if needed.
2391 */
James Smart2e0fef82007-06-17 19:56:36 -05002392 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002393 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002394out:
2395 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002396 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2397 if ((vport->fc_flag & FC_PT2PT) &&
2398 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2399 phba->pport->fc_myDID = 0;
2400 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2401 if (mbox) {
2402 lpfc_config_link(phba, mbox);
2403 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2404 mbox->vport = vport;
2405 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2406 MBX_NOT_FINISHED) {
2407 mempool_free(mbox, phba->mbox_mem_pool);
2408 }
2409 }
2410 }
dea31012005-04-17 16:05:31 -05002411 return;
2412}
2413
James Smarte59058c2008-08-24 21:49:00 -04002414/**
James Smart3621a712009-04-06 18:47:14 -04002415 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002416 * @vport: pointer to a virtual N_Port data structure.
2417 * @ndlp: pointer to a node-list data structure.
2418 * @retry: number of retries to the command IOCB.
2419 *
2420 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2421 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2422 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2423 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2424 *
2425 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2426 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2427 * will be stored into the context1 field of the IOCB for the completion
2428 * callback function to the LOGO ELS command.
2429 *
2430 * Return code
2431 * 0 - successfully issued logo
2432 * 1 - failed to issue logo
2433 **/
dea31012005-04-17 16:05:31 -05002434int
James Smart2e0fef82007-06-17 19:56:36 -05002435lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002436 uint8_t retry)
2437{
James Smart2e0fef82007-06-17 19:56:36 -05002438 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2439 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002440 IOCB_t *icmd;
2441 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002442 uint8_t *pcmd;
2443 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002444 int rc;
dea31012005-04-17 16:05:31 -05002445
James Smart98c9ea52007-10-27 13:37:33 -04002446 spin_lock_irq(shost->host_lock);
2447 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2448 spin_unlock_irq(shost->host_lock);
2449 return 0;
2450 }
2451 spin_unlock_irq(shost->host_lock);
2452
James Smart92d7f7b2007-06-17 19:56:38 -05002453 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002454 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2455 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002456 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002457 return 1;
dea31012005-04-17 16:05:31 -05002458
2459 icmd = &elsiocb->iocb;
2460 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2461 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002462 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002463
2464 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002465 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002466 pcmd += sizeof(uint32_t);
2467 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002468
James Smart858c9f62007-06-17 19:56:39 -05002469 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2470 "Issue LOGO: did:x%x",
2471 ndlp->nlp_DID, 0, 0);
2472
dea31012005-04-17 16:05:31 -05002473 phba->fc_stat.elsXmitLOGO++;
2474 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002475 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002476 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002477 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002478 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002479
2480 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002481 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002482 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002483 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002484 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002485 return 1;
dea31012005-04-17 16:05:31 -05002486 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002487 return 0;
dea31012005-04-17 16:05:31 -05002488}
2489
James Smarte59058c2008-08-24 21:49:00 -04002490/**
James Smart3621a712009-04-06 18:47:14 -04002491 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002492 * @phba: pointer to lpfc hba data structure.
2493 * @cmdiocb: pointer to lpfc command iocb data structure.
2494 * @rspiocb: pointer to lpfc response iocb data structure.
2495 *
2496 * This routine is a generic completion callback function for ELS commands.
2497 * Specifically, it is the callback function which does not need to perform
2498 * any command specific operations. It is currently used by the ELS command
2499 * issuing routines for the ELS State Change Request (SCR),
2500 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2501 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2502 * certain debug loggings, this callback function simply invokes the
2503 * lpfc_els_chk_latt() routine to check whether link went down during the
2504 * discovery process.
2505 **/
dea31012005-04-17 16:05:31 -05002506static void
James Smart2e0fef82007-06-17 19:56:36 -05002507lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2508 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002509{
James Smart2e0fef82007-06-17 19:56:36 -05002510 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002511 IOCB_t *irsp;
2512
2513 irsp = &rspiocb->iocb;
2514
James Smart858c9f62007-06-17 19:56:39 -05002515 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2516 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2517 irsp->ulpStatus, irsp->un.ulpWord[4],
2518 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002519 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002520 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2521 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2522 irsp->ulpIoTag, irsp->ulpStatus,
2523 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002524 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002525 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002526 lpfc_els_free_iocb(phba, cmdiocb);
2527 return;
2528}
2529
James Smarte59058c2008-08-24 21:49:00 -04002530/**
James Smart3621a712009-04-06 18:47:14 -04002531 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002532 * @vport: pointer to a host virtual N_Port data structure.
2533 * @nportid: N_Port identifier to the remote node.
2534 * @retry: number of retries to the command IOCB.
2535 *
2536 * This routine issues a State Change Request (SCR) to a fabric node
2537 * on a @vport. The remote node @nportid is passed into the function. It
2538 * first search the @vport node list to find the matching ndlp. If no such
2539 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2540 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2541 * routine is invoked to send the SCR IOCB.
2542 *
2543 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2544 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2545 * will be stored into the context1 field of the IOCB for the completion
2546 * callback function to the SCR ELS command.
2547 *
2548 * Return code
2549 * 0 - Successfully issued scr command
2550 * 1 - Failed to issue scr command
2551 **/
dea31012005-04-17 16:05:31 -05002552int
James Smart2e0fef82007-06-17 19:56:36 -05002553lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002554{
James Smart2e0fef82007-06-17 19:56:36 -05002555 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002556 IOCB_t *icmd;
2557 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002558 struct lpfc_sli *psli;
2559 uint8_t *pcmd;
2560 uint16_t cmdsize;
2561 struct lpfc_nodelist *ndlp;
2562
2563 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002564 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002565
James Smarte47c9092008-02-08 18:49:26 -05002566 ndlp = lpfc_findnode_did(vport, nportid);
2567 if (!ndlp) {
2568 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2569 if (!ndlp)
2570 return 1;
2571 lpfc_nlp_init(vport, ndlp, nportid);
2572 lpfc_enqueue_node(vport, ndlp);
2573 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2574 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2575 if (!ndlp)
2576 return 1;
2577 }
dea31012005-04-17 16:05:31 -05002578
James Smart2e0fef82007-06-17 19:56:36 -05002579 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2580 ndlp->nlp_DID, ELS_CMD_SCR);
2581
James Smart488d1462006-03-07 15:02:37 -05002582 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002583 /* This will trigger the release of the node just
2584 * allocated
2585 */
James Smart329f9bc2007-04-25 09:53:01 -04002586 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002587 return 1;
dea31012005-04-17 16:05:31 -05002588 }
2589
2590 icmd = &elsiocb->iocb;
2591 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2592
2593 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002594 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002595
2596 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002597 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002598 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2599
James Smart858c9f62007-06-17 19:56:39 -05002600 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2601 "Issue SCR: did:x%x",
2602 ndlp->nlp_DID, 0, 0);
2603
dea31012005-04-17 16:05:31 -05002604 phba->fc_stat.elsXmitSCR++;
2605 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002606 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2607 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002608 /* The additional lpfc_nlp_put will cause the following
2609 * lpfc_els_free_iocb routine to trigger the rlease of
2610 * the node.
2611 */
James Smart329f9bc2007-04-25 09:53:01 -04002612 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002613 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002614 return 1;
dea31012005-04-17 16:05:31 -05002615 }
James Smartfa4066b2008-01-11 01:53:27 -05002616 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2617 * trigger the release of node.
2618 */
James Smart329f9bc2007-04-25 09:53:01 -04002619 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002620 return 0;
dea31012005-04-17 16:05:31 -05002621}
2622
James Smarte59058c2008-08-24 21:49:00 -04002623/**
James Smart3621a712009-04-06 18:47:14 -04002624 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002625 * @vport: pointer to a host virtual N_Port data structure.
2626 * @nportid: N_Port identifier to the remote node.
2627 * @retry: number of retries to the command IOCB.
2628 *
2629 * This routine issues a Fibre Channel Address Resolution Response
2630 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2631 * is passed into the function. It first search the @vport node list to find
2632 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2633 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2634 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2635 *
2636 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2637 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2638 * will be stored into the context1 field of the IOCB for the completion
2639 * callback function to the PARPR ELS command.
2640 *
2641 * Return code
2642 * 0 - Successfully issued farpr command
2643 * 1 - Failed to issue farpr command
2644 **/
dea31012005-04-17 16:05:31 -05002645static int
James Smart2e0fef82007-06-17 19:56:36 -05002646lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002647{
James Smart2e0fef82007-06-17 19:56:36 -05002648 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002649 IOCB_t *icmd;
2650 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002651 struct lpfc_sli *psli;
2652 FARP *fp;
2653 uint8_t *pcmd;
2654 uint32_t *lp;
2655 uint16_t cmdsize;
2656 struct lpfc_nodelist *ondlp;
2657 struct lpfc_nodelist *ndlp;
2658
2659 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002660 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002661
James Smarte47c9092008-02-08 18:49:26 -05002662 ndlp = lpfc_findnode_did(vport, nportid);
2663 if (!ndlp) {
2664 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2665 if (!ndlp)
2666 return 1;
2667 lpfc_nlp_init(vport, ndlp, nportid);
2668 lpfc_enqueue_node(vport, ndlp);
2669 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2670 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2671 if (!ndlp)
2672 return 1;
2673 }
James Smart2e0fef82007-06-17 19:56:36 -05002674
2675 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2676 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002677 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002678 /* This will trigger the release of the node just
2679 * allocated
2680 */
James Smart329f9bc2007-04-25 09:53:01 -04002681 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002682 return 1;
dea31012005-04-17 16:05:31 -05002683 }
2684
2685 icmd = &elsiocb->iocb;
2686 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2687
2688 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002689 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002690
2691 /* Fill in FARPR payload */
2692 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002693 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002694 lp = (uint32_t *) pcmd;
2695 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002696 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002697 fp->Rflags = 0;
2698 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2699
James Smart92d7f7b2007-06-17 19:56:38 -05002700 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2701 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002702 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002703 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002704 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002705 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002706 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002707 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002708 }
2709
James Smart858c9f62007-06-17 19:56:39 -05002710 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2711 "Issue FARPR: did:x%x",
2712 ndlp->nlp_DID, 0, 0);
2713
dea31012005-04-17 16:05:31 -05002714 phba->fc_stat.elsXmitFARPR++;
2715 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002716 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2717 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002718 /* The additional lpfc_nlp_put will cause the following
2719 * lpfc_els_free_iocb routine to trigger the release of
2720 * the node.
2721 */
James Smart329f9bc2007-04-25 09:53:01 -04002722 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002723 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002724 return 1;
dea31012005-04-17 16:05:31 -05002725 }
James Smartfa4066b2008-01-11 01:53:27 -05002726 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2727 * trigger the release of the node.
2728 */
James Smart329f9bc2007-04-25 09:53:01 -04002729 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002730 return 0;
dea31012005-04-17 16:05:31 -05002731}
2732
James Smarte59058c2008-08-24 21:49:00 -04002733/**
James Smart3621a712009-04-06 18:47:14 -04002734 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002735 * @vport: pointer to a host virtual N_Port data structure.
2736 * @nlp: pointer to a node-list data structure.
2737 *
2738 * This routine cancels the timer with a delayed IOCB-command retry for
2739 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2740 * removes the ELS retry event if it presents. In addition, if the
2741 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2742 * commands are sent for the @vport's nodes that require issuing discovery
2743 * ADISC.
2744 **/
dea31012005-04-17 16:05:31 -05002745void
James Smart2e0fef82007-06-17 19:56:36 -05002746lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002747{
James Smart2e0fef82007-06-17 19:56:36 -05002748 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002749 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002750
James Smart0d2b6b82008-06-14 22:52:47 -04002751 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2752 return;
James Smart2e0fef82007-06-17 19:56:36 -05002753 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002754 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002755 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002756 del_timer_sync(&nlp->nlp_delayfunc);
2757 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002758 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002759 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002760 /* Decrement nlp reference count held for the delayed retry */
2761 evtp = &nlp->els_retry_evt;
2762 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2763 }
James Smartfdcebe22006-03-07 15:04:01 -05002764 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002765 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002766 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002767 spin_unlock_irq(shost->host_lock);
2768 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002769 if (vport->port_state < LPFC_VPORT_READY) {
2770 /* Check if there are more ADISCs to be sent */
2771 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002772 } else {
2773 /* Check if there are more PLOGIs to be sent */
2774 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002775 if (vport->num_disc_nodes == 0) {
2776 spin_lock_irq(shost->host_lock);
2777 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2778 spin_unlock_irq(shost->host_lock);
2779 lpfc_can_disctmo(vport);
2780 lpfc_end_rscn(vport);
2781 }
James Smartfdcebe22006-03-07 15:04:01 -05002782 }
2783 }
2784 }
2785 return;
2786}
2787
James Smarte59058c2008-08-24 21:49:00 -04002788/**
James Smart3621a712009-04-06 18:47:14 -04002789 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002790 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2791 *
2792 * This routine is invoked by the ndlp delayed-function timer to check
2793 * whether there is any pending ELS retry event(s) with the node. If not, it
2794 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2795 * adds the delayed events to the HBA work list and invokes the
2796 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2797 * event. Note that lpfc_nlp_get() is called before posting the event to
2798 * the work list to hold reference count of ndlp so that it guarantees the
2799 * reference to ndlp will still be available when the worker thread gets
2800 * to the event associated with the ndlp.
2801 **/
James Smartfdcebe22006-03-07 15:04:01 -05002802void
dea31012005-04-17 16:05:31 -05002803lpfc_els_retry_delay(unsigned long ptr)
2804{
James Smart2e0fef82007-06-17 19:56:36 -05002805 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2806 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002807 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002808 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002809 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002810
James Smart92d7f7b2007-06-17 19:56:38 -05002811 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002812 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002813 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002814 return;
2815 }
2816
James Smartfa4066b2008-01-11 01:53:27 -05002817 /* We need to hold the node by incrementing the reference
2818 * count until the queued work is done
2819 */
2820 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002821 if (evtp->evt_arg1) {
2822 evtp->evt = LPFC_EVT_ELS_RETRY;
2823 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002824 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002825 }
James Smart92d7f7b2007-06-17 19:56:38 -05002826 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002827 return;
2828}
2829
James Smarte59058c2008-08-24 21:49:00 -04002830/**
James Smart3621a712009-04-06 18:47:14 -04002831 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002832 * @ndlp: pointer to a node-list data structure.
2833 *
2834 * This routine is the worker-thread handler for processing the @ndlp delayed
2835 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2836 * the last ELS command from the associated ndlp and invokes the proper ELS
2837 * function according to the delayed ELS command to retry the command.
2838 **/
dea31012005-04-17 16:05:31 -05002839void
2840lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2841{
James Smart2e0fef82007-06-17 19:56:36 -05002842 struct lpfc_vport *vport = ndlp->vport;
2843 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2844 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002845
James Smart2e0fef82007-06-17 19:56:36 -05002846 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002847 did = ndlp->nlp_DID;
2848 cmd = ndlp->nlp_last_elscmd;
2849 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002850
2851 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002852 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002853 return;
2854 }
2855
2856 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002857 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002858 /*
2859 * If a discovery event readded nlp_delayfunc after timer
2860 * firing and before processing the timer, cancel the
2861 * nlp_delayfunc.
2862 */
2863 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002864 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002865 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002866
2867 switch (cmd) {
2868 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002869 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002870 break;
2871 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002872 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002873 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002874 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002875 }
dea31012005-04-17 16:05:31 -05002876 break;
2877 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002878 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002879 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002880 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002881 }
dea31012005-04-17 16:05:31 -05002882 break;
2883 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002884 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002885 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002886 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002887 }
dea31012005-04-17 16:05:31 -05002888 break;
2889 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002890 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002891 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002892 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002893 }
dea31012005-04-17 16:05:31 -05002894 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002895 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05002896 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
2897 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05002898 break;
dea31012005-04-17 16:05:31 -05002899 }
2900 return;
2901}
2902
James Smarte59058c2008-08-24 21:49:00 -04002903/**
James Smart3621a712009-04-06 18:47:14 -04002904 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002905 * @phba: pointer to lpfc hba data structure.
2906 * @cmdiocb: pointer to lpfc command iocb data structure.
2907 * @rspiocb: pointer to lpfc response iocb data structure.
2908 *
2909 * This routine makes a retry decision on an ELS command IOCB, which has
2910 * failed. The following ELS IOCBs use this function for retrying the command
2911 * when previously issued command responsed with error status: FLOGI, PLOGI,
2912 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2913 * returned error status, it makes the decision whether a retry shall be
2914 * issued for the command, and whether a retry shall be made immediately or
2915 * delayed. In the former case, the corresponding ELS command issuing-function
2916 * is called to retry the command. In the later case, the ELS command shall
2917 * be posted to the ndlp delayed event and delayed function timer set to the
2918 * ndlp for the delayed command issusing.
2919 *
2920 * Return code
2921 * 0 - No retry of els command is made
2922 * 1 - Immediate or delayed retry of els command is made
2923 **/
dea31012005-04-17 16:05:31 -05002924static int
James Smart2e0fef82007-06-17 19:56:36 -05002925lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2926 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002927{
James Smart2e0fef82007-06-17 19:56:36 -05002928 struct lpfc_vport *vport = cmdiocb->vport;
2929 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2930 IOCB_t *irsp = &rspiocb->iocb;
2931 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2932 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002933 uint32_t *elscmd;
2934 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002935 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002936 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002937 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002938 uint32_t did;
dea31012005-04-17 16:05:31 -05002939
James Smart488d1462006-03-07 15:02:37 -05002940
dea31012005-04-17 16:05:31 -05002941 /* Note: context2 may be 0 for internal driver abort
2942 * of delays ELS command.
2943 */
2944
2945 if (pcmd && pcmd->virt) {
2946 elscmd = (uint32_t *) (pcmd->virt);
2947 cmd = *elscmd++;
2948 }
2949
James Smarte47c9092008-02-08 18:49:26 -05002950 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002951 did = ndlp->nlp_DID;
2952 else {
2953 /* We should only hit this case for retrying PLOGI */
2954 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002955 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002956 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2957 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002958 return 1;
2959 }
2960
James Smart858c9f62007-06-17 19:56:39 -05002961 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2962 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2963 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2964
dea31012005-04-17 16:05:31 -05002965 switch (irsp->ulpStatus) {
2966 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05002967 break;
James Smart1151e3e2011-02-16 12:39:35 -05002968 case IOSTAT_REMOTE_STOP:
2969 if (phba->sli_rev == LPFC_SLI_REV4) {
2970 /* This IO was aborted by the target, we don't
2971 * know the rxid and because we did not send the
2972 * ABTS we cannot generate and RRQ.
2973 */
2974 lpfc_set_rrq_active(phba, ndlp,
2975 cmdiocb->sli4_xritag, 0, 0);
2976 }
2977 break;
dea31012005-04-17 16:05:31 -05002978 case IOSTAT_LOCAL_REJECT:
2979 switch ((irsp->un.ulpWord[4] & 0xff)) {
2980 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002981 if (cmd == ELS_CMD_FLOGI) {
2982 if (PCI_DEVICE_ID_HORNET ==
2983 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05002984 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05002985 phba->pport->fc_myDID = 0;
2986 phba->alpa_map[0] = 0;
2987 phba->alpa_map[1] = 0;
2988 }
2989 }
James Smart2e0fef82007-06-17 19:56:36 -05002990 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002991 delay = 1000;
dea31012005-04-17 16:05:31 -05002992 retry = 1;
2993 break;
2994
James Smart92d7f7b2007-06-17 19:56:38 -05002995 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002996 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2997 "0124 Retry illegal cmd x%x "
2998 "retry:x%x delay:x%x\n",
2999 cmd, cmdiocb->retry, delay);
3000 retry = 1;
3001 /* All command's retry policy */
3002 maxretry = 8;
3003 if (cmdiocb->retry > 2)
3004 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05003005 break;
3006
dea31012005-04-17 16:05:31 -05003007 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04003008 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05003009 retry = 1;
3010 if (cmdiocb->retry > 100)
3011 delay = 100;
3012 maxretry = 250;
3013 break;
3014
3015 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05003016 delay = 100;
dea31012005-04-17 16:05:31 -05003017 retry = 1;
3018 break;
3019
James Smart858c9f62007-06-17 19:56:39 -05003020 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05003021 case IOERR_INVALID_RPI:
3022 retry = 1;
3023 break;
3024 }
3025 break;
3026
3027 case IOSTAT_NPORT_RJT:
3028 case IOSTAT_FABRIC_RJT:
3029 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3030 retry = 1;
3031 break;
3032 }
3033 break;
3034
3035 case IOSTAT_NPORT_BSY:
3036 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04003037 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05003038 retry = 1;
3039 break;
3040
3041 case IOSTAT_LS_RJT:
3042 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3043 /* Added for Vendor specifc support
3044 * Just keep retrying for these Rsn / Exp codes
3045 */
3046 switch (stat.un.b.lsRjtRsnCode) {
3047 case LSRJT_UNABLE_TPC:
3048 if (stat.un.b.lsRjtRsnCodeExp ==
3049 LSEXP_CMD_IN_PROGRESS) {
3050 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003051 delay = 1000;
dea31012005-04-17 16:05:31 -05003052 maxretry = 48;
3053 }
3054 retry = 1;
3055 break;
3056 }
James Smartffc95492010-06-07 15:23:17 -04003057 if (stat.un.b.lsRjtRsnCodeExp ==
3058 LSEXP_CANT_GIVE_DATA) {
3059 if (cmd == ELS_CMD_PLOGI) {
3060 delay = 1000;
3061 maxretry = 48;
3062 }
3063 retry = 1;
3064 break;
3065 }
dea31012005-04-17 16:05:31 -05003066 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003067 delay = 1000;
dea31012005-04-17 16:05:31 -05003068 maxretry = lpfc_max_els_tries + 1;
3069 retry = 1;
3070 break;
3071 }
James Smart92d7f7b2007-06-17 19:56:38 -05003072 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3073 (cmd == ELS_CMD_FDISC) &&
3074 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003075 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3076 "0125 FDISC Failed (x%x). "
3077 "Fabric out of resources\n",
3078 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003079 lpfc_vport_set_state(vport,
3080 FC_VPORT_NO_FABRIC_RSCS);
3081 }
dea31012005-04-17 16:05:31 -05003082 break;
3083
3084 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003085 if ((cmd == ELS_CMD_PLOGI) ||
3086 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003087 delay = 1000;
dea31012005-04-17 16:05:31 -05003088 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003089 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003090 /* FDISC retry policy */
3091 maxretry = 48;
3092 if (cmdiocb->retry >= 32)
3093 delay = 1000;
dea31012005-04-17 16:05:31 -05003094 }
3095 retry = 1;
3096 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003097
3098 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003099 /* There are some cases where switches return this
3100 * error when they are not ready and should be returning
3101 * Logical Busy. We should delay every time.
3102 */
3103 if (cmd == ELS_CMD_FDISC &&
3104 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3105 maxretry = 3;
3106 delay = 1000;
3107 retry = 1;
3108 break;
3109 }
James Smart92d7f7b2007-06-17 19:56:38 -05003110 case LSRJT_PROTOCOL_ERR:
3111 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3112 (cmd == ELS_CMD_FDISC) &&
3113 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3114 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3115 ) {
James Smarte8b62012007-08-02 11:10:09 -04003116 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003117 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003118 "Fabric Detected Bad WWN\n",
3119 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003120 lpfc_vport_set_state(vport,
3121 FC_VPORT_FABRIC_REJ_WWN);
3122 }
3123 break;
dea31012005-04-17 16:05:31 -05003124 }
3125 break;
3126
3127 case IOSTAT_INTERMED_RSP:
3128 case IOSTAT_BA_RJT:
3129 break;
3130
3131 default:
3132 break;
3133 }
3134
James Smart488d1462006-03-07 15:02:37 -05003135 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003136 retry = 1;
dea31012005-04-17 16:05:31 -05003137
James Smartdf9e1b52011-12-13 13:22:17 -05003138 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05003139 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003140 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003141 /* FLOGI retry policy */
3142 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05003143 /* retry FLOGI forever */
James Smart6669f9b2009-10-02 15:16:45 -04003144 maxretry = 0;
3145 if (cmdiocb->retry >= 100)
3146 delay = 5000;
3147 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003148 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05003149 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3150 /* retry FDISCs every second up to devloss */
3151 retry = 1;
3152 maxretry = vport->cfg_devloss_tmo;
3153 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04003154 }
3155
James Smart6669f9b2009-10-02 15:16:45 -04003156 cmdiocb->retry++;
3157 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003158 phba->fc_stat.elsRetryExceeded++;
3159 retry = 0;
3160 }
3161
James Smarted957682007-06-17 19:56:37 -05003162 if ((vport->load_flag & FC_UNLOADING) != 0)
3163 retry = 0;
3164
dea31012005-04-17 16:05:31 -05003165 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003166 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3167 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3168 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3169 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3170 "2849 Stop retry ELS command "
3171 "x%x to remote NPORT x%x, "
3172 "Data: x%x x%x\n", cmd, did,
3173 cmdiocb->retry, delay);
3174 return 0;
3175 }
3176 }
dea31012005-04-17 16:05:31 -05003177
3178 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003179 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3180 "0107 Retry ELS command x%x to remote "
3181 "NPORT x%x Data: x%x x%x\n",
3182 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003183
James Smart858c9f62007-06-17 19:56:39 -05003184 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3185 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3186 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
3187 /* Don't reset timer for no resources */
3188
dea31012005-04-17 16:05:31 -05003189 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003190 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003191 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003192 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003193 }
3194
3195 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003196 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003197 phba->fc_stat.elsDelayRetry++;
3198 ndlp->nlp_retry = cmdiocb->retry;
3199
James Smart92d7f7b2007-06-17 19:56:38 -05003200 /* delay is specified in milliseconds */
3201 mod_timer(&ndlp->nlp_delayfunc,
3202 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003203 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003204 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003205 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003206
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003207 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003208 if (cmd == ELS_CMD_PRLI)
3209 lpfc_nlp_set_state(vport, ndlp,
3210 NLP_STE_REG_LOGIN_ISSUE);
3211 else
3212 lpfc_nlp_set_state(vport, ndlp,
3213 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003214 ndlp->nlp_last_elscmd = cmd;
3215
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003216 return 1;
dea31012005-04-17 16:05:31 -05003217 }
3218 switch (cmd) {
3219 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003220 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003221 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003222 case ELS_CMD_FDISC:
3223 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3224 return 1;
dea31012005-04-17 16:05:31 -05003225 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003226 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003227 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003228 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003229 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003230 }
James Smart2e0fef82007-06-17 19:56:36 -05003231 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003232 return 1;
dea31012005-04-17 16:05:31 -05003233 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003234 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003235 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3236 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003237 return 1;
dea31012005-04-17 16:05:31 -05003238 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003239 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003240 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3241 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003242 return 1;
dea31012005-04-17 16:05:31 -05003243 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003244 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003245 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3246 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003247 return 1;
dea31012005-04-17 16:05:31 -05003248 }
3249 }
dea31012005-04-17 16:05:31 -05003250 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003251 if (logerr) {
3252 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3253 "0137 No retry ELS command x%x to remote "
3254 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3255 cmd, did, irsp->ulpStatus,
3256 irsp->un.ulpWord[4]);
3257 }
3258 else {
3259 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003260 "0108 No retry ELS command x%x to remote "
3261 "NPORT x%x Retried:%d Error:x%x/%x\n",
3262 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3263 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003264 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003265 return 0;
dea31012005-04-17 16:05:31 -05003266}
3267
James Smarte59058c2008-08-24 21:49:00 -04003268/**
James Smart3621a712009-04-06 18:47:14 -04003269 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003270 * @phba: pointer to lpfc hba data structure.
3271 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3272 *
3273 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3274 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3275 * checks to see whether there is a lpfc DMA buffer associated with the
3276 * response of the command IOCB. If so, it will be released before releasing
3277 * the lpfc DMA buffer associated with the IOCB itself.
3278 *
3279 * Return code
3280 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3281 **/
James Smart09372822008-01-11 01:52:54 -05003282static int
James Smart87af33f2007-10-27 13:37:43 -04003283lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3284{
3285 struct lpfc_dmabuf *buf_ptr;
3286
James Smarte59058c2008-08-24 21:49:00 -04003287 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003288 if (!list_empty(&buf_ptr1->list)) {
3289 list_remove_head(&buf_ptr1->list, buf_ptr,
3290 struct lpfc_dmabuf,
3291 list);
3292 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3293 kfree(buf_ptr);
3294 }
3295 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3296 kfree(buf_ptr1);
3297 return 0;
3298}
3299
James Smarte59058c2008-08-24 21:49:00 -04003300/**
James Smart3621a712009-04-06 18:47:14 -04003301 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003302 * @phba: pointer to lpfc hba data structure.
3303 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3304 *
3305 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3306 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3307 * pool.
3308 *
3309 * Return code
3310 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3311 **/
James Smart09372822008-01-11 01:52:54 -05003312static int
James Smart87af33f2007-10-27 13:37:43 -04003313lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3314{
3315 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3316 kfree(buf_ptr);
3317 return 0;
3318}
3319
James Smarte59058c2008-08-24 21:49:00 -04003320/**
James Smart3621a712009-04-06 18:47:14 -04003321 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003322 * @phba: pointer to lpfc hba data structure.
3323 * @elsiocb: pointer to lpfc els command iocb data structure.
3324 *
3325 * This routine frees a command IOCB and its associated resources. The
3326 * command IOCB data structure contains the reference to various associated
3327 * resources, these fields must be set to NULL if the associated reference
3328 * not present:
3329 * context1 - reference to ndlp
3330 * context2 - reference to cmd
3331 * context2->next - reference to rsp
3332 * context3 - reference to bpl
3333 *
3334 * It first properly decrements the reference count held on ndlp for the
3335 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3336 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3337 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3338 * adds the DMA buffer the @phba data structure for the delayed release.
3339 * If reference to the Buffer Pointer List (BPL) is present, the
3340 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3341 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3342 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3343 *
3344 * Return code
3345 * 0 - Success (currently, always return 0)
3346 **/
James Smart87af33f2007-10-27 13:37:43 -04003347int
James Smart329f9bc2007-04-25 09:53:01 -04003348lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003349{
3350 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003351 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003352
James Smarta8adb832007-10-27 13:37:53 -04003353 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3354 if (ndlp) {
3355 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3356 lpfc_nlp_put(ndlp);
3357
3358 /* If the ndlp is not being used by another discovery
3359 * thread, free it.
3360 */
3361 if (!lpfc_nlp_not_used(ndlp)) {
3362 /* If ndlp is being used by another discovery
3363 * thread, just clear NLP_DEFER_RM
3364 */
3365 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3366 }
3367 }
3368 else
3369 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003370 elsiocb->context1 = NULL;
3371 }
dea31012005-04-17 16:05:31 -05003372 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3373 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003374 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3375 /* Firmware could still be in progress of DMAing
3376 * payload, so don't free data buffer till after
3377 * a hbeat.
3378 */
3379 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3380 buf_ptr = elsiocb->context2;
3381 elsiocb->context2 = NULL;
3382 if (buf_ptr) {
3383 buf_ptr1 = NULL;
3384 spin_lock_irq(&phba->hbalock);
3385 if (!list_empty(&buf_ptr->list)) {
3386 list_remove_head(&buf_ptr->list,
3387 buf_ptr1, struct lpfc_dmabuf,
3388 list);
3389 INIT_LIST_HEAD(&buf_ptr1->list);
3390 list_add_tail(&buf_ptr1->list,
3391 &phba->elsbuf);
3392 phba->elsbuf_cnt++;
3393 }
3394 INIT_LIST_HEAD(&buf_ptr->list);
3395 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3396 phba->elsbuf_cnt++;
3397 spin_unlock_irq(&phba->hbalock);
3398 }
3399 } else {
3400 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3401 lpfc_els_free_data(phba, buf_ptr1);
3402 }
dea31012005-04-17 16:05:31 -05003403 }
3404
3405 if (elsiocb->context3) {
3406 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003407 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003408 }
James Bottomley604a3e32005-10-29 10:28:33 -05003409 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003410 return 0;
3411}
3412
James Smarte59058c2008-08-24 21:49:00 -04003413/**
James Smart3621a712009-04-06 18:47:14 -04003414 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003415 * @phba: pointer to lpfc hba data structure.
3416 * @cmdiocb: pointer to lpfc command iocb data structure.
3417 * @rspiocb: pointer to lpfc response iocb data structure.
3418 *
3419 * This routine is the completion callback function to the Logout (LOGO)
3420 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3421 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3422 * release the ndlp if it has the last reference remaining (reference count
3423 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3424 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3425 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3426 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3427 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3428 * IOCB data structure.
3429 **/
dea31012005-04-17 16:05:31 -05003430static void
James Smart2e0fef82007-06-17 19:56:36 -05003431lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3432 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003433{
James Smart2e0fef82007-06-17 19:56:36 -05003434 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3435 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003436 IOCB_t *irsp;
3437
3438 irsp = &rspiocb->iocb;
3439 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3440 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3441 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003442 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003443 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3444 "0109 ACC to LOGO completes to NPort x%x "
3445 "Data: x%x x%x x%x\n",
3446 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3447 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003448
3449 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3450 /* NPort Recovery mode or node is just allocated */
3451 if (!lpfc_nlp_not_used(ndlp)) {
3452 /* If the ndlp is being used by another discovery
3453 * thread, just unregister the RPI.
3454 */
3455 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003456 } else {
3457 /* Indicate the node has already released, should
3458 * not reference to it from within lpfc_els_free_iocb.
3459 */
3460 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003461 }
dea31012005-04-17 16:05:31 -05003462 }
James Smart73d91e52011-10-10 21:32:10 -04003463
3464 /*
3465 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05003466 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04003467 */
dea31012005-04-17 16:05:31 -05003468 lpfc_els_free_iocb(phba, cmdiocb);
James Smartdf9e1b52011-12-13 13:22:17 -05003469
3470 /*
3471 * Remove the ndlp reference if it's a fabric node that has
3472 * sent us an unsolicted LOGO.
3473 */
3474 if (ndlp->nlp_type & NLP_FABRIC)
3475 lpfc_nlp_put(ndlp);
3476
dea31012005-04-17 16:05:31 -05003477 return;
3478}
3479
James Smarte59058c2008-08-24 21:49:00 -04003480/**
James Smart3621a712009-04-06 18:47:14 -04003481 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003482 * @phba: pointer to lpfc hba data structure.
3483 * @pmb: pointer to the driver internal queue element for mailbox command.
3484 *
3485 * This routine is the completion callback function for unregister default
3486 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3487 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3488 * decrements the ndlp reference count held for this completion callback
3489 * function. After that, it invokes the lpfc_nlp_not_used() to check
3490 * whether there is only one reference left on the ndlp. If so, it will
3491 * perform one more decrement and trigger the release of the ndlp.
3492 **/
James Smart858c9f62007-06-17 19:56:39 -05003493void
3494lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3495{
3496 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3497 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3498
3499 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003500 pmb->context2 = NULL;
3501
James Smart858c9f62007-06-17 19:56:39 -05003502 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3503 kfree(mp);
3504 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003505 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003506 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003507 /* This is the end of the default RPI cleanup logic for this
3508 * ndlp. If no other discovery threads are using this ndlp.
3509 * we should free all resources associated with it.
3510 */
3511 lpfc_nlp_not_used(ndlp);
3512 }
James Smart3772a992009-05-22 14:50:54 -04003513
James Smart858c9f62007-06-17 19:56:39 -05003514 return;
3515}
3516
James Smarte59058c2008-08-24 21:49:00 -04003517/**
James Smart3621a712009-04-06 18:47:14 -04003518 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003519 * @phba: pointer to lpfc hba data structure.
3520 * @cmdiocb: pointer to lpfc command iocb data structure.
3521 * @rspiocb: pointer to lpfc response iocb data structure.
3522 *
3523 * This routine is the completion callback function for ELS Response IOCB
3524 * command. In normal case, this callback function just properly sets the
3525 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3526 * field in the command IOCB is not NULL, the referred mailbox command will
3527 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3528 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3529 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3530 * routine shall be invoked trying to release the ndlp if no other threads
3531 * are currently referring it.
3532 **/
dea31012005-04-17 16:05:31 -05003533static void
James Smart858c9f62007-06-17 19:56:39 -05003534lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003535 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003536{
James Smart2e0fef82007-06-17 19:56:36 -05003537 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3538 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3539 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003540 IOCB_t *irsp;
3541 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003542 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003543 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003544 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003545
James Smart33ccf8d2006-08-17 11:57:58 -04003546 irsp = &rspiocb->iocb;
3547
dea31012005-04-17 16:05:31 -05003548 if (cmdiocb->context_un.mbox)
3549 mbox = cmdiocb->context_un.mbox;
3550
James Smartfa4066b2008-01-11 01:53:27 -05003551 /* First determine if this is a LS_RJT cmpl. Note, this callback
3552 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3553 */
James Smart87af33f2007-10-27 13:37:43 -04003554 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003555 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3556 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003557 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003558 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003559 */
3560 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3561 ls_rjt = 1;
3562 }
3563
dea31012005-04-17 16:05:31 -05003564 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003565 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003566 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003567 mp = (struct lpfc_dmabuf *) mbox->context1;
3568 if (mp) {
3569 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3570 kfree(mp);
3571 }
James Smart329f9bc2007-04-25 09:53:01 -04003572 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003573 }
James Smart58da1ff2008-04-07 10:15:56 -04003574 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3575 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003576 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003577 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003578 /* Indicate the node has already released,
3579 * should not reference to it from within
3580 * the routine lpfc_els_free_iocb.
3581 */
3582 cmdiocb->context1 = NULL;
3583 }
dea31012005-04-17 16:05:31 -05003584 goto out;
3585 }
3586
James Smart858c9f62007-06-17 19:56:39 -05003587 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003588 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003589 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003590 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003591 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003592 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3593 "0110 ELS response tag x%x completes "
3594 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3595 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3596 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3597 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3598 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003599 if (mbox) {
3600 if ((rspiocb->iocb.ulpStatus == 0)
3601 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003602 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003603 /* Increment reference count to ndlp to hold the
3604 * reference to ndlp for the callback function.
3605 */
James Smart329f9bc2007-04-25 09:53:01 -04003606 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003607 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003608 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3609 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3610 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3611 }
3612 else {
3613 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3614 ndlp->nlp_prev_state = ndlp->nlp_state;
3615 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003616 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003617 }
James Smart0b727fe2007-10-27 13:37:25 -04003618 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003619 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003620 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003621 else
3622 /* Decrement the ndlp reference count we
3623 * set for this failed mailbox command.
3624 */
3625 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003626
3627 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3628 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3629 "0138 ELS rsp: Cannot issue reg_login for x%x "
3630 "Data: x%x x%x x%x\n",
3631 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3632 ndlp->nlp_rpi);
3633
James Smartfa4066b2008-01-11 01:53:27 -05003634 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003635 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003636 /* Indicate node has already been released,
3637 * should not reference to it from within
3638 * the routine lpfc_els_free_iocb.
3639 */
3640 cmdiocb->context1 = NULL;
3641 }
dea31012005-04-17 16:05:31 -05003642 } else {
James Smart858c9f62007-06-17 19:56:39 -05003643 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3644 if (!lpfc_error_lost_link(irsp) &&
3645 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003646 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003647 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003648 /* Indicate node has already been
3649 * released, should not reference
3650 * to it from within the routine
3651 * lpfc_els_free_iocb.
3652 */
3653 cmdiocb->context1 = NULL;
3654 }
dea31012005-04-17 16:05:31 -05003655 }
3656 }
James Smart14691152006-12-02 13:34:28 -05003657 mp = (struct lpfc_dmabuf *) mbox->context1;
3658 if (mp) {
3659 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3660 kfree(mp);
3661 }
3662 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003663 }
3664out:
James Smart58da1ff2008-04-07 10:15:56 -04003665 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003666 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003667 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003668 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003669
3670 /* If the node is not being used by another discovery thread,
3671 * and we are sending a reject, we are done with it.
3672 * Release driver reference count here and free associated
3673 * resources.
3674 */
3675 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003676 if (lpfc_nlp_not_used(ndlp))
3677 /* Indicate node has already been released,
3678 * should not reference to it from within
3679 * the routine lpfc_els_free_iocb.
3680 */
3681 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003682 }
James Smart87af33f2007-10-27 13:37:43 -04003683
dea31012005-04-17 16:05:31 -05003684 lpfc_els_free_iocb(phba, cmdiocb);
3685 return;
3686}
3687
James Smarte59058c2008-08-24 21:49:00 -04003688/**
James Smart3621a712009-04-06 18:47:14 -04003689 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003690 * @vport: pointer to a host virtual N_Port data structure.
3691 * @flag: the els command code to be accepted.
3692 * @oldiocb: pointer to the original lpfc command iocb data structure.
3693 * @ndlp: pointer to a node-list data structure.
3694 * @mbox: pointer to the driver internal queue element for mailbox command.
3695 *
3696 * This routine prepares and issues an Accept (ACC) response IOCB
3697 * command. It uses the @flag to properly set up the IOCB field for the
3698 * specific ACC response command to be issued and invokes the
3699 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3700 * @mbox pointer is passed in, it will be put into the context_un.mbox
3701 * field of the IOCB for the completion callback function to issue the
3702 * mailbox command to the HBA later when callback is invoked.
3703 *
3704 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3705 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3706 * will be stored into the context1 field of the IOCB for the completion
3707 * callback function to the corresponding response ELS IOCB command.
3708 *
3709 * Return code
3710 * 0 - Successfully issued acc response
3711 * 1 - Failed to issue acc response
3712 **/
dea31012005-04-17 16:05:31 -05003713int
James Smart2e0fef82007-06-17 19:56:36 -05003714lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3715 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003716 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003717{
James Smart2e0fef82007-06-17 19:56:36 -05003718 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3719 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003720 IOCB_t *icmd;
3721 IOCB_t *oldcmd;
3722 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003723 struct lpfc_sli *psli;
3724 uint8_t *pcmd;
3725 uint16_t cmdsize;
3726 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003727 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003728
3729 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003730 oldcmd = &oldiocb->iocb;
3731
3732 switch (flag) {
3733 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003734 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003735 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3736 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003737 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003738 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003739 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003740 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003741 return 1;
dea31012005-04-17 16:05:31 -05003742 }
James Smart2e0fef82007-06-17 19:56:36 -05003743
dea31012005-04-17 16:05:31 -05003744 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003745 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3746 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003747 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3748 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003749 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003750
3751 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3752 "Issue ACC: did:x%x flg:x%x",
3753 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003754 break;
3755 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003756 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003757 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3758 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003759 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003760 return 1;
James Smart488d1462006-03-07 15:02:37 -05003761
dea31012005-04-17 16:05:31 -05003762 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003763 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3764 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003765 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3766
3767 if (mbox)
3768 elsiocb->context_un.mbox = mbox;
3769
3770 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003771 pcmd += sizeof(uint32_t);
3772 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003773
3774 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3775 "Issue ACC PLOGI: did:x%x flg:x%x",
3776 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003777 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003778 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003779 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003780 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003781 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3782 if (!elsiocb)
3783 return 1;
3784
3785 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003786 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3787 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04003788 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3789
3790 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003791 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003792 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3793 els_pkt_ptr = (ELS_PKT *) pcmd;
3794 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003795
3796 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3797 "Issue ACC PRLO: did:x%x flg:x%x",
3798 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003799 break;
dea31012005-04-17 16:05:31 -05003800 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003801 return 1;
dea31012005-04-17 16:05:31 -05003802 }
dea31012005-04-17 16:05:31 -05003803 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003804 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3805 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
James Smarte6446432012-05-09 21:16:42 -04003806 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
3807 "fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003808 elsiocb->iotag, elsiocb->iocb.ulpContext,
3809 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
James Smarte6446432012-05-09 21:16:42 -04003810 ndlp->nlp_rpi, vport->fc_flag);
dea31012005-04-17 16:05:31 -05003811 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003812 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003813 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003814 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003815 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3816 } else {
James Smart858c9f62007-06-17 19:56:39 -05003817 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003818 }
3819
3820 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003821 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003822 if (rc == IOCB_ERROR) {
3823 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003824 return 1;
dea31012005-04-17 16:05:31 -05003825 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003826 return 0;
dea31012005-04-17 16:05:31 -05003827}
3828
James Smarte59058c2008-08-24 21:49:00 -04003829/**
James Smart3621a712009-04-06 18:47:14 -04003830 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003831 * @vport: pointer to a virtual N_Port data structure.
3832 * @rejectError:
3833 * @oldiocb: pointer to the original lpfc command iocb data structure.
3834 * @ndlp: pointer to a node-list data structure.
3835 * @mbox: pointer to the driver internal queue element for mailbox command.
3836 *
3837 * This routine prepares and issue an Reject (RJT) response IOCB
3838 * command. If a @mbox pointer is passed in, it will be put into the
3839 * context_un.mbox field of the IOCB for the completion callback function
3840 * to issue to the HBA later.
3841 *
3842 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3843 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3844 * will be stored into the context1 field of the IOCB for the completion
3845 * callback function to the reject response ELS IOCB command.
3846 *
3847 * Return code
3848 * 0 - Successfully issued reject response
3849 * 1 - Failed to issue reject response
3850 **/
dea31012005-04-17 16:05:31 -05003851int
James Smart2e0fef82007-06-17 19:56:36 -05003852lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003853 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3854 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003855{
James Smart2e0fef82007-06-17 19:56:36 -05003856 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003857 IOCB_t *icmd;
3858 IOCB_t *oldcmd;
3859 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003860 struct lpfc_sli *psli;
3861 uint8_t *pcmd;
3862 uint16_t cmdsize;
3863 int rc;
3864
3865 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003866 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003867 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3868 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003869 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003870 return 1;
dea31012005-04-17 16:05:31 -05003871
3872 icmd = &elsiocb->iocb;
3873 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003874 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3875 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003876 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3877
3878 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003879 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003880 *((uint32_t *) (pcmd)) = rejectError;
3881
James Smart51ef4c22007-08-02 11:10:31 -04003882 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003883 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003884
dea31012005-04-17 16:05:31 -05003885 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003886 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3887 "0129 Xmit ELS RJT x%x response tag x%x "
3888 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3889 "rpi x%x\n",
3890 rejectError, elsiocb->iotag,
3891 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3892 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003893 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3894 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3895 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3896
dea31012005-04-17 16:05:31 -05003897 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003898 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003899 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003900
dea31012005-04-17 16:05:31 -05003901 if (rc == IOCB_ERROR) {
3902 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003903 return 1;
dea31012005-04-17 16:05:31 -05003904 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003905 return 0;
dea31012005-04-17 16:05:31 -05003906}
3907
James Smarte59058c2008-08-24 21:49:00 -04003908/**
James Smart3621a712009-04-06 18:47:14 -04003909 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003910 * @vport: pointer to a virtual N_Port data structure.
3911 * @oldiocb: pointer to the original lpfc command iocb data structure.
3912 * @ndlp: pointer to a node-list data structure.
3913 *
3914 * This routine prepares and issues an Accept (ACC) response to Address
3915 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3916 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3917 *
3918 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3919 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3920 * will be stored into the context1 field of the IOCB for the completion
3921 * callback function to the ADISC Accept response ELS IOCB command.
3922 *
3923 * Return code
3924 * 0 - Successfully issued acc adisc response
3925 * 1 - Failed to issue adisc acc response
3926 **/
dea31012005-04-17 16:05:31 -05003927int
James Smart2e0fef82007-06-17 19:56:36 -05003928lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3929 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003930{
James Smart2e0fef82007-06-17 19:56:36 -05003931 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003932 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003933 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003934 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003935 uint8_t *pcmd;
3936 uint16_t cmdsize;
3937 int rc;
3938
James Smart92d7f7b2007-06-17 19:56:38 -05003939 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003940 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3941 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003942 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003943 return 1;
dea31012005-04-17 16:05:31 -05003944
dea31012005-04-17 16:05:31 -05003945 icmd = &elsiocb->iocb;
3946 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003947 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3948 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04003949
3950 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003951 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3952 "0130 Xmit ADISC ACC response iotag x%x xri: "
3953 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3954 elsiocb->iotag, elsiocb->iocb.ulpContext,
3955 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3956 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003957 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3958
3959 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003960 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003961
3962 ap = (ADISC *) (pcmd);
3963 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003964 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3965 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003966 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003967
James Smart858c9f62007-06-17 19:56:39 -05003968 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3969 "Issue ACC ADISC: did:x%x flg:x%x",
3970 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3971
dea31012005-04-17 16:05:31 -05003972 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003973 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003974 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003975 if (rc == IOCB_ERROR) {
3976 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003977 return 1;
dea31012005-04-17 16:05:31 -05003978 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003979 return 0;
dea31012005-04-17 16:05:31 -05003980}
3981
James Smarte59058c2008-08-24 21:49:00 -04003982/**
James Smart3621a712009-04-06 18:47:14 -04003983 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003984 * @vport: pointer to a virtual N_Port data structure.
3985 * @oldiocb: pointer to the original lpfc command iocb data structure.
3986 * @ndlp: pointer to a node-list data structure.
3987 *
3988 * This routine prepares and issues an Accept (ACC) response to Process
3989 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3990 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3991 *
3992 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3993 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3994 * will be stored into the context1 field of the IOCB for the completion
3995 * callback function to the PRLI Accept response ELS IOCB command.
3996 *
3997 * Return code
3998 * 0 - Successfully issued acc prli response
3999 * 1 - Failed to issue acc prli response
4000 **/
dea31012005-04-17 16:05:31 -05004001int
James Smart2e0fef82007-06-17 19:56:36 -05004002lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04004003 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004004{
James Smart2e0fef82007-06-17 19:56:36 -05004005 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004006 PRLI *npr;
4007 lpfc_vpd_t *vpd;
4008 IOCB_t *icmd;
4009 IOCB_t *oldcmd;
4010 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004011 struct lpfc_sli *psli;
4012 uint8_t *pcmd;
4013 uint16_t cmdsize;
4014 int rc;
4015
4016 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05004017
James Smart92d7f7b2007-06-17 19:56:38 -05004018 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05004019 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05004020 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004021 if (!elsiocb)
4022 return 1;
dea31012005-04-17 16:05:31 -05004023
dea31012005-04-17 16:05:31 -05004024 icmd = &elsiocb->iocb;
4025 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004026 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4027 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4028
James Smart5b8bd0c2007-04-25 09:52:49 -04004029 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004030 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4031 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4032 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4033 elsiocb->iotag, elsiocb->iocb.ulpContext,
4034 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4035 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004036 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4037
4038 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05004039 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004040
4041 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05004042 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05004043
4044 npr = (PRLI *) pcmd;
4045 vpd = &phba->vpd;
4046 /*
James Smart0d2b6b82008-06-14 22:52:47 -04004047 * If the remote port is a target and our firmware version is 3.20 or
4048 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05004049 */
James Smart0d2b6b82008-06-14 22:52:47 -04004050 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4051 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05004052 npr->ConfmComplAllowed = 1;
4053 npr->Retry = 1;
4054 npr->TaskRetryIdReq = 1;
4055 }
4056
4057 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4058 npr->estabImagePair = 1;
4059 npr->readXferRdyDis = 1;
4060 npr->ConfmComplAllowed = 1;
4061
4062 npr->prliType = PRLI_FCP_TYPE;
4063 npr->initiatorFunc = 1;
4064
James Smart858c9f62007-06-17 19:56:39 -05004065 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4066 "Issue ACC PRLI: did:x%x flg:x%x",
4067 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4068
dea31012005-04-17 16:05:31 -05004069 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004070 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004071
James Smart3772a992009-05-22 14:50:54 -04004072 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004073 if (rc == IOCB_ERROR) {
4074 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004075 return 1;
dea31012005-04-17 16:05:31 -05004076 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004077 return 0;
dea31012005-04-17 16:05:31 -05004078}
4079
James Smarte59058c2008-08-24 21:49:00 -04004080/**
James Smart3621a712009-04-06 18:47:14 -04004081 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004082 * @vport: pointer to a virtual N_Port data structure.
4083 * @format: rnid command format.
4084 * @oldiocb: pointer to the original lpfc command iocb data structure.
4085 * @ndlp: pointer to a node-list data structure.
4086 *
4087 * This routine issues a Request Node Identification Data (RNID) Accept
4088 * (ACC) response. It constructs the RNID ACC response command according to
4089 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4090 * issue the response. Note that this command does not need to hold the ndlp
4091 * reference count for the callback. So, the ndlp reference count taken by
4092 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4093 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4094 * there is no ndlp reference available.
4095 *
4096 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4097 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4098 * will be stored into the context1 field of the IOCB for the completion
4099 * callback function. However, for the RNID Accept Response ELS command,
4100 * this is undone later by this routine after the IOCB is allocated.
4101 *
4102 * Return code
4103 * 0 - Successfully issued acc rnid response
4104 * 1 - Failed to issue acc rnid response
4105 **/
dea31012005-04-17 16:05:31 -05004106static int
James Smart2e0fef82007-06-17 19:56:36 -05004107lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004108 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004109{
James Smart2e0fef82007-06-17 19:56:36 -05004110 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004111 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004112 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004113 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004114 struct lpfc_sli *psli;
4115 uint8_t *pcmd;
4116 uint16_t cmdsize;
4117 int rc;
4118
4119 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004120 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4121 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004122 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004123 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004124
James Smart2e0fef82007-06-17 19:56:36 -05004125 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4126 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004127 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004128 return 1;
dea31012005-04-17 16:05:31 -05004129
dea31012005-04-17 16:05:31 -05004130 icmd = &elsiocb->iocb;
4131 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004132 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4133 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4134
James Smart5b8bd0c2007-04-25 09:52:49 -04004135 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004136 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4137 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4138 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004139 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004140 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004141 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004142
James Smart92d7f7b2007-06-17 19:56:38 -05004143 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004144 rn = (RNID *) (pcmd);
4145 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004146 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4147 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4148 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004149 switch (format) {
4150 case 0:
4151 rn->SpecificLen = 0;
4152 break;
4153 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004154 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004155 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004156 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004157 rn->un.topologyDisc.unitType = RNID_HBA;
4158 rn->un.topologyDisc.physPort = 0;
4159 rn->un.topologyDisc.attachedNodes = 0;
4160 break;
4161 default:
4162 rn->CommonLen = 0;
4163 rn->SpecificLen = 0;
4164 break;
4165 }
4166
James Smart858c9f62007-06-17 19:56:39 -05004167 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4168 "Issue ACC RNID: did:x%x flg:x%x",
4169 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4170
dea31012005-04-17 16:05:31 -05004171 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004172 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004173
James Smart3772a992009-05-22 14:50:54 -04004174 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004175 if (rc == IOCB_ERROR) {
4176 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004177 return 1;
dea31012005-04-17 16:05:31 -05004178 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004179 return 0;
dea31012005-04-17 16:05:31 -05004180}
4181
James Smarte59058c2008-08-24 21:49:00 -04004182/**
James Smart19ca7602010-11-20 23:11:55 -05004183 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4184 * @vport: pointer to a virtual N_Port data structure.
4185 * @iocb: pointer to the lpfc command iocb data structure.
4186 * @ndlp: pointer to a node-list data structure.
4187 *
4188 * Return
4189 **/
4190static void
4191lpfc_els_clear_rrq(struct lpfc_vport *vport,
4192 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4193{
4194 struct lpfc_hba *phba = vport->phba;
4195 uint8_t *pcmd;
4196 struct RRQ *rrq;
4197 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004198 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004199 struct lpfc_node_rrq *prrq;
4200
4201
4202 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4203 pcmd += sizeof(uint32_t);
4204 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004205 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b062011-04-16 11:03:17 -04004206 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004207
4208 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4209 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4210 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004211 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b062011-04-16 11:03:17 -04004212 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004213 rxid,
4214 iocb->iotag, iocb->iocb.ulpContext);
4215
4216 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4217 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4218 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004219 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b062011-04-16 11:03:17 -04004220 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004221 else
4222 xri = rxid;
4223 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004224 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004225 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004226 return;
4227}
4228
4229/**
James Smart12265f62010-10-22 11:05:53 -04004230 * lpfc_els_rsp_echo_acc - Issue echo acc response
4231 * @vport: pointer to a virtual N_Port data structure.
4232 * @data: pointer to echo data to return in the accept.
4233 * @oldiocb: pointer to the original lpfc command iocb data structure.
4234 * @ndlp: pointer to a node-list data structure.
4235 *
4236 * Return code
4237 * 0 - Successfully issued acc echo response
4238 * 1 - Failed to issue acc echo response
4239 **/
4240static int
4241lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4242 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4243{
4244 struct lpfc_hba *phba = vport->phba;
4245 struct lpfc_iocbq *elsiocb;
4246 struct lpfc_sli *psli;
4247 uint8_t *pcmd;
4248 uint16_t cmdsize;
4249 int rc;
4250
4251 psli = &phba->sli;
4252 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4253
James Smartbf086112011-08-21 21:48:13 -04004254 /* The accumulated length can exceed the BPL_SIZE. For
4255 * now, use this as the limit
4256 */
4257 if (cmdsize > LPFC_BPL_SIZE)
4258 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04004259 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4260 ndlp->nlp_DID, ELS_CMD_ACC);
4261 if (!elsiocb)
4262 return 1;
4263
James Smart7851fe22011-07-22 18:36:52 -04004264 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4265 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4266
James Smart12265f62010-10-22 11:05:53 -04004267 /* Xmit ECHO ACC response tag <ulpIoTag> */
4268 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4269 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4270 elsiocb->iotag, elsiocb->iocb.ulpContext);
4271 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4272 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4273 pcmd += sizeof(uint32_t);
4274 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4275
4276 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4277 "Issue ACC ECHO: did:x%x flg:x%x",
4278 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4279
4280 phba->fc_stat.elsXmitACC++;
4281 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04004282
4283 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4284 if (rc == IOCB_ERROR) {
4285 lpfc_els_free_iocb(phba, elsiocb);
4286 return 1;
4287 }
4288 return 0;
4289}
4290
4291/**
James Smart3621a712009-04-06 18:47:14 -04004292 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004293 * @vport: pointer to a host virtual N_Port data structure.
4294 *
4295 * This routine issues Address Discover (ADISC) ELS commands to those
4296 * N_Ports which are in node port recovery state and ADISC has not been issued
4297 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4298 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4299 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4300 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4301 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4302 * IOCBs quit for later pick up. On the other hand, after walking through
4303 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4304 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4305 * no more ADISC need to be sent.
4306 *
4307 * Return code
4308 * The number of N_Ports with adisc issued.
4309 **/
dea31012005-04-17 16:05:31 -05004310int
James Smart2e0fef82007-06-17 19:56:36 -05004311lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004312{
James Smart2e0fef82007-06-17 19:56:36 -05004313 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004314 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004315 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004316
James Smart685f0bf2007-04-25 09:53:08 -04004317 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004318 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004319 if (!NLP_CHK_NODE_ACT(ndlp))
4320 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004321 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4322 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4323 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004324 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004325 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004326 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004327 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004328 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4329 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004330 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004331 vport->num_disc_nodes++;
4332 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004333 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004334 spin_lock_irq(shost->host_lock);
4335 vport->fc_flag |= FC_NLP_MORE;
4336 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004337 break;
dea31012005-04-17 16:05:31 -05004338 }
4339 }
4340 }
4341 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004342 spin_lock_irq(shost->host_lock);
4343 vport->fc_flag &= ~FC_NLP_MORE;
4344 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004345 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004346 return sentadisc;
dea31012005-04-17 16:05:31 -05004347}
4348
James Smarte59058c2008-08-24 21:49:00 -04004349/**
James Smart3621a712009-04-06 18:47:14 -04004350 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004351 * @vport: pointer to a host virtual N_Port data structure.
4352 *
4353 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4354 * which are in node port recovery state, with a @vport. Each time an ELS
4355 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4356 * the per @vport number of discover count (num_disc_nodes) shall be
4357 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4358 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4359 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4360 * later pick up. On the other hand, after walking through all the ndlps with
4361 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4362 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4363 * PLOGI need to be sent.
4364 *
4365 * Return code
4366 * The number of N_Ports with plogi issued.
4367 **/
dea31012005-04-17 16:05:31 -05004368int
James Smart2e0fef82007-06-17 19:56:36 -05004369lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004370{
James Smart2e0fef82007-06-17 19:56:36 -05004371 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004372 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004373 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004374
James Smart2e0fef82007-06-17 19:56:36 -05004375 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4376 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004377 if (!NLP_CHK_NODE_ACT(ndlp))
4378 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004379 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4380 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4381 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4382 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4383 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004384 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4385 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004386 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004387 vport->num_disc_nodes++;
4388 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004389 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004390 spin_lock_irq(shost->host_lock);
4391 vport->fc_flag |= FC_NLP_MORE;
4392 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004393 break;
dea31012005-04-17 16:05:31 -05004394 }
4395 }
4396 }
James Smart87af33f2007-10-27 13:37:43 -04004397 if (sentplogi) {
4398 lpfc_set_disctmo(vport);
4399 }
4400 else {
James Smart2e0fef82007-06-17 19:56:36 -05004401 spin_lock_irq(shost->host_lock);
4402 vport->fc_flag &= ~FC_NLP_MORE;
4403 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004404 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004405 return sentplogi;
dea31012005-04-17 16:05:31 -05004406}
4407
James Smarte59058c2008-08-24 21:49:00 -04004408/**
James Smart3621a712009-04-06 18:47:14 -04004409 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004410 * @vport: pointer to a host virtual N_Port data structure.
4411 *
4412 * This routine cleans up any Registration State Change Notification
4413 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4414 * @vport together with the host_lock is used to prevent multiple thread
4415 * trying to access the RSCN array on a same @vport at the same time.
4416 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004417void
James Smart2e0fef82007-06-17 19:56:36 -05004418lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004419{
James Smart2e0fef82007-06-17 19:56:36 -05004420 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4421 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004422 int i;
4423
James Smart7f5f3d02008-02-08 18:50:14 -05004424 spin_lock_irq(shost->host_lock);
4425 if (vport->fc_rscn_flush) {
4426 /* Another thread is walking fc_rscn_id_list on this vport */
4427 spin_unlock_irq(shost->host_lock);
4428 return;
4429 }
4430 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4431 vport->fc_rscn_flush = 1;
4432 spin_unlock_irq(shost->host_lock);
4433
James Smart2e0fef82007-06-17 19:56:36 -05004434 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004435 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004436 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004437 }
James Smart2e0fef82007-06-17 19:56:36 -05004438 spin_lock_irq(shost->host_lock);
4439 vport->fc_rscn_id_cnt = 0;
4440 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4441 spin_unlock_irq(shost->host_lock);
4442 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004443 /* Indicate we are done walking this fc_rscn_id_list */
4444 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004445}
4446
James Smarte59058c2008-08-24 21:49:00 -04004447/**
James Smart3621a712009-04-06 18:47:14 -04004448 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004449 * @vport: pointer to a host virtual N_Port data structure.
4450 * @did: remote destination port identifier.
4451 *
4452 * This routine checks whether there is any pending Registration State
4453 * Configuration Notification (RSCN) to a @did on @vport.
4454 *
4455 * Return code
4456 * None zero - The @did matched with a pending rscn
4457 * 0 - not able to match @did with a pending rscn
4458 **/
dea31012005-04-17 16:05:31 -05004459int
James Smart2e0fef82007-06-17 19:56:36 -05004460lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004461{
4462 D_ID ns_did;
4463 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004464 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004465 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004466 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004467
4468 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004469
4470 /* Never match fabric nodes for RSCNs */
4471 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004472 return 0;
dea31012005-04-17 16:05:31 -05004473
4474 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004475 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004476 return did;
dea31012005-04-17 16:05:31 -05004477
James Smart7f5f3d02008-02-08 18:50:14 -05004478 spin_lock_irq(shost->host_lock);
4479 if (vport->fc_rscn_flush) {
4480 /* Another thread is walking fc_rscn_id_list on this vport */
4481 spin_unlock_irq(shost->host_lock);
4482 return 0;
4483 }
4484 /* Indicate we are walking fc_rscn_id_list on this vport */
4485 vport->fc_rscn_flush = 1;
4486 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004487 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004488 lp = vport->fc_rscn_id_list[i]->virt;
4489 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4490 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004491 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004492 rscn_did.un.word = be32_to_cpu(*lp++);
4493 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004494 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4495 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004496 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4497 && (ns_did.un.b.area == rscn_did.un.b.area)
4498 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004499 goto return_did_out;
dea31012005-04-17 16:05:31 -05004500 break;
James Smarteaf15d52008-12-04 22:39:29 -05004501 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004502 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4503 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004504 goto return_did_out;
dea31012005-04-17 16:05:31 -05004505 break;
James Smarteaf15d52008-12-04 22:39:29 -05004506 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004507 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004508 goto return_did_out;
dea31012005-04-17 16:05:31 -05004509 break;
James Smarteaf15d52008-12-04 22:39:29 -05004510 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004511 goto return_did_out;
dea31012005-04-17 16:05:31 -05004512 }
4513 }
James Smart92d7f7b2007-06-17 19:56:38 -05004514 }
James Smart7f5f3d02008-02-08 18:50:14 -05004515 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4516 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004517 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004518return_did_out:
4519 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4520 vport->fc_rscn_flush = 0;
4521 return did;
dea31012005-04-17 16:05:31 -05004522}
4523
James Smarte59058c2008-08-24 21:49:00 -04004524/**
James Smart3621a712009-04-06 18:47:14 -04004525 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004526 * @vport: pointer to a host virtual N_Port data structure.
4527 *
4528 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4529 * state machine for a @vport's nodes that are with pending RSCN (Registration
4530 * State Change Notification).
4531 *
4532 * Return code
4533 * 0 - Successful (currently alway return 0)
4534 **/
dea31012005-04-17 16:05:31 -05004535static int
James Smart2e0fef82007-06-17 19:56:36 -05004536lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004537{
James Smart685f0bf2007-04-25 09:53:08 -04004538 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004539
James Smart0d2b6b82008-06-14 22:52:47 -04004540 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004541 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004542 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004543 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4544 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004545 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004546 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004547 NLP_EVT_DEVICE_RECOVERY);
4548 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004549 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004550 return 0;
dea31012005-04-17 16:05:31 -05004551}
4552
James Smarte59058c2008-08-24 21:49:00 -04004553/**
James Smart3621a712009-04-06 18:47:14 -04004554 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004555 * @vport: pointer to a host virtual N_Port data structure.
4556 * @cmdiocb: pointer to lpfc command iocb data structure.
4557 *
4558 * lpfc_send_rscn_event sends an RSCN netlink event to management
4559 * applications.
4560 */
4561static void
4562lpfc_send_rscn_event(struct lpfc_vport *vport,
4563 struct lpfc_iocbq *cmdiocb)
4564{
4565 struct lpfc_dmabuf *pcmd;
4566 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4567 uint32_t *payload_ptr;
4568 uint32_t payload_len;
4569 struct lpfc_rscn_event_header *rscn_event_data;
4570
4571 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4572 payload_ptr = (uint32_t *) pcmd->virt;
4573 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4574
4575 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4576 payload_len, GFP_KERNEL);
4577 if (!rscn_event_data) {
4578 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4579 "0147 Failed to allocate memory for RSCN event\n");
4580 return;
4581 }
4582 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4583 rscn_event_data->payload_length = payload_len;
4584 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4585 payload_len);
4586
4587 fc_host_post_vendor_event(shost,
4588 fc_get_event_number(),
4589 sizeof(struct lpfc_els_event_header) + payload_len,
4590 (char *)rscn_event_data,
4591 LPFC_NL_VENDOR_ID);
4592
4593 kfree(rscn_event_data);
4594}
4595
4596/**
James Smart3621a712009-04-06 18:47:14 -04004597 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004598 * @vport: pointer to a host virtual N_Port data structure.
4599 * @cmdiocb: pointer to lpfc command iocb data structure.
4600 * @ndlp: pointer to a node-list data structure.
4601 *
4602 * This routine processes an unsolicited RSCN (Registration State Change
4603 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4604 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4605 * discover state machine is about to begin discovery, it just accepts the
4606 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4607 * contains N_Port IDs for other vports on this HBA, it just accepts the
4608 * RSCN and ignore processing it. If the state machine is in the recovery
4609 * state, the fc_rscn_id_list of this @vport is walked and the
4610 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4611 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4612 * routine is invoked to handle the RSCN event.
4613 *
4614 * Return code
4615 * 0 - Just sent the acc response
4616 * 1 - Sent the acc response and waited for name server completion
4617 **/
dea31012005-04-17 16:05:31 -05004618static int
James Smart2e0fef82007-06-17 19:56:36 -05004619lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004620 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004621{
James Smart2e0fef82007-06-17 19:56:36 -05004622 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4623 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004624 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004625 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004626 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004627 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004628 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004629 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004630 int i;
dea31012005-04-17 16:05:31 -05004631
4632 icmd = &cmdiocb->iocb;
4633 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4634 lp = (uint32_t *) pcmd->virt;
4635
James Smart92d7f7b2007-06-17 19:56:38 -05004636 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4637 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004638 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004639 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4640 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004641 vport->fc_flag, payload_len, *lp,
4642 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004643
4644 /* Send an RSCN event to the management application */
4645 lpfc_send_rscn_event(vport, cmdiocb);
4646
James Smartd2873e42006-08-18 17:46:43 -04004647 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004648 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004649 FCH_EVT_RSCN, lp[i]);
4650
dea31012005-04-17 16:05:31 -05004651 /* If we are about to begin discovery, just ACC the RSCN.
4652 * Discovery processing will satisfy it.
4653 */
James Smart2e0fef82007-06-17 19:56:36 -05004654 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004655 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4656 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4657 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4658
James Smart51ef4c22007-08-02 11:10:31 -04004659 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004660 return 0;
dea31012005-04-17 16:05:31 -05004661 }
4662
James Smart92d7f7b2007-06-17 19:56:38 -05004663 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4664 * just ACC and ignore it.
4665 */
4666 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004667 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004668 i = payload_len;
4669 datap = lp;
4670 while (i > 0) {
4671 nportid = *datap++;
4672 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4673 i -= sizeof(uint32_t);
4674 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004675 if (lpfc_find_vport_by_did(phba, nportid))
4676 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004677 }
4678 if (rscn_id == hba_id) {
4679 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004680 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004681 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004682 "Data: x%x x%x x%x x%x\n",
4683 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004684 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004685 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4686 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4687 ndlp->nlp_DID, vport->port_state,
4688 ndlp->nlp_flag);
4689
James Smart92d7f7b2007-06-17 19:56:38 -05004690 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004691 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004692 return 0;
4693 }
4694 }
4695
James Smart7f5f3d02008-02-08 18:50:14 -05004696 spin_lock_irq(shost->host_lock);
4697 if (vport->fc_rscn_flush) {
4698 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004699 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004700 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004701 /* Send back ACC */
4702 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004703 return 0;
4704 }
4705 /* Indicate we are walking fc_rscn_id_list on this vport */
4706 vport->fc_rscn_flush = 1;
4707 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004708 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004709 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004710 /* If we are already processing an RSCN, save the received
4711 * RSCN payload buffer, cmdiocb->context2 to process later.
4712 */
James Smart2e0fef82007-06-17 19:56:36 -05004713 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004714 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4715 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4716 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4717
James Smart09372822008-01-11 01:52:54 -05004718 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004719 vport->fc_flag |= FC_RSCN_DEFERRED;
4720 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004721 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004722 vport->fc_flag |= FC_RSCN_MODE;
4723 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004724 if (rscn_cnt) {
4725 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4726 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4727 }
4728 if ((rscn_cnt) &&
4729 (payload_len + length <= LPFC_BPL_SIZE)) {
4730 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004731 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004732 memcpy(((uint8_t *)cmd) + length, lp,
4733 payload_len);
4734 } else {
4735 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4736 vport->fc_rscn_id_cnt++;
4737 /* If we zero, cmdiocb->context2, the calling
4738 * routine will not try to free it.
4739 */
4740 cmdiocb->context2 = NULL;
4741 }
dea31012005-04-17 16:05:31 -05004742 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004743 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4744 "0235 Deferred RSCN "
4745 "Data: x%x x%x x%x\n",
4746 vport->fc_rscn_id_cnt, vport->fc_flag,
4747 vport->port_state);
dea31012005-04-17 16:05:31 -05004748 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004749 vport->fc_flag |= FC_RSCN_DISCOVERY;
4750 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004751 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004752 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4753 "0234 ReDiscovery RSCN "
4754 "Data: x%x x%x x%x\n",
4755 vport->fc_rscn_id_cnt, vport->fc_flag,
4756 vport->port_state);
dea31012005-04-17 16:05:31 -05004757 }
James Smart7f5f3d02008-02-08 18:50:14 -05004758 /* Indicate we are done walking fc_rscn_id_list on this vport */
4759 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004760 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004761 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004762 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004763 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004764 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004765 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004766 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004767 return 0;
dea31012005-04-17 16:05:31 -05004768 }
James Smart858c9f62007-06-17 19:56:39 -05004769 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4770 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4771 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4772
James Smart2e0fef82007-06-17 19:56:36 -05004773 spin_lock_irq(shost->host_lock);
4774 vport->fc_flag |= FC_RSCN_MODE;
4775 spin_unlock_irq(shost->host_lock);
4776 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004777 /* Indicate we are done walking fc_rscn_id_list on this vport */
4778 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004779 /*
4780 * If we zero, cmdiocb->context2, the calling routine will
4781 * not try to free it.
4782 */
4783 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004784 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004785 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004786 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004787 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004788 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004789 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004790}
4791
James Smarte59058c2008-08-24 21:49:00 -04004792/**
James Smart3621a712009-04-06 18:47:14 -04004793 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004794 * @vport: pointer to a host virtual N_Port data structure.
4795 *
4796 * This routine handles the Registration State Configuration Notification
4797 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4798 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4799 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4800 * NameServer shall be issued. If CT command to the NameServer fails to be
4801 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4802 * RSCN activities with the @vport.
4803 *
4804 * Return code
4805 * 0 - Cleaned up rscn on the @vport
4806 * 1 - Wait for plogi to name server before proceed
4807 **/
dea31012005-04-17 16:05:31 -05004808int
James Smart2e0fef82007-06-17 19:56:36 -05004809lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004810{
4811 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004812 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004813
James Smart92d7f7b2007-06-17 19:56:38 -05004814 /* Ignore RSCN if the port is being torn down. */
4815 if (vport->load_flag & FC_UNLOADING) {
4816 lpfc_els_flush_rscn(vport);
4817 return 0;
4818 }
4819
dea31012005-04-17 16:05:31 -05004820 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004821 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004822
4823 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004824 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4825 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4826 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4827 vport->port_state);
dea31012005-04-17 16:05:31 -05004828
4829 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004830 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004831 vport->num_disc_nodes = 0;
4832
James Smart2e0fef82007-06-17 19:56:36 -05004833 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004834 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4835 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004836 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004837 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004838 /* Wait for NameServer query cmpl before we can
4839 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004840 return 1;
dea31012005-04-17 16:05:31 -05004841 } else {
4842 /* If login to NameServer does not exist, issue one */
4843 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004844 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004845 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004846 /* Wait for NameServer login cmpl before we can
4847 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004848 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004849
James Smarte47c9092008-02-08 18:49:26 -05004850 if (ndlp) {
4851 ndlp = lpfc_enable_node(vport, ndlp,
4852 NLP_STE_PLOGI_ISSUE);
4853 if (!ndlp) {
4854 lpfc_els_flush_rscn(vport);
4855 return 0;
4856 }
4857 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004858 } else {
James Smarte47c9092008-02-08 18:49:26 -05004859 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4860 if (!ndlp) {
4861 lpfc_els_flush_rscn(vport);
4862 return 0;
4863 }
James Smart2e0fef82007-06-17 19:56:36 -05004864 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004865 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004866 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004867 }
James Smarte47c9092008-02-08 18:49:26 -05004868 ndlp->nlp_type |= NLP_FABRIC;
4869 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4870 /* Wait for NameServer login cmpl before we can
4871 * continue
4872 */
4873 return 1;
dea31012005-04-17 16:05:31 -05004874 }
4875
James Smart2e0fef82007-06-17 19:56:36 -05004876 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004877 return 0;
dea31012005-04-17 16:05:31 -05004878}
4879
James Smarte59058c2008-08-24 21:49:00 -04004880/**
James Smart3621a712009-04-06 18:47:14 -04004881 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004882 * @vport: pointer to a host virtual N_Port data structure.
4883 * @cmdiocb: pointer to lpfc command iocb data structure.
4884 * @ndlp: pointer to a node-list data structure.
4885 *
4886 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4887 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4888 * point topology. As an unsolicited FLOGI should not be received in a loop
4889 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4890 * lpfc_check_sparm() routine is invoked to check the parameters in the
4891 * unsolicited FLOGI. If parameters validation failed, the routine
4892 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4893 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4894 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4895 * will initiate PLOGI. The higher lexicographical value party shall has
4896 * higher priority (as the winning port) and will initiate PLOGI and
4897 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4898 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4899 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4900 *
4901 * Return code
4902 * 0 - Successfully processed the unsolicited flogi
4903 * 1 - Failed to process the unsolicited flogi
4904 **/
dea31012005-04-17 16:05:31 -05004905static int
James Smart2e0fef82007-06-17 19:56:36 -05004906lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004907 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004908{
James Smart2e0fef82007-06-17 19:56:36 -05004909 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4910 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004911 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4912 uint32_t *lp = (uint32_t *) pcmd->virt;
4913 IOCB_t *icmd = &cmdiocb->iocb;
4914 struct serv_parm *sp;
4915 LPFC_MBOXQ_t *mbox;
4916 struct ls_rjt stat;
4917 uint32_t cmd, did;
4918 int rc;
4919
4920 cmd = *lp++;
4921 sp = (struct serv_parm *) lp;
4922
4923 /* FLOGI received */
4924
James Smart2e0fef82007-06-17 19:56:36 -05004925 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004926
James Smart76a95d72010-11-20 23:11:48 -05004927 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004928 /* We should never receive a FLOGI in loop mode, ignore it */
4929 did = icmd->un.elsreq64.remoteID;
4930
4931 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4932 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004933 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4934 "0113 An FLOGI ELS command x%x was "
4935 "received from DID x%x in Loop Mode\n",
4936 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004937 return 1;
dea31012005-04-17 16:05:31 -05004938 }
4939
4940 did = Fabric_DID;
4941
James Smart341af102010-01-26 23:07:37 -05004942 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004943 /* For a FLOGI we accept, then if our portname is greater
4944 * then the remote portname we initiate Nport login.
4945 */
4946
James Smart2e0fef82007-06-17 19:56:36 -05004947 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004948 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004949
4950 if (!rc) {
James Smart1b511972011-12-13 13:23:09 -05004951 if (phba->sli_rev < LPFC_SLI_REV4) {
4952 mbox = mempool_alloc(phba->mbox_mem_pool,
4953 GFP_KERNEL);
4954 if (!mbox)
4955 return 1;
4956 lpfc_linkdown(phba);
4957 lpfc_init_link(phba, mbox,
4958 phba->cfg_topology,
4959 phba->cfg_link_speed);
4960 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
4961 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4962 mbox->vport = vport;
4963 rc = lpfc_sli_issue_mbox(phba, mbox,
4964 MBX_NOWAIT);
4965 lpfc_set_loopback_flag(phba);
4966 if (rc == MBX_NOT_FINISHED)
4967 mempool_free(mbox, phba->mbox_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004968 return 1;
James Smart1b511972011-12-13 13:23:09 -05004969 } else {
4970 /* abort the flogi coming back to ourselves
4971 * due to external loopback on the port.
4972 */
4973 lpfc_els_abort_flogi(phba);
4974 return 0;
dea31012005-04-17 16:05:31 -05004975 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004976 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004977 spin_lock_irq(shost->host_lock);
4978 vport->fc_flag |= FC_PT2PT_PLOGI;
4979 spin_unlock_irq(shost->host_lock);
James Smarte6446432012-05-09 21:16:42 -04004980 vport->fc_myDID = PT2PT_LocalID;
4981 } else
4982 vport->fc_myDID = PT2PT_RemoteID;
4983 vport->port_state = LPFC_FLOGI;
James Smart2e0fef82007-06-17 19:56:36 -05004984 spin_lock_irq(shost->host_lock);
4985 vport->fc_flag |= FC_PT2PT;
4986 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4987 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004988 } else {
4989 /* Reject this request because invalid parameters */
4990 stat.un.b.lsRjtRsvd0 = 0;
4991 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4992 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4993 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004994 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4995 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004996 return 1;
dea31012005-04-17 16:05:31 -05004997 }
4998
4999 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04005000 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005001
James Smarte6446432012-05-09 21:16:42 -04005002 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
5003 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5004 if (!mbox)
5005 goto fail;
5006
5007 lpfc_config_link(phba, mbox);
5008
5009 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5010 mbox->vport = vport;
5011 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5012 if (rc == MBX_NOT_FINISHED) {
5013 mempool_free(mbox, phba->mbox_mem_pool);
5014 goto fail;
5015 }
5016 }
5017
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005018 return 0;
James Smarte6446432012-05-09 21:16:42 -04005019fail:
5020 return 1;
dea31012005-04-17 16:05:31 -05005021}
5022
James Smarte59058c2008-08-24 21:49:00 -04005023/**
James Smart3621a712009-04-06 18:47:14 -04005024 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04005025 * @vport: pointer to a host virtual N_Port data structure.
5026 * @cmdiocb: pointer to lpfc command iocb data structure.
5027 * @ndlp: pointer to a node-list data structure.
5028 *
5029 * This routine processes Request Node Identification Data (RNID) IOCB
5030 * received as an ELS unsolicited event. Only when the RNID specified format
5031 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
5032 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
5033 * Accept (ACC) the RNID ELS command. All the other RNID formats are
5034 * rejected by invoking the lpfc_els_rsp_reject() routine.
5035 *
5036 * Return code
5037 * 0 - Successfully processed rnid iocb (currently always return 0)
5038 **/
dea31012005-04-17 16:05:31 -05005039static int
James Smart2e0fef82007-06-17 19:56:36 -05005040lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5041 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005042{
5043 struct lpfc_dmabuf *pcmd;
5044 uint32_t *lp;
5045 IOCB_t *icmd;
5046 RNID *rn;
5047 struct ls_rjt stat;
5048 uint32_t cmd, did;
5049
5050 icmd = &cmdiocb->iocb;
5051 did = icmd->un.elsreq64.remoteID;
5052 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5053 lp = (uint32_t *) pcmd->virt;
5054
5055 cmd = *lp++;
5056 rn = (RNID *) lp;
5057
5058 /* RNID received */
5059
5060 switch (rn->Format) {
5061 case 0:
5062 case RNID_TOPOLOGY_DISC:
5063 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05005064 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005065 break;
5066 default:
5067 /* Reject this request because format not supported */
5068 stat.un.b.lsRjtRsvd0 = 0;
5069 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5070 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5071 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005072 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5073 NULL);
dea31012005-04-17 16:05:31 -05005074 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005075 return 0;
dea31012005-04-17 16:05:31 -05005076}
5077
James Smarte59058c2008-08-24 21:49:00 -04005078/**
James Smart12265f62010-10-22 11:05:53 -04005079 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
5080 * @vport: pointer to a host virtual N_Port data structure.
5081 * @cmdiocb: pointer to lpfc command iocb data structure.
5082 * @ndlp: pointer to a node-list data structure.
5083 *
5084 * Return code
5085 * 0 - Successfully processed echo iocb (currently always return 0)
5086 **/
5087static int
5088lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5089 struct lpfc_nodelist *ndlp)
5090{
5091 uint8_t *pcmd;
5092
5093 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
5094
5095 /* skip over first word of echo command to find echo data */
5096 pcmd += sizeof(uint32_t);
5097
5098 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
5099 return 0;
5100}
5101
5102/**
James Smart3621a712009-04-06 18:47:14 -04005103 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04005104 * @vport: pointer to a host virtual N_Port data structure.
5105 * @cmdiocb: pointer to lpfc command iocb data structure.
5106 * @ndlp: pointer to a node-list data structure.
5107 *
5108 * This routine processes a Link Incident Report Registration(LIRR) IOCB
5109 * received as an ELS unsolicited event. Currently, this function just invokes
5110 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
5111 *
5112 * Return code
5113 * 0 - Successfully processed lirr iocb (currently always return 0)
5114 **/
dea31012005-04-17 16:05:31 -05005115static int
James Smart2e0fef82007-06-17 19:56:36 -05005116lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5117 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005118{
5119 struct ls_rjt stat;
5120
5121 /* For now, unconditionally reject this command */
5122 stat.un.b.lsRjtRsvd0 = 0;
5123 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5124 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5125 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005126 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005127 return 0;
5128}
5129
James Smarte59058c2008-08-24 21:49:00 -04005130/**
James Smart5ffc2662009-11-18 15:39:44 -05005131 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5132 * @vport: pointer to a host virtual N_Port data structure.
5133 * @cmdiocb: pointer to lpfc command iocb data structure.
5134 * @ndlp: pointer to a node-list data structure.
5135 *
5136 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5137 * received as an ELS unsolicited event. A request to RRQ shall only
5138 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5139 * Nx_Port N_Port_ID of the target Exchange is the same as the
5140 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5141 * not accepted, an LS_RJT with reason code "Unable to perform
5142 * command request" and reason code explanation "Invalid Originator
5143 * S_ID" shall be returned. For now, we just unconditionally accept
5144 * RRQ from the target.
5145 **/
5146static void
5147lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5148 struct lpfc_nodelist *ndlp)
5149{
5150 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05005151 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5152 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05005153}
5154
5155/**
James Smart12265f62010-10-22 11:05:53 -04005156 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5157 * @phba: pointer to lpfc hba data structure.
5158 * @pmb: pointer to the driver internal queue element for mailbox command.
5159 *
5160 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5161 * mailbox command. This callback function is to actually send the Accept
5162 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5163 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5164 * mailbox command, constructs the RPS response with the link statistics
5165 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5166 * response to the RPS.
5167 *
5168 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5169 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5170 * will be stored into the context1 field of the IOCB for the completion
5171 * callback function to the RPS Accept Response ELS IOCB command.
5172 *
5173 **/
5174static void
5175lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5176{
5177 MAILBOX_t *mb;
5178 IOCB_t *icmd;
5179 struct RLS_RSP *rls_rsp;
5180 uint8_t *pcmd;
5181 struct lpfc_iocbq *elsiocb;
5182 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005183 uint16_t oxid;
5184 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04005185 uint32_t cmdsize;
5186
5187 mb = &pmb->u.mb;
5188
5189 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005190 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5191 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04005192 pmb->context1 = NULL;
5193 pmb->context2 = NULL;
5194
5195 if (mb->mbxStatus) {
5196 mempool_free(pmb, phba->mbox_mem_pool);
5197 return;
5198 }
5199
5200 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04005201 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5202 lpfc_max_els_tries, ndlp,
5203 ndlp->nlp_DID, ELS_CMD_ACC);
5204
5205 /* Decrement the ndlp reference count from previous mbox command */
5206 lpfc_nlp_put(ndlp);
5207
James Smart37db57e2012-05-09 21:17:16 -04005208 if (!elsiocb) {
5209 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04005210 return;
James Smart37db57e2012-05-09 21:17:16 -04005211 }
James Smart12265f62010-10-22 11:05:53 -04005212
5213 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005214 icmd->ulpContext = rxid;
5215 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04005216
5217 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5218 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5219 pcmd += sizeof(uint32_t); /* Skip past command */
5220 rls_rsp = (struct RLS_RSP *)pcmd;
5221
5222 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5223 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5224 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5225 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5226 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5227 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04005228 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04005229 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5230 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5231 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5232 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5233 elsiocb->iotag, elsiocb->iocb.ulpContext,
5234 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5235 ndlp->nlp_rpi);
5236 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5237 phba->fc_stat.elsXmitACC++;
5238 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5239 lpfc_els_free_iocb(phba, elsiocb);
5240}
5241
5242/**
James Smart3621a712009-04-06 18:47:14 -04005243 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005244 * @phba: pointer to lpfc hba data structure.
5245 * @pmb: pointer to the driver internal queue element for mailbox command.
5246 *
5247 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5248 * mailbox command. This callback function is to actually send the Accept
5249 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5250 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5251 * mailbox command, constructs the RPS response with the link statistics
5252 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5253 * response to the RPS.
5254 *
5255 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5256 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5257 * will be stored into the context1 field of the IOCB for the completion
5258 * callback function to the RPS Accept Response ELS IOCB command.
5259 *
5260 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005261static void
James Smart329f9bc2007-04-25 09:53:01 -04005262lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005263{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005264 MAILBOX_t *mb;
5265 IOCB_t *icmd;
5266 RPS_RSP *rps_rsp;
5267 uint8_t *pcmd;
5268 struct lpfc_iocbq *elsiocb;
5269 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005270 uint16_t status;
5271 uint16_t oxid;
5272 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005273 uint32_t cmdsize;
5274
James Smart04c68492009-05-22 14:52:52 -04005275 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005276
5277 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005278 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5279 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07005280 pmb->context1 = NULL;
5281 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005282
5283 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005284 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005285 return;
5286 }
5287
5288 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005289 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005290 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5291 lpfc_max_els_tries, ndlp,
5292 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005293
5294 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005295 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005296
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005297 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005298 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005299
5300 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005301 icmd->ulpContext = rxid;
5302 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005303
5304 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5305 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005306 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005307 rps_rsp = (RPS_RSP *)pcmd;
5308
James Smart76a95d72010-11-20 23:11:48 -05005309 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005310 status = 0x10;
5311 else
5312 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005313 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005314 status |= 0x4;
5315
5316 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005317 rps_rsp->portStatus = cpu_to_be16(status);
5318 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5319 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5320 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5321 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5322 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5323 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005324 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005325 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5326 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5327 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5328 elsiocb->iotag, elsiocb->iocb.ulpContext,
5329 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5330 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005331 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005332 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005333 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005334 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005335 return;
5336}
5337
James Smarte59058c2008-08-24 21:49:00 -04005338/**
James Smart12265f62010-10-22 11:05:53 -04005339 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5340 * @vport: pointer to a host virtual N_Port data structure.
5341 * @cmdiocb: pointer to lpfc command iocb data structure.
5342 * @ndlp: pointer to a node-list data structure.
5343 *
5344 * This routine processes Read Port Status (RPL) IOCB received as an
5345 * ELS unsolicited event. It first checks the remote port state. If the
5346 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5347 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5348 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5349 * for reading the HBA link statistics. It is for the callback function,
5350 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5351 * to actually sending out RPL Accept (ACC) response.
5352 *
5353 * Return codes
5354 * 0 - Successfully processed rls iocb (currently always return 0)
5355 **/
5356static int
5357lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5358 struct lpfc_nodelist *ndlp)
5359{
5360 struct lpfc_hba *phba = vport->phba;
5361 LPFC_MBOXQ_t *mbox;
5362 struct lpfc_dmabuf *pcmd;
5363 struct ls_rjt stat;
5364
5365 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5366 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5367 /* reject the unsolicited RPS request and done with it */
5368 goto reject_out;
5369
5370 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5371
5372 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5373 if (mbox) {
5374 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005375 mbox->context1 = (void *)((unsigned long)
5376 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5377 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04005378 mbox->context2 = lpfc_nlp_get(ndlp);
5379 mbox->vport = vport;
5380 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5381 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5382 != MBX_NOT_FINISHED)
5383 /* Mbox completion will send ELS Response */
5384 return 0;
5385 /* Decrement reference count used for the failed mbox
5386 * command.
5387 */
5388 lpfc_nlp_put(ndlp);
5389 mempool_free(mbox, phba->mbox_mem_pool);
5390 }
5391reject_out:
5392 /* issue rejection response */
5393 stat.un.b.lsRjtRsvd0 = 0;
5394 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5395 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5396 stat.un.b.vendorUnique = 0;
5397 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5398 return 0;
5399}
5400
5401/**
5402 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5403 * @vport: pointer to a host virtual N_Port data structure.
5404 * @cmdiocb: pointer to lpfc command iocb data structure.
5405 * @ndlp: pointer to a node-list data structure.
5406 *
5407 * This routine processes Read Timout Value (RTV) IOCB received as an
5408 * ELS unsolicited event. It first checks the remote port state. If the
5409 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5410 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5411 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5412 * Value (RTV) unsolicited IOCB event.
5413 *
5414 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5415 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5416 * will be stored into the context1 field of the IOCB for the completion
5417 * callback function to the RPS Accept Response ELS IOCB command.
5418 *
5419 * Return codes
5420 * 0 - Successfully processed rtv iocb (currently always return 0)
5421 **/
5422static int
5423lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5424 struct lpfc_nodelist *ndlp)
5425{
5426 struct lpfc_hba *phba = vport->phba;
5427 struct ls_rjt stat;
5428 struct RTV_RSP *rtv_rsp;
5429 uint8_t *pcmd;
5430 struct lpfc_iocbq *elsiocb;
5431 uint32_t cmdsize;
5432
5433
5434 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5435 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5436 /* reject the unsolicited RPS request and done with it */
5437 goto reject_out;
5438
5439 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5440 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5441 lpfc_max_els_tries, ndlp,
5442 ndlp->nlp_DID, ELS_CMD_ACC);
5443
5444 if (!elsiocb)
5445 return 1;
5446
5447 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5448 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5449 pcmd += sizeof(uint32_t); /* Skip past command */
5450
5451 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04005452 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
5453 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04005454
5455 rtv_rsp = (struct RTV_RSP *)pcmd;
5456
5457 /* populate RTV payload */
5458 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5459 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5460 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5461 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5462 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5463
5464 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5465 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5466 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5467 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5468 "Data: x%x x%x x%x\n",
5469 elsiocb->iotag, elsiocb->iocb.ulpContext,
5470 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5471 ndlp->nlp_rpi,
5472 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5473 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5474 phba->fc_stat.elsXmitACC++;
5475 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5476 lpfc_els_free_iocb(phba, elsiocb);
5477 return 0;
5478
5479reject_out:
5480 /* issue rejection response */
5481 stat.un.b.lsRjtRsvd0 = 0;
5482 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5483 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5484 stat.un.b.vendorUnique = 0;
5485 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5486 return 0;
5487}
5488
5489/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005490 * @vport: pointer to a host virtual N_Port data structure.
5491 * @cmdiocb: pointer to lpfc command iocb data structure.
5492 * @ndlp: pointer to a node-list data structure.
5493 *
5494 * This routine processes Read Port Status (RPS) IOCB received as an
5495 * ELS unsolicited event. It first checks the remote port state. If the
5496 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5497 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5498 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5499 * for reading the HBA link statistics. It is for the callback function,
5500 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5501 * to actually sending out RPS Accept (ACC) response.
5502 *
5503 * Return codes
5504 * 0 - Successfully processed rps iocb (currently always return 0)
5505 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005506static int
James Smart2e0fef82007-06-17 19:56:36 -05005507lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5508 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005509{
James Smart2e0fef82007-06-17 19:56:36 -05005510 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005511 uint32_t *lp;
5512 uint8_t flag;
5513 LPFC_MBOXQ_t *mbox;
5514 struct lpfc_dmabuf *pcmd;
5515 RPS *rps;
5516 struct ls_rjt stat;
5517
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005518 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005519 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5520 /* reject the unsolicited RPS request and done with it */
5521 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005522
5523 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5524 lp = (uint32_t *) pcmd->virt;
5525 flag = (be32_to_cpu(*lp++) & 0xf);
5526 rps = (RPS *) lp;
5527
5528 if ((flag == 0) ||
5529 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005530 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005531 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005532
James Smart92d7f7b2007-06-17 19:56:38 -05005533 printk("Fix me....\n");
5534 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005535 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5536 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005537 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005538 mbox->context1 = (void *)((unsigned long)
5539 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5540 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04005541 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005542 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005543 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005544 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005545 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005546 /* Mbox completion will send ELS Response */
5547 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005548 /* Decrement reference count used for the failed mbox
5549 * command.
5550 */
James Smart329f9bc2007-04-25 09:53:01 -04005551 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005552 mempool_free(mbox, phba->mbox_mem_pool);
5553 }
5554 }
James Smart90160e02008-08-24 21:49:45 -04005555
5556reject_out:
5557 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005558 stat.un.b.lsRjtRsvd0 = 0;
5559 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5560 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5561 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005562 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005563 return 0;
5564}
5565
James Smart19ca7602010-11-20 23:11:55 -05005566/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5567 * @vport: pointer to a host virtual N_Port data structure.
5568 * @ndlp: pointer to a node-list data structure.
5569 * @did: DID of the target.
5570 * @rrq: Pointer to the rrq struct.
5571 *
5572 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5573 * Successful the the completion handler will clear the RRQ.
5574 *
5575 * Return codes
5576 * 0 - Successfully sent rrq els iocb.
5577 * 1 - Failed to send rrq els iocb.
5578 **/
5579static int
5580lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5581 uint32_t did, struct lpfc_node_rrq *rrq)
5582{
5583 struct lpfc_hba *phba = vport->phba;
5584 struct RRQ *els_rrq;
5585 IOCB_t *icmd;
5586 struct lpfc_iocbq *elsiocb;
5587 uint8_t *pcmd;
5588 uint16_t cmdsize;
5589 int ret;
5590
5591
5592 if (ndlp != rrq->ndlp)
5593 ndlp = rrq->ndlp;
5594 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5595 return 1;
5596
5597 /* If ndlp is not NULL, we will bump the reference count on it */
5598 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5599 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5600 ELS_CMD_RRQ);
5601 if (!elsiocb)
5602 return 1;
5603
5604 icmd = &elsiocb->iocb;
5605 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5606
5607 /* For RRQ request, remainder of payload is Exchange IDs */
5608 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5609 pcmd += sizeof(uint32_t);
5610 els_rrq = (struct RRQ *) pcmd;
5611
5612 bf_set(rrq_oxid, els_rrq, rrq->xritag);
5613 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5614 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5615 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5616 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5617
5618
5619 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5620 "Issue RRQ: did:x%x",
5621 did, rrq->xritag, rrq->rxid);
5622 elsiocb->context_un.rrq = rrq;
5623 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5624 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5625
5626 if (ret == IOCB_ERROR) {
5627 lpfc_els_free_iocb(phba, elsiocb);
5628 return 1;
5629 }
5630 return 0;
5631}
5632
5633/**
5634 * lpfc_send_rrq - Sends ELS RRQ if needed.
5635 * @phba: pointer to lpfc hba data structure.
5636 * @rrq: pointer to the active rrq.
5637 *
5638 * This routine will call the lpfc_issue_els_rrq if the rrq is
5639 * still active for the xri. If this function returns a failure then
5640 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5641 *
5642 * Returns 0 Success.
5643 * 1 Failure.
5644 **/
5645int
5646lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5647{
5648 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5649 rrq->nlp_DID);
5650 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5651 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5652 rrq->nlp_DID, rrq);
5653 else
5654 return 1;
5655}
5656
James Smarte59058c2008-08-24 21:49:00 -04005657/**
James Smart3621a712009-04-06 18:47:14 -04005658 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005659 * @vport: pointer to a host virtual N_Port data structure.
5660 * @cmdsize: size of the ELS command.
5661 * @oldiocb: pointer to the original lpfc command iocb data structure.
5662 * @ndlp: pointer to a node-list data structure.
5663 *
5664 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5665 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5666 *
5667 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5668 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5669 * will be stored into the context1 field of the IOCB for the completion
5670 * callback function to the RPL Accept Response ELS command.
5671 *
5672 * Return code
5673 * 0 - Successfully issued ACC RPL ELS command
5674 * 1 - Failed to issue ACC RPL ELS command
5675 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005676static int
James Smart2e0fef82007-06-17 19:56:36 -05005677lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5678 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005679{
James Smart2e0fef82007-06-17 19:56:36 -05005680 struct lpfc_hba *phba = vport->phba;
5681 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005682 RPL_RSP rpl_rsp;
5683 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005684 uint8_t *pcmd;
5685
James Smart2e0fef82007-06-17 19:56:36 -05005686 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5687 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005688
James Smart488d1462006-03-07 15:02:37 -05005689 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005690 return 1;
James Smart488d1462006-03-07 15:02:37 -05005691
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005692 icmd = &elsiocb->iocb;
5693 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005694 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5695 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005696
5697 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5698 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005699 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005700 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5701 pcmd += sizeof(uint16_t);
5702
5703 /* Setup the RPL ACC payload */
5704 rpl_rsp.listLen = be32_to_cpu(1);
5705 rpl_rsp.index = 0;
5706 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005707 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5708 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005709 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005710 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005711 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005712 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5713 "0120 Xmit ELS RPL ACC response tag x%x "
5714 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5715 "rpi x%x\n",
5716 elsiocb->iotag, elsiocb->iocb.ulpContext,
5717 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5718 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005719 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005720 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005721 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5722 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005723 lpfc_els_free_iocb(phba, elsiocb);
5724 return 1;
5725 }
5726 return 0;
5727}
5728
James Smarte59058c2008-08-24 21:49:00 -04005729/**
James Smart3621a712009-04-06 18:47:14 -04005730 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005731 * @vport: pointer to a host virtual N_Port data structure.
5732 * @cmdiocb: pointer to lpfc command iocb data structure.
5733 * @ndlp: pointer to a node-list data structure.
5734 *
5735 * This routine processes Read Port List (RPL) IOCB received as an ELS
5736 * unsolicited event. It first checks the remote port state. If the remote
5737 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5738 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5739 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5740 * to accept the RPL.
5741 *
5742 * Return code
5743 * 0 - Successfully processed rpl iocb (currently always return 0)
5744 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005745static int
James Smart2e0fef82007-06-17 19:56:36 -05005746lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5747 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005748{
5749 struct lpfc_dmabuf *pcmd;
5750 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005751 uint32_t maxsize;
5752 uint16_t cmdsize;
5753 RPL *rpl;
5754 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005755
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005756 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5757 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005758 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005759 stat.un.b.lsRjtRsvd0 = 0;
5760 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5761 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5762 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005763 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5764 NULL);
James Smart90160e02008-08-24 21:49:45 -04005765 /* rejected the unsolicited RPL request and done with it */
5766 return 0;
dea31012005-04-17 16:05:31 -05005767 }
5768
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005769 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5770 lp = (uint32_t *) pcmd->virt;
5771 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005772 maxsize = be32_to_cpu(rpl->maxsize);
5773
5774 /* We support only one port */
5775 if ((rpl->index == 0) &&
5776 ((maxsize == 0) ||
5777 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5778 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005779 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005780 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5781 }
James Smart2e0fef82007-06-17 19:56:36 -05005782 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005783
5784 return 0;
5785}
5786
James Smarte59058c2008-08-24 21:49:00 -04005787/**
James Smart3621a712009-04-06 18:47:14 -04005788 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005789 * @vport: pointer to a virtual N_Port data structure.
5790 * @cmdiocb: pointer to lpfc command iocb data structure.
5791 * @ndlp: pointer to a node-list data structure.
5792 *
5793 * This routine processes Fibre Channel Address Resolution Protocol
5794 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5795 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5796 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5797 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5798 * remote PortName is compared against the FC PortName stored in the @vport
5799 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5800 * compared against the FC NodeName stored in the @vport data structure.
5801 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5802 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5803 * invoked to send out FARP Response to the remote node. Before sending the
5804 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5805 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5806 * routine is invoked to log into the remote port first.
5807 *
5808 * Return code
5809 * 0 - Either the FARP Match Mode not supported or successfully processed
5810 **/
dea31012005-04-17 16:05:31 -05005811static int
James Smart2e0fef82007-06-17 19:56:36 -05005812lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5813 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005814{
5815 struct lpfc_dmabuf *pcmd;
5816 uint32_t *lp;
5817 IOCB_t *icmd;
5818 FARP *fp;
5819 uint32_t cmd, cnt, did;
5820
5821 icmd = &cmdiocb->iocb;
5822 did = icmd->un.elsreq64.remoteID;
5823 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5824 lp = (uint32_t *) pcmd->virt;
5825
5826 cmd = *lp++;
5827 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005828 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005829 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5830 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005831 /* We will only support match on WWPN or WWNN */
5832 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005833 return 0;
dea31012005-04-17 16:05:31 -05005834 }
5835
5836 cnt = 0;
5837 /* If this FARP command is searching for my portname */
5838 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005839 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005840 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005841 cnt = 1;
5842 }
5843
5844 /* If this FARP command is searching for my nodename */
5845 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005846 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005847 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005848 cnt = 1;
5849 }
5850
5851 if (cnt) {
5852 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5853 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5854 /* Log back into the node before sending the FARP. */
5855 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005856 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005857 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005858 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005859 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005860 }
5861
5862 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005863 if (fp->Rflags & FARP_REQUEST_FARPR)
5864 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005865 }
5866 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005867 return 0;
dea31012005-04-17 16:05:31 -05005868}
5869
James Smarte59058c2008-08-24 21:49:00 -04005870/**
James Smart3621a712009-04-06 18:47:14 -04005871 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005872 * @vport: pointer to a host virtual N_Port data structure.
5873 * @cmdiocb: pointer to lpfc command iocb data structure.
5874 * @ndlp: pointer to a node-list data structure.
5875 *
5876 * This routine processes Fibre Channel Address Resolution Protocol
5877 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5878 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5879 * the FARP response request.
5880 *
5881 * Return code
5882 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5883 **/
dea31012005-04-17 16:05:31 -05005884static int
James Smart2e0fef82007-06-17 19:56:36 -05005885lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5886 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005887{
5888 struct lpfc_dmabuf *pcmd;
5889 uint32_t *lp;
5890 IOCB_t *icmd;
5891 uint32_t cmd, did;
5892
5893 icmd = &cmdiocb->iocb;
5894 did = icmd->un.elsreq64.remoteID;
5895 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5896 lp = (uint32_t *) pcmd->virt;
5897
5898 cmd = *lp++;
5899 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005900 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5901 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005902 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005903 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005904
5905 return 0;
5906}
5907
James Smarte59058c2008-08-24 21:49:00 -04005908/**
James Smart3621a712009-04-06 18:47:14 -04005909 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005910 * @vport: pointer to a host virtual N_Port data structure.
5911 * @cmdiocb: pointer to lpfc command iocb data structure.
5912 * @fan_ndlp: pointer to a node-list data structure.
5913 *
5914 * This routine processes a Fabric Address Notification (FAN) IOCB
5915 * command received as an ELS unsolicited event. The FAN ELS command will
5916 * only be processed on a physical port (i.e., the @vport represents the
5917 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5918 * compared against those in the phba data structure. If any of those is
5919 * different, the lpfc_initial_flogi() routine is invoked to initialize
5920 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5921 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5922 * is invoked to register login to the fabric.
5923 *
5924 * Return code
5925 * 0 - Successfully processed fan iocb (currently always return 0).
5926 **/
dea31012005-04-17 16:05:31 -05005927static int
James Smart2e0fef82007-06-17 19:56:36 -05005928lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5929 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005930{
James Smart2e0fef82007-06-17 19:56:36 -05005931 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005932 uint32_t *lp;
5933 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005934
James Smart0d2b6b82008-06-14 22:52:47 -04005935 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5936 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5937 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005938 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005939 if ((vport == phba->pport) &&
5940 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005941 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005942 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005943 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005944 sizeof(struct lpfc_name)))) {
5945 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05005946 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005947 } else {
5948 /* FAN verified - skip FLOGI */
5949 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005950 if (phba->sli_rev < LPFC_SLI_REV4)
5951 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05005952 else {
5953 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5954 "3138 Need register VFI: (x%x/%x)\n",
5955 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04005956 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05005957 }
dea31012005-04-17 16:05:31 -05005958 }
dea31012005-04-17 16:05:31 -05005959 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005960 return 0;
dea31012005-04-17 16:05:31 -05005961}
5962
James Smarte59058c2008-08-24 21:49:00 -04005963/**
James Smart3621a712009-04-06 18:47:14 -04005964 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005965 * @ptr: holder for the timer function associated data.
5966 *
5967 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5968 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5969 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5970 * up the worker thread. It is for the worker thread to invoke the routine
5971 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5972 **/
dea31012005-04-17 16:05:31 -05005973void
5974lpfc_els_timeout(unsigned long ptr)
5975{
James Smart2e0fef82007-06-17 19:56:36 -05005976 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5977 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005978 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005979 unsigned long iflag;
5980
James Smart2e0fef82007-06-17 19:56:36 -05005981 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005982 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5983 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005984 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005985 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005986
James Smart5e9d9b82008-06-14 22:52:53 -04005987 if (!tmo_posted)
5988 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005989 return;
5990}
5991
James Smart2a9bf3d2010-06-07 15:24:45 -04005992
James Smarte59058c2008-08-24 21:49:00 -04005993/**
James Smart3621a712009-04-06 18:47:14 -04005994 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005995 * @vport: pointer to a virtual N_Port data structure.
5996 *
5997 * This routine is the actual handler function that processes an ELS timeout
5998 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5999 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
6000 * invoking the lpfc_sli_issue_abort_iotag() routine.
6001 **/
dea31012005-04-17 16:05:31 -05006002void
James Smart2e0fef82007-06-17 19:56:36 -05006003lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006004{
James Smart2e0fef82007-06-17 19:56:36 -05006005 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006006 struct lpfc_sli_ring *pring;
6007 struct lpfc_iocbq *tmp_iocb, *piocb;
6008 IOCB_t *cmd = NULL;
6009 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05006010 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05006011 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05006012 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04006013 LIST_HEAD(txcmplq_completions);
6014 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05006015
James Smart2a9bf3d2010-06-07 15:24:45 -04006016
dea31012005-04-17 16:05:31 -05006017 timeout = (uint32_t)(phba->fc_ratov << 1);
6018
6019 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006020
James Smart2a9bf3d2010-06-07 15:24:45 -04006021 spin_lock_irq(&phba->hbalock);
6022 list_splice_init(&pring->txcmplq, &txcmplq_completions);
6023 spin_unlock_irq(&phba->hbalock);
6024
6025 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05006026 cmd = &piocb->iocb;
6027
James Smart2e0fef82007-06-17 19:56:36 -05006028 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
6029 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
6030 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05006031 continue;
James Smart2e0fef82007-06-17 19:56:36 -05006032
6033 if (piocb->vport != vport)
6034 continue;
6035
dea31012005-04-17 16:05:31 -05006036 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05006037 if (pcmd)
6038 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05006039
James Smart92d7f7b2007-06-17 19:56:38 -05006040 if (els_command == ELS_CMD_FARP ||
6041 els_command == ELS_CMD_FARPR ||
6042 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05006043 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05006044
dea31012005-04-17 16:05:31 -05006045 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05006046 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05006047 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05006048 else
dea31012005-04-17 16:05:31 -05006049 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05006050 continue;
6051 }
6052
James Smart2e0fef82007-06-17 19:56:36 -05006053 remote_ID = 0xffffffff;
6054 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05006055 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05006056 else {
6057 struct lpfc_nodelist *ndlp;
6058 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04006059 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05006060 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05006061 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006062 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05006063 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006064 spin_lock_irq(&phba->hbalock);
6065 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05006066 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04006067
James Smart2a9bf3d2010-06-07 15:24:45 -04006068 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
6069 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6070 "0127 ELS timeout Data: x%x x%x x%x "
6071 "x%x\n", els_command,
6072 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
6073 spin_lock_irq(&phba->hbalock);
6074 list_del_init(&piocb->dlist);
6075 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6076 spin_unlock_irq(&phba->hbalock);
6077 }
6078
James Smart2e0fef82007-06-17 19:56:36 -05006079 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
6080 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05006081}
6082
James Smarte59058c2008-08-24 21:49:00 -04006083/**
James Smart3621a712009-04-06 18:47:14 -04006084 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04006085 * @vport: pointer to a host virtual N_Port data structure.
6086 *
6087 * This routine is used to clean up all the outstanding ELS commands on a
6088 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
6089 * routine. After that, it walks the ELS transmit queue to remove all the
6090 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
6091 * the IOCBs with a non-NULL completion callback function, the callback
6092 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6093 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
6094 * callback function, the IOCB will simply be released. Finally, it walks
6095 * the ELS transmit completion queue to issue an abort IOCB to any transmit
6096 * completion queue IOCB that is associated with the @vport and is not
6097 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
6098 * part of the discovery state machine) out to HBA by invoking the
6099 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
6100 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
6101 * the IOCBs are aborted when this function returns.
6102 **/
dea31012005-04-17 16:05:31 -05006103void
James Smart2e0fef82007-06-17 19:56:36 -05006104lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006105{
James Smart2534ba72007-04-25 09:52:20 -04006106 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05006107 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04006108 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006109 struct lpfc_iocbq *tmp_iocb, *piocb;
6110 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006111
6112 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05006113
James Smart2e0fef82007-06-17 19:56:36 -05006114 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006115 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6116 cmd = &piocb->iocb;
6117
6118 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6119 continue;
6120 }
6121
6122 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04006123 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6124 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6125 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6126 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05006127 continue;
dea31012005-04-17 16:05:31 -05006128
James Smart2e0fef82007-06-17 19:56:36 -05006129 if (piocb->vport != vport)
6130 continue;
6131
James Smart2534ba72007-04-25 09:52:20 -04006132 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04006133 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05006134 }
6135
6136 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05006137 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6138 continue;
6139 }
dea31012005-04-17 16:05:31 -05006140
James Smart2e0fef82007-06-17 19:56:36 -05006141 if (piocb->vport != vport)
6142 continue;
6143
James Smart07951072007-04-25 09:51:38 -04006144 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05006145 }
James Smart2e0fef82007-06-17 19:56:36 -05006146 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04006147
James Smarta257bf92009-04-06 18:48:10 -04006148 /* Cancell all the IOCBs from the completions list */
6149 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6150 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04006151
dea31012005-04-17 16:05:31 -05006152 return;
6153}
6154
James Smarte59058c2008-08-24 21:49:00 -04006155/**
James Smart3621a712009-04-06 18:47:14 -04006156 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04006157 * @phba: pointer to lpfc hba data structure.
6158 *
6159 * This routine is used to clean up all the outstanding ELS commands on a
6160 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6161 * routine. After that, it walks the ELS transmit queue to remove all the
6162 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6163 * the IOCBs with the completion callback function associated, the callback
6164 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6165 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6166 * callback function associated, the IOCB will simply be released. Finally,
6167 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6168 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6169 * management plane IOCBs that are not part of the discovery state machine)
6170 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6171 **/
James Smart549e55c2007-08-02 11:09:51 -04006172void
6173lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6174{
6175 LIST_HEAD(completions);
6176 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6177 struct lpfc_iocbq *tmp_iocb, *piocb;
6178 IOCB_t *cmd = NULL;
6179
6180 lpfc_fabric_abort_hba(phba);
6181 spin_lock_irq(&phba->hbalock);
6182 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6183 cmd = &piocb->iocb;
6184 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6185 continue;
6186 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6187 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6188 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6189 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6190 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6191 continue;
6192 list_move_tail(&piocb->list, &completions);
6193 pring->txq_cnt--;
6194 }
6195 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6196 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6197 continue;
6198 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6199 }
6200 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04006201
6202 /* Cancel all the IOCBs from the completions list */
6203 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6204 IOERR_SLI_ABORTED);
6205
James Smart549e55c2007-08-02 11:09:51 -04006206 return;
6207}
6208
James Smarte59058c2008-08-24 21:49:00 -04006209/**
James Smart3621a712009-04-06 18:47:14 -04006210 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04006211 * @phba: Pointer to hba context object.
6212 * @cmdiocbp: Pointer to command iocb which reported error.
6213 * @rspiocbp: Pointer to response iocb which reported error.
6214 *
6215 * This function sends an event when there is an ELS command
6216 * failure.
6217 **/
6218void
6219lpfc_send_els_failure_event(struct lpfc_hba *phba,
6220 struct lpfc_iocbq *cmdiocbp,
6221 struct lpfc_iocbq *rspiocbp)
6222{
6223 struct lpfc_vport *vport = cmdiocbp->vport;
6224 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6225 struct lpfc_lsrjt_event lsrjt_event;
6226 struct lpfc_fabric_event_header fabric_event;
6227 struct ls_rjt stat;
6228 struct lpfc_nodelist *ndlp;
6229 uint32_t *pcmd;
6230
6231 ndlp = cmdiocbp->context1;
6232 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6233 return;
6234
6235 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6236 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6237 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6238 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6239 sizeof(struct lpfc_name));
6240 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6241 sizeof(struct lpfc_name));
6242 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6243 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006244 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006245 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6246 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6247 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6248 fc_host_post_vendor_event(shost,
6249 fc_get_event_number(),
6250 sizeof(lsrjt_event),
6251 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006252 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006253 return;
6254 }
6255 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6256 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6257 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6258 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6259 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6260 else
6261 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6262 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6263 sizeof(struct lpfc_name));
6264 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6265 sizeof(struct lpfc_name));
6266 fc_host_post_vendor_event(shost,
6267 fc_get_event_number(),
6268 sizeof(fabric_event),
6269 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006270 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006271 return;
6272 }
6273
6274}
6275
6276/**
James Smart3621a712009-04-06 18:47:14 -04006277 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006278 * @vport: Pointer to vport object.
6279 * @ndlp: Pointer FC node object.
6280 * @cmd: ELS command code.
6281 *
6282 * This function posts an event when there is an incoming
6283 * unsolicited ELS command.
6284 **/
6285static void
6286lpfc_send_els_event(struct lpfc_vport *vport,
6287 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006288 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006289{
James Smartddcc50f2008-12-04 22:38:46 -05006290 struct lpfc_els_event_header *els_data = NULL;
6291 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006292 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6293
James Smartddcc50f2008-12-04 22:38:46 -05006294 if (*payload == ELS_CMD_LOGO) {
6295 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6296 if (!logo_data) {
6297 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6298 "0148 Failed to allocate memory "
6299 "for LOGO event\n");
6300 return;
6301 }
6302 els_data = &logo_data->header;
6303 } else {
6304 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6305 GFP_KERNEL);
6306 if (!els_data) {
6307 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6308 "0149 Failed to allocate memory "
6309 "for ELS event\n");
6310 return;
6311 }
6312 }
6313 els_data->event_type = FC_REG_ELS_EVENT;
6314 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006315 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006316 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006317 break;
6318 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006319 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006320 break;
6321 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006322 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6323 break;
6324 case ELS_CMD_LOGO:
6325 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6326 /* Copy the WWPN in the LOGO payload */
6327 memcpy(logo_data->logo_wwpn, &payload[2],
6328 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006329 break;
6330 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006331 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006332 return;
6333 }
James Smartddcc50f2008-12-04 22:38:46 -05006334 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6335 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6336 if (*payload == ELS_CMD_LOGO) {
6337 fc_host_post_vendor_event(shost,
6338 fc_get_event_number(),
6339 sizeof(struct lpfc_logo_event),
6340 (char *)logo_data,
6341 LPFC_NL_VENDOR_ID);
6342 kfree(logo_data);
6343 } else {
6344 fc_host_post_vendor_event(shost,
6345 fc_get_event_number(),
6346 sizeof(struct lpfc_els_event_header),
6347 (char *)els_data,
6348 LPFC_NL_VENDOR_ID);
6349 kfree(els_data);
6350 }
James Smartea2151b2008-09-07 11:52:10 -04006351
6352 return;
6353}
6354
6355
6356/**
James Smart3621a712009-04-06 18:47:14 -04006357 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006358 * @phba: pointer to lpfc hba data structure.
6359 * @pring: pointer to a SLI ring.
6360 * @vport: pointer to a host virtual N_Port data structure.
6361 * @elsiocb: pointer to lpfc els command iocb data structure.
6362 *
6363 * This routine is used for processing the IOCB associated with a unsolicited
6364 * event. It first determines whether there is an existing ndlp that matches
6365 * the DID from the unsolicited IOCB. If not, it will create a new one with
6366 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6367 * IOCB is then used to invoke the proper routine and to set up proper state
6368 * of the discovery state machine.
6369 **/
James Smarted957682007-06-17 19:56:37 -05006370static void
6371lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006372 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006373{
James Smart87af33f2007-10-27 13:37:43 -04006374 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006375 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006376 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006377 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05006378 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006379 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006380
James Smarte47c9092008-02-08 18:49:26 -05006381 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006382 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006383
dea31012005-04-17 16:05:31 -05006384 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006385 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6386 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006387 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006388 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006389
James Smart858c9f62007-06-17 19:56:39 -05006390 did = icmd->un.rcvels.remoteID;
6391 if (icmd->ulpStatus) {
6392 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6393 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6394 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006395 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006396 }
dea31012005-04-17 16:05:31 -05006397
6398 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006399 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006400 goto dropit;
dea31012005-04-17 16:05:31 -05006401
James Smartc8685952009-11-18 15:39:16 -05006402 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006403 if (vport->load_flag & FC_UNLOADING)
6404 goto dropit;
6405
James Smart92494142011-02-16 12:39:44 -05006406 /* If NPort discovery is delayed drop incoming ELS */
6407 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6408 (cmd != ELS_CMD_PLOGI))
6409 goto dropit;
6410
James Smart2e0fef82007-06-17 19:56:36 -05006411 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006412 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006413 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006414 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006415 if (!ndlp)
dea31012005-04-17 16:05:31 -05006416 goto dropit;
dea31012005-04-17 16:05:31 -05006417
James Smart2e0fef82007-06-17 19:56:36 -05006418 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006419 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006420 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006421 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006422 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006423 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6424 ndlp = lpfc_enable_node(vport, ndlp,
6425 NLP_STE_UNUSED_NODE);
6426 if (!ndlp)
6427 goto dropit;
6428 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6429 newnode = 1;
6430 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6431 ndlp->nlp_type |= NLP_FABRIC;
6432 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6433 /* This is similar to the new node path */
6434 ndlp = lpfc_nlp_get(ndlp);
6435 if (!ndlp)
6436 goto dropit;
6437 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6438 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006439 }
dea31012005-04-17 16:05:31 -05006440
6441 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006442
James Smart329f9bc2007-04-25 09:53:01 -04006443 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006444 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006445
6446 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6447 cmd &= ELS_CMD_MASK;
6448 }
6449 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006450 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6451 "0112 ELS command x%x received from NPORT x%x "
6452 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006453 switch (cmd) {
6454 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006455 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6456 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6457 did, vport->port_state, ndlp->nlp_flag);
6458
dea31012005-04-17 16:05:31 -05006459 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006460 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6461
James Smartddcc50f2008-12-04 22:38:46 -05006462 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05006463
6464 /* If Nport discovery is delayed, reject PLOGIs */
6465 if (vport->fc_flag & FC_DISC_DELAYED) {
6466 rjt_err = LSRJT_UNABLE_TPC;
6467 break;
6468 }
James Smart858c9f62007-06-17 19:56:39 -05006469 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006470 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6471 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6472 rjt_err = LSRJT_UNABLE_TPC;
6473 break;
6474 }
6475 /* We get here, and drop thru, if we are PT2PT with
6476 * another NPort and the other side has initiated
6477 * the PLOGI before responding to our FLOGI.
6478 */
dea31012005-04-17 16:05:31 -05006479 }
James Smart87af33f2007-10-27 13:37:43 -04006480
6481 shost = lpfc_shost_from_vport(vport);
6482 spin_lock_irq(shost->host_lock);
6483 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6484 spin_unlock_irq(shost->host_lock);
6485
James Smart2e0fef82007-06-17 19:56:36 -05006486 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6487 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006488
dea31012005-04-17 16:05:31 -05006489 break;
6490 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006491 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6492 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6493 did, vport->port_state, ndlp->nlp_flag);
6494
dea31012005-04-17 16:05:31 -05006495 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006496 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006497 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006498 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006499 break;
6500 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006501 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6502 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6503 did, vport->port_state, ndlp->nlp_flag);
6504
dea31012005-04-17 16:05:31 -05006505 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006506 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006507 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006508 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006509 break;
6510 }
James Smart2e0fef82007-06-17 19:56:36 -05006511 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006512 break;
6513 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006514 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6515 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6516 did, vport->port_state, ndlp->nlp_flag);
6517
dea31012005-04-17 16:05:31 -05006518 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006519 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006520 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006521 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006522 break;
6523 }
James Smart2e0fef82007-06-17 19:56:36 -05006524 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006525 break;
6526 case ELS_CMD_RSCN:
6527 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006528 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006529 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006530 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006531 break;
6532 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006533 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6534 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6535 did, vport->port_state, ndlp->nlp_flag);
6536
James Smartddcc50f2008-12-04 22:38:46 -05006537 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006538 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006539 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006540 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006541 break;
6542 }
James Smart2e0fef82007-06-17 19:56:36 -05006543 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6544 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006545 break;
6546 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006547 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6548 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6549 did, vport->port_state, ndlp->nlp_flag);
6550
dea31012005-04-17 16:05:31 -05006551 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006552 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006553 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006554 break;
6555 }
James Smart2e0fef82007-06-17 19:56:36 -05006556 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6557 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006558 break;
6559 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006560 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6561 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6562 did, vport->port_state, ndlp->nlp_flag);
6563
dea31012005-04-17 16:05:31 -05006564 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006565 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006566 break;
6567 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006568 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6569 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6570 did, vport->port_state, ndlp->nlp_flag);
6571
dea31012005-04-17 16:05:31 -05006572 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006573 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006574 break;
6575 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006576 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6577 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6578 did, vport->port_state, ndlp->nlp_flag);
6579
dea31012005-04-17 16:05:31 -05006580 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006581 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006582 break;
dea31012005-04-17 16:05:31 -05006583 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006584 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6585 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6586 did, vport->port_state, ndlp->nlp_flag);
6587
dea31012005-04-17 16:05:31 -05006588 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006589 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006590 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006591 break;
6592 }
James Smart2e0fef82007-06-17 19:56:36 -05006593 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006594 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006595 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006596 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6597 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6598 did, vport->port_state, ndlp->nlp_flag);
6599
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006600 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006601 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006602 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006603 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006604 break;
James Smart12265f62010-10-22 11:05:53 -04006605 case ELS_CMD_RLS:
6606 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6607 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6608 did, vport->port_state, ndlp->nlp_flag);
6609
6610 phba->fc_stat.elsRcvRLS++;
6611 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6612 if (newnode)
6613 lpfc_nlp_put(ndlp);
6614 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006615 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006616 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6617 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6618 did, vport->port_state, ndlp->nlp_flag);
6619
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006620 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006621 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006622 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006623 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006624 break;
6625 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006626 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6627 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6628 did, vport->port_state, ndlp->nlp_flag);
6629
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006630 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006631 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006632 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006633 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006634 break;
dea31012005-04-17 16:05:31 -05006635 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006636 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6637 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6638 did, vport->port_state, ndlp->nlp_flag);
6639
dea31012005-04-17 16:05:31 -05006640 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006641 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006642 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006643 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006644 break;
James Smart12265f62010-10-22 11:05:53 -04006645 case ELS_CMD_RTV:
6646 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6647 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6648 did, vport->port_state, ndlp->nlp_flag);
6649 phba->fc_stat.elsRcvRTV++;
6650 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6651 if (newnode)
6652 lpfc_nlp_put(ndlp);
6653 break;
James Smart5ffc2662009-11-18 15:39:44 -05006654 case ELS_CMD_RRQ:
6655 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6656 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6657 did, vport->port_state, ndlp->nlp_flag);
6658
6659 phba->fc_stat.elsRcvRRQ++;
6660 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6661 if (newnode)
6662 lpfc_nlp_put(ndlp);
6663 break;
James Smart12265f62010-10-22 11:05:53 -04006664 case ELS_CMD_ECHO:
6665 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6666 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6667 did, vport->port_state, ndlp->nlp_flag);
6668
6669 phba->fc_stat.elsRcvECHO++;
6670 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6671 if (newnode)
6672 lpfc_nlp_put(ndlp);
6673 break;
dea31012005-04-17 16:05:31 -05006674 default:
James Smart858c9f62007-06-17 19:56:39 -05006675 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6676 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6677 cmd, did, vport->port_state);
6678
dea31012005-04-17 16:05:31 -05006679 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006680 rjt_err = LSRJT_CMD_UNSUPPORTED;
dea31012005-04-17 16:05:31 -05006681
6682 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006683 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6684 "0115 Unknown ELS command x%x "
6685 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006686 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006687 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006688 break;
6689 }
6690
6691 /* check if need to LS_RJT received ELS cmd */
6692 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006693 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006694 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006695 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006696 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6697 NULL);
dea31012005-04-17 16:05:31 -05006698 }
6699
James Smartd7c255b2008-08-24 21:50:00 -04006700 lpfc_nlp_put(elsiocb->context1);
6701 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006702 return;
6703
6704dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006705 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006706 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6707 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006708 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006709 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006710 phba->fc_stat.elsRcvDrop++;
6711}
6712
James Smarte59058c2008-08-24 21:49:00 -04006713/**
James Smart3621a712009-04-06 18:47:14 -04006714 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006715 * @phba: pointer to lpfc hba data structure.
6716 * @pring: pointer to a SLI ring.
6717 * @elsiocb: pointer to lpfc els iocb data structure.
6718 *
6719 * This routine is used to process an unsolicited event received from a SLI
6720 * (Service Level Interface) ring. The actual processing of the data buffer
6721 * associated with the unsolicited event is done by invoking the routine
6722 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6723 * SLI ring on which the unsolicited event was received.
6724 **/
James Smarted957682007-06-17 19:56:37 -05006725void
6726lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6727 struct lpfc_iocbq *elsiocb)
6728{
6729 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006730 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006731 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006732 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6733 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006734
James Smartd7c255b2008-08-24 21:50:00 -04006735 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006736 elsiocb->context2 = NULL;
6737 elsiocb->context3 = NULL;
6738
6739 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6740 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6741 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6742 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006743 phba->fc_stat.NoRcvBuf++;
6744 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006745 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006746 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006747 return;
6748 }
6749
James Smart92d7f7b2007-06-17 19:56:38 -05006750 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6751 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6752 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6753 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6754 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006755 else
6756 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04006757 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05006758 }
James Smart6d368e52011-05-24 11:44:12 -04006759
James Smart7f5f3d02008-02-08 18:50:14 -05006760 /* If there are no BDEs associated
6761 * with this IOCB, there is nothing to do.
6762 */
James Smarted957682007-06-17 19:56:37 -05006763 if (icmd->ulpBdeCount == 0)
6764 return;
6765
James Smart7f5f3d02008-02-08 18:50:14 -05006766 /* type of ELS cmd is first 32bit word
6767 * in packet
6768 */
James Smarted957682007-06-17 19:56:37 -05006769 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006770 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006771 } else {
6772 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6773 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006774 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6775 paddr);
James Smarted957682007-06-17 19:56:37 -05006776 }
6777
James Smart92d7f7b2007-06-17 19:56:38 -05006778 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6779 /*
6780 * The different unsolicited event handlers would tell us
6781 * if they are done with "mp" by setting context2 to NULL.
6782 */
dea31012005-04-17 16:05:31 -05006783 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006784 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6785 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006786 }
James Smarted957682007-06-17 19:56:37 -05006787
6788 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006789 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006790 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006791 elsiocb->context2 = bdeBuf2;
6792 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006793 /* free mp if we are done with it */
6794 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006795 lpfc_in_buf_free(phba, elsiocb->context2);
6796 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006797 }
dea31012005-04-17 16:05:31 -05006798 }
dea31012005-04-17 16:05:31 -05006799}
James Smart92d7f7b2007-06-17 19:56:38 -05006800
James Smarte59058c2008-08-24 21:49:00 -04006801/**
James Smart3621a712009-04-06 18:47:14 -04006802 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006803 * @phba: pointer to lpfc hba data structure.
6804 * @vport: pointer to a virtual N_Port data structure.
6805 *
6806 * This routine issues a Port Login (PLOGI) to the Name Server with
6807 * State Change Request (SCR) for a @vport. This routine will create an
6808 * ndlp for the Name Server associated to the @vport if such node does
6809 * not already exist. The PLOGI to Name Server is issued by invoking the
6810 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6811 * (FDMI) is configured to the @vport, a FDMI node will be created and
6812 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6813 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006814void
6815lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6816{
6817 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05006818 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6819
6820 /*
6821 * If lpfc_delay_discovery parameter is set and the clean address
6822 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6823 * discovery.
6824 */
6825 spin_lock_irq(shost->host_lock);
6826 if (vport->fc_flag & FC_DISC_DELAYED) {
6827 spin_unlock_irq(shost->host_lock);
6828 mod_timer(&vport->delayed_disc_tmo,
6829 jiffies + HZ * phba->fc_ratov);
6830 return;
6831 }
6832 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006833
6834 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6835 if (!ndlp) {
6836 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6837 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006838 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05006839 lpfc_disc_start(vport);
6840 return;
6841 }
6842 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006843 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6844 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006845 return;
6846 }
6847 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006848 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6849 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6850 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006851 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05006852 lpfc_disc_start(vport);
6853 return;
6854 }
6855 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6856 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6857 "0348 NameServer login: node freed\n");
6858 return;
6859 }
James Smart92d7f7b2007-06-17 19:56:38 -05006860 }
James Smart58da1ff2008-04-07 10:15:56 -04006861 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006862
6863 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6864
6865 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6866 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006867 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6868 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006869 return;
6870 }
6871
James Smart3de2a652007-08-02 11:09:59 -04006872 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05006873 /* If this is the first time, allocate an ndlp and initialize
6874 * it. Otherwise, make sure the node is enabled and then do the
6875 * login.
6876 */
6877 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
6878 if (!ndlp_fdmi) {
6879 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6880 GFP_KERNEL);
6881 if (ndlp_fdmi) {
6882 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6883 ndlp_fdmi->nlp_type |= NLP_FABRIC;
6884 } else
6885 return;
6886 }
6887 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
6888 ndlp_fdmi = lpfc_enable_node(vport,
6889 ndlp_fdmi,
6890 NLP_STE_NPR_NODE);
6891
James Smart92d7f7b2007-06-17 19:56:38 -05006892 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04006893 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05006894 NLP_STE_PLOGI_ISSUE);
6895 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006896 }
6897 }
James Smart92d7f7b2007-06-17 19:56:38 -05006898}
6899
James Smarte59058c2008-08-24 21:49:00 -04006900/**
James Smart3621a712009-04-06 18:47:14 -04006901 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006902 * @phba: pointer to lpfc hba data structure.
6903 * @pmb: pointer to the driver internal queue element for mailbox command.
6904 *
6905 * This routine is the completion callback function to register new vport
6906 * mailbox command. If the new vport mailbox command completes successfully,
6907 * the fabric registration login shall be performed on physical port (the
6908 * new vport created is actually a physical port, with VPI 0) or the port
6909 * login to Name Server for State Change Request (SCR) will be performed
6910 * on virtual port (real virtual port, with VPI greater than 0).
6911 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006912static void
6913lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6914{
6915 struct lpfc_vport *vport = pmb->vport;
6916 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6917 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006918 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006919 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006920
James Smart09372822008-01-11 01:52:54 -05006921 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006922 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006923 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006924
6925 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006926 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006927 "0915 Register VPI failed : Status: x%x"
6928 " upd bit: x%x \n", mb->mbxStatus,
6929 mb->un.varRegVpi.upd);
6930 if (phba->sli_rev == LPFC_SLI_REV4 &&
6931 mb->un.varRegVpi.upd)
6932 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006933
6934 switch (mb->mbxStatus) {
6935 case 0x11: /* unsupported feature */
6936 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006937 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006938 /* giving up on vport registration */
6939 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6940 spin_lock_irq(shost->host_lock);
6941 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6942 spin_unlock_irq(shost->host_lock);
6943 lpfc_can_disctmo(vport);
6944 break;
James Smart695a8142010-01-26 23:08:03 -05006945 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6946 case 0x20:
6947 spin_lock_irq(shost->host_lock);
6948 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6949 spin_unlock_irq(shost->host_lock);
6950 lpfc_init_vpi(phba, pmb, vport->vpi);
6951 pmb->vport = vport;
6952 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6953 rc = lpfc_sli_issue_mbox(phba, pmb,
6954 MBX_NOWAIT);
6955 if (rc == MBX_NOT_FINISHED) {
6956 lpfc_printf_vlog(vport,
6957 KERN_ERR, LOG_MBOX,
6958 "2732 Failed to issue INIT_VPI"
6959 " mailbox command\n");
6960 } else {
6961 lpfc_nlp_put(ndlp);
6962 return;
6963 }
6964
James Smart92d7f7b2007-06-17 19:56:38 -05006965 default:
6966 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04006967 if (phba->sli_rev == LPFC_SLI_REV4)
6968 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006969 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006970 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006971 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006972 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006973 if (vport->port_type == LPFC_PHYSICAL_PORT
6974 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05006975 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05006976 else
6977 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006978 break;
6979 }
James Smart92d7f7b2007-06-17 19:56:38 -05006980 } else {
James Smart695a8142010-01-26 23:08:03 -05006981 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006982 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006983 spin_unlock_irq(shost->host_lock);
6984 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006985 if (phba->sli_rev < LPFC_SLI_REV4)
6986 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006987 else {
James Smartfc2b9892010-02-26 14:15:29 -05006988 /*
6989 * If the physical port is instantiated using
6990 * FDISC, do not start vport discovery.
6991 */
6992 if (vport->port_state != LPFC_FDISC)
6993 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006994 lpfc_do_scr_ns_plogi(phba, vport);
6995 }
6996 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006997 lpfc_do_scr_ns_plogi(phba, vport);
6998 }
James Smart38b92ef2010-08-04 16:11:39 -04006999mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05007000 /* Now, we decrement the ndlp reference count held for this
7001 * callback function
7002 */
7003 lpfc_nlp_put(ndlp);
7004
James Smart92d7f7b2007-06-17 19:56:38 -05007005 mempool_free(pmb, phba->mbox_mem_pool);
7006 return;
7007}
7008
James Smarte59058c2008-08-24 21:49:00 -04007009/**
James Smart3621a712009-04-06 18:47:14 -04007010 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04007011 * @phba: pointer to lpfc hba data structure.
7012 * @vport: pointer to a host virtual N_Port data structure.
7013 * @ndlp: pointer to a node-list data structure.
7014 *
7015 * This routine registers the @vport as a new virtual port with a HBA.
7016 * It is done through a registering vpi mailbox command.
7017 **/
James Smart695a8142010-01-26 23:08:03 -05007018void
James Smart92d7f7b2007-06-17 19:56:38 -05007019lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
7020 struct lpfc_nodelist *ndlp)
7021{
James Smart09372822008-01-11 01:52:54 -05007022 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007023 LPFC_MBOXQ_t *mbox;
7024
7025 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7026 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04007027 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05007028 mbox->vport = vport;
7029 mbox->context2 = lpfc_nlp_get(ndlp);
7030 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04007031 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05007032 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05007033 /* mailbox command not success, decrement ndlp
7034 * reference count for this command
7035 */
7036 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007037 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05007038
James Smarte8b62012007-08-02 11:10:09 -04007039 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7040 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05007041 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007042 }
7043 } else {
James Smarte8b62012007-08-02 11:10:09 -04007044 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7045 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05007046 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007047 }
James Smartfa4066b2008-01-11 01:53:27 -05007048 return;
7049
7050mbox_err_exit:
7051 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7052 spin_lock_irq(shost->host_lock);
7053 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
7054 spin_unlock_irq(shost->host_lock);
7055 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007056}
7057
James Smarte59058c2008-08-24 21:49:00 -04007058/**
James Smart0c9ab6f2010-02-26 14:15:57 -05007059 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05007060 * @phba: pointer to lpfc hba data structure.
7061 *
James Smart0c9ab6f2010-02-26 14:15:57 -05007062 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05007063 **/
7064void
James Smart0c9ab6f2010-02-26 14:15:57 -05007065lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05007066{
7067 struct lpfc_vport **vports;
7068 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05007069 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05007070 int i;
James Smart695a8142010-01-26 23:08:03 -05007071
7072 /* Treat this failure as linkdown for all vports */
7073 link_state = phba->link_state;
7074 lpfc_linkdown(phba);
7075 phba->link_state = link_state;
7076
7077 vports = lpfc_create_vport_work_array(phba);
7078
7079 if (vports) {
7080 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
7081 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
7082 if (ndlp)
7083 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
7084 lpfc_els_flush_cmd(vports[i]);
7085 }
7086 lpfc_destroy_vport_work_array(phba, vports);
7087 }
James Smart0c9ab6f2010-02-26 14:15:57 -05007088}
7089
7090/**
7091 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7092 * @phba: pointer to lpfc hba data structure.
7093 *
7094 * This routine abort all pending discovery commands and
7095 * start a timer to retry FLOGI for the physical port
7096 * discovery.
7097 **/
7098void
7099lpfc_retry_pport_discovery(struct lpfc_hba *phba)
7100{
7101 struct lpfc_nodelist *ndlp;
7102 struct Scsi_Host *shost;
7103
7104 /* Cancel the all vports retry delay retry timers */
7105 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05007106
7107 /* If fabric require FLOGI, then re-instantiate physical login */
7108 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
7109 if (!ndlp)
7110 return;
7111
James Smart695a8142010-01-26 23:08:03 -05007112 shost = lpfc_shost_from_vport(phba->pport);
7113 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
7114 spin_lock_irq(shost->host_lock);
7115 ndlp->nlp_flag |= NLP_DELAY_TMO;
7116 spin_unlock_irq(shost->host_lock);
7117 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7118 phba->pport->port_state = LPFC_FLOGI;
7119 return;
7120}
7121
7122/**
7123 * lpfc_fabric_login_reqd - Check if FLOGI required.
7124 * @phba: pointer to lpfc hba data structure.
7125 * @cmdiocb: pointer to FDISC command iocb.
7126 * @rspiocb: pointer to FDISC response iocb.
7127 *
7128 * This routine checks if a FLOGI is reguired for FDISC
7129 * to succeed.
7130 **/
7131static int
7132lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7133 struct lpfc_iocbq *cmdiocb,
7134 struct lpfc_iocbq *rspiocb)
7135{
7136
7137 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7138 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7139 return 0;
7140 else
7141 return 1;
7142}
7143
7144/**
James Smart3621a712009-04-06 18:47:14 -04007145 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007146 * @phba: pointer to lpfc hba data structure.
7147 * @cmdiocb: pointer to lpfc command iocb data structure.
7148 * @rspiocb: pointer to lpfc response iocb data structure.
7149 *
7150 * This routine is the completion callback function to a Fabric Discover
7151 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7152 * single threaded, each FDISC completion callback function will reset
7153 * the discovery timer for all vports such that the timers will not get
7154 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7155 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7156 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7157 * assigned to the vport has been changed with the completion of the FDISC
7158 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7159 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7160 * routine is invoked to register new vport with the HBA. Otherwise, the
7161 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7162 * Server for State Change Request (SCR).
7163 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007164static void
7165lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7166 struct lpfc_iocbq *rspiocb)
7167{
7168 struct lpfc_vport *vport = cmdiocb->vport;
7169 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7170 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7171 struct lpfc_nodelist *np;
7172 struct lpfc_nodelist *next_np;
7173 IOCB_t *irsp = &rspiocb->iocb;
7174 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05007175 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7176 struct serv_parm *sp;
7177 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05007178
James Smarte8b62012007-08-02 11:10:09 -04007179 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7180 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7181 irsp->ulpStatus, irsp->un.ulpWord[4],
7182 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05007183 /* Since all FDISCs are being single threaded, we
7184 * must reset the discovery timer for ALL vports
7185 * waiting to send FDISC when one completes.
7186 */
7187 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7188 lpfc_set_disctmo(piocb->vport);
7189 }
7190
James Smart858c9f62007-06-17 19:56:39 -05007191 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7192 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7193 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7194
James Smart92d7f7b2007-06-17 19:56:38 -05007195 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05007196
7197 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7198 lpfc_retry_pport_discovery(phba);
7199 goto out;
7200 }
7201
James Smart92d7f7b2007-06-17 19:56:38 -05007202 /* Check for retry */
7203 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7204 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007205 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04007206 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart6b5151f2012-01-18 16:24:06 -05007207 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04007208 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04007209 goto fdisc_failed;
7210 }
James Smartd7c255b2008-08-24 21:50:00 -04007211 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05007212 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04007213 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04007214 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05007215 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04007216 vport->fc_flag |= FC_PUBLIC_LOOP;
7217 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007218
James Smartd7c255b2008-08-24 21:50:00 -04007219 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7220 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05007221 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7222 sp = prsp->virt + sizeof(uint32_t);
7223 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7224 memcpy(&vport->fabric_portname, &sp->portName,
7225 sizeof(struct lpfc_name));
7226 memcpy(&vport->fabric_nodename, &sp->nodeName,
7227 sizeof(struct lpfc_name));
7228 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04007229 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7230 /* If our NportID changed, we need to ensure all
7231 * remaining NPORTs get unreg_login'ed so we can
7232 * issue unreg_vpi.
7233 */
7234 list_for_each_entry_safe(np, next_np,
7235 &vport->fc_nodes, nlp_listp) {
7236 if (!NLP_CHK_NODE_ACT(ndlp) ||
7237 (np->nlp_state != NLP_STE_NPR_NODE) ||
7238 !(np->nlp_flag & NLP_NPR_ADISC))
7239 continue;
James Smart09372822008-01-11 01:52:54 -05007240 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007241 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007242 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007243 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007244 }
James Smart78730cf2010-04-06 15:06:30 -04007245 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007246
7247 if (phba->sli_rev == LPFC_SLI_REV4)
7248 lpfc_sli4_unreg_all_rpis(vport);
7249
James Smartd7c255b2008-08-24 21:50:00 -04007250 lpfc_mbx_unreg_vpi(vport);
7251 spin_lock_irq(shost->host_lock);
7252 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007253 if (phba->sli_rev == LPFC_SLI_REV4)
7254 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007255 else
7256 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007257 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007258 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7259 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7260 /*
7261 * Driver needs to re-reg VPI in order for f/w
7262 * to update the MAC address.
7263 */
7264 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007265 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007266 }
7267
James Smartecfd03c2010-02-12 14:41:27 -05007268 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7269 lpfc_issue_init_vpi(vport);
7270 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007271 lpfc_register_new_vport(phba, vport, ndlp);
7272 else
7273 lpfc_do_scr_ns_plogi(phba, vport);
7274 goto out;
7275fdisc_failed:
7276 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7277 /* Cancel discovery timer */
7278 lpfc_can_disctmo(vport);
7279 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007280out:
7281 lpfc_els_free_iocb(phba, cmdiocb);
7282}
7283
James Smarte59058c2008-08-24 21:49:00 -04007284/**
James Smart3621a712009-04-06 18:47:14 -04007285 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007286 * @vport: pointer to a virtual N_Port data structure.
7287 * @ndlp: pointer to a node-list data structure.
7288 * @retry: number of retries to the command IOCB.
7289 *
7290 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7291 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7292 * routine to issue the IOCB, which makes sure only one outstanding fabric
7293 * IOCB will be sent off HBA at any given time.
7294 *
7295 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7296 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7297 * will be stored into the context1 field of the IOCB for the completion
7298 * callback function to the FDISC ELS command.
7299 *
7300 * Return code
7301 * 0 - Successfully issued fdisc iocb command
7302 * 1 - Failed to issue fdisc iocb command
7303 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007304static int
James Smart92d7f7b2007-06-17 19:56:38 -05007305lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7306 uint8_t retry)
7307{
7308 struct lpfc_hba *phba = vport->phba;
7309 IOCB_t *icmd;
7310 struct lpfc_iocbq *elsiocb;
7311 struct serv_parm *sp;
7312 uint8_t *pcmd;
7313 uint16_t cmdsize;
7314 int did = ndlp->nlp_DID;
7315 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007316
James Smart5ffc2662009-11-18 15:39:44 -05007317 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05007318 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007319 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7320 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7321 ELS_CMD_FDISC);
7322 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007323 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007324 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7325 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007326 return 1;
7327 }
7328
7329 icmd = &elsiocb->iocb;
7330 icmd->un.elsreq64.myID = 0;
7331 icmd->un.elsreq64.fl = 1;
7332
James Smart73d91e52011-10-10 21:32:10 -04007333 /*
7334 * SLI3 ports require a different context type value than SLI4.
7335 * Catch SLI3 ports here and override the prep.
7336 */
7337 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04007338 icmd->ulpCt_h = 1;
7339 icmd->ulpCt_l = 0;
7340 }
James Smart92d7f7b2007-06-17 19:56:38 -05007341
7342 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7343 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7344 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7345 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7346 sp = (struct serv_parm *) pcmd;
7347 /* Setup CSPs accordingly for Fabric */
7348 sp->cmn.e_d_tov = 0;
7349 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05007350 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007351 sp->cls1.classValid = 0;
7352 sp->cls2.seqDelivery = 1;
7353 sp->cls3.seqDelivery = 1;
7354
7355 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7356 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7357 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7358 pcmd += sizeof(uint32_t); /* Port Name */
7359 memcpy(pcmd, &vport->fc_portname, 8);
7360 pcmd += sizeof(uint32_t); /* Node Name */
7361 pcmd += sizeof(uint32_t); /* Node Name */
7362 memcpy(pcmd, &vport->fc_nodename, 8);
7363
7364 lpfc_set_disctmo(vport);
7365
7366 phba->fc_stat.elsXmitFDISC++;
7367 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7368
James Smart858c9f62007-06-17 19:56:39 -05007369 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7370 "Issue FDISC: did:x%x",
7371 did, 0, 0);
7372
James Smart92d7f7b2007-06-17 19:56:38 -05007373 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7374 if (rc == IOCB_ERROR) {
7375 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007376 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007377 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7378 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007379 return 1;
7380 }
7381 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007382 return 0;
7383}
7384
James Smarte59058c2008-08-24 21:49:00 -04007385/**
James Smart3621a712009-04-06 18:47:14 -04007386 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007387 * @phba: pointer to lpfc hba data structure.
7388 * @cmdiocb: pointer to lpfc command iocb data structure.
7389 * @rspiocb: pointer to lpfc response iocb data structure.
7390 *
7391 * This routine is the completion callback function to the issuing of a LOGO
7392 * ELS command off a vport. It frees the command IOCB and then decrement the
7393 * reference count held on ndlp for this completion function, indicating that
7394 * the reference to the ndlp is no long needed. Note that the
7395 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7396 * callback function and an additional explicit ndlp reference decrementation
7397 * will trigger the actual release of the ndlp.
7398 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007399static void
7400lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7401 struct lpfc_iocbq *rspiocb)
7402{
7403 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007404 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007405 struct lpfc_nodelist *ndlp;
James Smart9589b062011-04-16 11:03:17 -04007406 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05007407
James Smart9589b062011-04-16 11:03:17 -04007408 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007409 irsp = &rspiocb->iocb;
7410 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7411 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7412 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007413
7414 lpfc_els_free_iocb(phba, cmdiocb);
7415 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007416
7417 /* Trigger the release of the ndlp after logo */
7418 lpfc_nlp_put(ndlp);
James Smart9589b062011-04-16 11:03:17 -04007419
7420 /* NPIV LOGO completes to NPort <nlp_DID> */
7421 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7422 "2928 NPIV LOGO completes to NPort x%x "
7423 "Data: x%x x%x x%x x%x\n",
7424 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
7425 irsp->ulpTimeout, vport->num_disc_nodes);
7426
7427 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
7428 spin_lock_irq(shost->host_lock);
7429 vport->fc_flag &= ~FC_FABRIC;
7430 spin_unlock_irq(shost->host_lock);
7431 }
James Smart92d7f7b2007-06-17 19:56:38 -05007432}
7433
James Smarte59058c2008-08-24 21:49:00 -04007434/**
James Smart3621a712009-04-06 18:47:14 -04007435 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007436 * @vport: pointer to a virtual N_Port data structure.
7437 * @ndlp: pointer to a node-list data structure.
7438 *
7439 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7440 *
7441 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7442 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7443 * will be stored into the context1 field of the IOCB for the completion
7444 * callback function to the LOGO ELS command.
7445 *
7446 * Return codes
7447 * 0 - Successfully issued logo off the @vport
7448 * 1 - Failed to issue logo off the @vport
7449 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007450int
7451lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7452{
7453 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7454 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007455 IOCB_t *icmd;
7456 struct lpfc_iocbq *elsiocb;
7457 uint8_t *pcmd;
7458 uint16_t cmdsize;
7459
7460 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7461 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7462 ELS_CMD_LOGO);
7463 if (!elsiocb)
7464 return 1;
7465
7466 icmd = &elsiocb->iocb;
7467 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7468 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7469 pcmd += sizeof(uint32_t);
7470
7471 /* Fill in LOGO payload */
7472 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7473 pcmd += sizeof(uint32_t);
7474 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7475
James Smart858c9f62007-06-17 19:56:39 -05007476 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7477 "Issue LOGO npiv did:x%x flg:x%x",
7478 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7479
James Smart92d7f7b2007-06-17 19:56:38 -05007480 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7481 spin_lock_irq(shost->host_lock);
7482 ndlp->nlp_flag |= NLP_LOGO_SND;
7483 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007484 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7485 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007486 spin_lock_irq(shost->host_lock);
7487 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7488 spin_unlock_irq(shost->host_lock);
7489 lpfc_els_free_iocb(phba, elsiocb);
7490 return 1;
7491 }
7492 return 0;
7493}
7494
James Smarte59058c2008-08-24 21:49:00 -04007495/**
James Smart3621a712009-04-06 18:47:14 -04007496 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007497 * @ptr: holder for the timer function associated data.
7498 *
7499 * This routine is invoked by the fabric iocb block timer after
7500 * timeout. It posts the fabric iocb block timeout event by setting the
7501 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7502 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7503 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7504 * posted event WORKER_FABRIC_BLOCK_TMO.
7505 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007506void
7507lpfc_fabric_block_timeout(unsigned long ptr)
7508{
7509 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7510 unsigned long iflags;
7511 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007512
James Smart92d7f7b2007-06-17 19:56:38 -05007513 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7514 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7515 if (!tmo_posted)
7516 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7517 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7518
James Smart5e9d9b82008-06-14 22:52:53 -04007519 if (!tmo_posted)
7520 lpfc_worker_wake_up(phba);
7521 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007522}
7523
James Smarte59058c2008-08-24 21:49:00 -04007524/**
James Smart3621a712009-04-06 18:47:14 -04007525 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007526 * @phba: pointer to lpfc hba data structure.
7527 *
7528 * This routine issues one fabric iocb from the driver internal list to
7529 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7530 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7531 * remove one pending fabric iocb from the driver internal list and invokes
7532 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7533 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007534static void
7535lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7536{
7537 struct lpfc_iocbq *iocb;
7538 unsigned long iflags;
7539 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007540 IOCB_t *cmd;
7541
7542repeat:
7543 iocb = NULL;
7544 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007545 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007546 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7547 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7548 list);
7549 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007550 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007551 atomic_inc(&phba->fabric_iocb_count);
7552 }
7553 spin_unlock_irqrestore(&phba->hbalock, iflags);
7554 if (iocb) {
7555 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7556 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7557 iocb->iocb_flag |= LPFC_IO_FABRIC;
7558
James Smart858c9f62007-06-17 19:56:39 -05007559 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7560 "Fabric sched1: ste:x%x",
7561 iocb->vport->port_state, 0, 0);
7562
James Smart3772a992009-05-22 14:50:54 -04007563 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007564
7565 if (ret == IOCB_ERROR) {
7566 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7567 iocb->fabric_iocb_cmpl = NULL;
7568 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7569 cmd = &iocb->iocb;
7570 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7571 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7572 iocb->iocb_cmpl(phba, iocb, iocb);
7573
7574 atomic_dec(&phba->fabric_iocb_count);
7575 goto repeat;
7576 }
7577 }
7578
7579 return;
7580}
7581
James Smarte59058c2008-08-24 21:49:00 -04007582/**
James Smart3621a712009-04-06 18:47:14 -04007583 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007584 * @phba: pointer to lpfc hba data structure.
7585 *
7586 * This routine unblocks the issuing fabric iocb command. The function
7587 * will clear the fabric iocb block bit and then invoke the routine
7588 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7589 * from the driver internal fabric iocb list.
7590 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007591void
7592lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7593{
7594 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7595
7596 lpfc_resume_fabric_iocbs(phba);
7597 return;
7598}
7599
James Smarte59058c2008-08-24 21:49:00 -04007600/**
James Smart3621a712009-04-06 18:47:14 -04007601 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007602 * @phba: pointer to lpfc hba data structure.
7603 *
7604 * This routine blocks the issuing fabric iocb for a specified amount of
7605 * time (currently 100 ms). This is done by set the fabric iocb block bit
7606 * and set up a timeout timer for 100ms. When the block bit is set, no more
7607 * fabric iocb will be issued out of the HBA.
7608 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007609static void
7610lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7611{
7612 int blocked;
7613
7614 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007615 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007616 if (!blocked)
7617 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7618
7619 return;
7620}
7621
James Smarte59058c2008-08-24 21:49:00 -04007622/**
James Smart3621a712009-04-06 18:47:14 -04007623 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007624 * @phba: pointer to lpfc hba data structure.
7625 * @cmdiocb: pointer to lpfc command iocb data structure.
7626 * @rspiocb: pointer to lpfc response iocb data structure.
7627 *
7628 * This routine is the callback function that is put to the fabric iocb's
7629 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7630 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7631 * function first restores and invokes the original iocb's callback function
7632 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7633 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7634 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007635static void
7636lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7637 struct lpfc_iocbq *rspiocb)
7638{
7639 struct ls_rjt stat;
7640
7641 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7642 BUG();
7643
7644 switch (rspiocb->iocb.ulpStatus) {
7645 case IOSTAT_NPORT_RJT:
7646 case IOSTAT_FABRIC_RJT:
7647 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7648 lpfc_block_fabric_iocbs(phba);
7649 }
7650 break;
7651
7652 case IOSTAT_NPORT_BSY:
7653 case IOSTAT_FABRIC_BSY:
7654 lpfc_block_fabric_iocbs(phba);
7655 break;
7656
7657 case IOSTAT_LS_RJT:
7658 stat.un.lsRjtError =
7659 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7660 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7661 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7662 lpfc_block_fabric_iocbs(phba);
7663 break;
7664 }
7665
7666 if (atomic_read(&phba->fabric_iocb_count) == 0)
7667 BUG();
7668
7669 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7670 cmdiocb->fabric_iocb_cmpl = NULL;
7671 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7672 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7673
7674 atomic_dec(&phba->fabric_iocb_count);
7675 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007676 /* Post any pending iocbs to HBA */
7677 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007678 }
7679}
7680
James Smarte59058c2008-08-24 21:49:00 -04007681/**
James Smart3621a712009-04-06 18:47:14 -04007682 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007683 * @phba: pointer to lpfc hba data structure.
7684 * @iocb: pointer to lpfc command iocb data structure.
7685 *
7686 * This routine is used as the top-level API for issuing a fabric iocb command
7687 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7688 * function makes sure that only one fabric bound iocb will be outstanding at
7689 * any given time. As such, this function will first check to see whether there
7690 * is already an outstanding fabric iocb on the wire. If so, it will put the
7691 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7692 * issued later. Otherwise, it will issue the iocb on the wire and update the
7693 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7694 *
7695 * Note, this implementation has a potential sending out fabric IOCBs out of
7696 * order. The problem is caused by the construction of the "ready" boolen does
7697 * not include the condition that the internal fabric IOCB list is empty. As
7698 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7699 * ahead of the fabric IOCBs in the internal list.
7700 *
7701 * Return code
7702 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7703 * IOCB_ERROR - failed to issue fabric iocb
7704 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007705static int
James Smart92d7f7b2007-06-17 19:56:38 -05007706lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7707{
7708 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007709 int ready;
7710 int ret;
7711
7712 if (atomic_read(&phba->fabric_iocb_count) > 1)
7713 BUG();
7714
7715 spin_lock_irqsave(&phba->hbalock, iflags);
7716 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7717 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7718
James Smart7f5f3d02008-02-08 18:50:14 -05007719 if (ready)
7720 /* Increment fabric iocb count to hold the position */
7721 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007722 spin_unlock_irqrestore(&phba->hbalock, iflags);
7723 if (ready) {
7724 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7725 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7726 iocb->iocb_flag |= LPFC_IO_FABRIC;
7727
James Smart858c9f62007-06-17 19:56:39 -05007728 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7729 "Fabric sched2: ste:x%x",
7730 iocb->vport->port_state, 0, 0);
7731
James Smart3772a992009-05-22 14:50:54 -04007732 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007733
7734 if (ret == IOCB_ERROR) {
7735 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7736 iocb->fabric_iocb_cmpl = NULL;
7737 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7738 atomic_dec(&phba->fabric_iocb_count);
7739 }
7740 } else {
7741 spin_lock_irqsave(&phba->hbalock, iflags);
7742 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7743 spin_unlock_irqrestore(&phba->hbalock, iflags);
7744 ret = IOCB_SUCCESS;
7745 }
7746 return ret;
7747}
7748
James Smarte59058c2008-08-24 21:49:00 -04007749/**
James Smart3621a712009-04-06 18:47:14 -04007750 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007751 * @vport: pointer to a virtual N_Port data structure.
7752 *
7753 * This routine aborts all the IOCBs associated with a @vport from the
7754 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7755 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7756 * list, removes each IOCB associated with the @vport off the list, set the
7757 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7758 * associated with the IOCB.
7759 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007760static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007761{
7762 LIST_HEAD(completions);
7763 struct lpfc_hba *phba = vport->phba;
7764 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007765
7766 spin_lock_irq(&phba->hbalock);
7767 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7768 list) {
7769
7770 if (piocb->vport != vport)
7771 continue;
7772
7773 list_move_tail(&piocb->list, &completions);
7774 }
7775 spin_unlock_irq(&phba->hbalock);
7776
James Smarta257bf92009-04-06 18:48:10 -04007777 /* Cancel all the IOCBs from the completions list */
7778 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7779 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007780}
7781
James Smarte59058c2008-08-24 21:49:00 -04007782/**
James Smart3621a712009-04-06 18:47:14 -04007783 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007784 * @ndlp: pointer to a node-list data structure.
7785 *
7786 * This routine aborts all the IOCBs associated with an @ndlp from the
7787 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7788 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7789 * list, removes each IOCB associated with the @ndlp off the list, set the
7790 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7791 * associated with the IOCB.
7792 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007793void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7794{
7795 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007796 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007797 struct lpfc_iocbq *tmp_iocb, *piocb;
7798 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007799
7800 spin_lock_irq(&phba->hbalock);
7801 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7802 list) {
7803 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7804
7805 list_move_tail(&piocb->list, &completions);
7806 }
7807 }
7808 spin_unlock_irq(&phba->hbalock);
7809
James Smarta257bf92009-04-06 18:48:10 -04007810 /* Cancel all the IOCBs from the completions list */
7811 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7812 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007813}
7814
James Smarte59058c2008-08-24 21:49:00 -04007815/**
James Smart3621a712009-04-06 18:47:14 -04007816 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007817 * @phba: pointer to lpfc hba data structure.
7818 *
7819 * This routine aborts all the IOCBs currently on the driver internal
7820 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7821 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7822 * list, removes IOCBs off the list, set the status feild to
7823 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7824 * the IOCB.
7825 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007826void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7827{
7828 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007829
7830 spin_lock_irq(&phba->hbalock);
7831 list_splice_init(&phba->fabric_iocb_list, &completions);
7832 spin_unlock_irq(&phba->hbalock);
7833
James Smarta257bf92009-04-06 18:48:10 -04007834 /* Cancel all the IOCBs from the completions list */
7835 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7836 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007837}
James Smart6fb120a2009-05-22 14:52:59 -04007838
7839/**
James Smart1151e3e2011-02-16 12:39:35 -05007840 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7841 * @vport: pointer to lpfc vport data structure.
7842 *
7843 * This routine is invoked by the vport cleanup for deletions and the cleanup
7844 * for an ndlp on removal.
7845 **/
7846void
7847lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
7848{
7849 struct lpfc_hba *phba = vport->phba;
7850 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7851 unsigned long iflag = 0;
7852
7853 spin_lock_irqsave(&phba->hbalock, iflag);
7854 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7855 list_for_each_entry_safe(sglq_entry, sglq_next,
7856 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7857 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
7858 sglq_entry->ndlp = NULL;
7859 }
7860 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7861 spin_unlock_irqrestore(&phba->hbalock, iflag);
7862 return;
7863}
7864
7865/**
James Smart6fb120a2009-05-22 14:52:59 -04007866 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7867 * @phba: pointer to lpfc hba data structure.
7868 * @axri: pointer to the els xri abort wcqe structure.
7869 *
7870 * This routine is invoked by the worker thread to process a SLI4 slow-path
7871 * ELS aborted xri.
7872 **/
7873void
7874lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7875 struct sli4_wcqe_xri_aborted *axri)
7876{
7877 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05007878 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04007879 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05007880
James Smart6fb120a2009-05-22 14:52:59 -04007881 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7882 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05007883 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04007884 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007885
James Smart0f65ff62010-02-26 14:14:23 -05007886 spin_lock_irqsave(&phba->hbalock, iflag);
7887 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007888 list_for_each_entry_safe(sglq_entry, sglq_next,
7889 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7890 if (sglq_entry->sli4_xritag == xri) {
7891 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05007892 ndlp = sglq_entry->ndlp;
7893 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04007894 list_add_tail(&sglq_entry->list,
7895 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007896 sglq_entry->state = SGL_FREED;
7897 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007898 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart19ca7602010-11-20 23:11:55 -05007899 lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04007900
7901 /* Check if TXQ queue needs to be serviced */
7902 if (pring->txq_cnt)
7903 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007904 return;
7905 }
7906 }
James Smart0f65ff62010-02-26 14:14:23 -05007907 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04007908 lxri = lpfc_sli4_xri_inrange(phba, xri);
7909 if (lxri == NO_XRI) {
7910 spin_unlock_irqrestore(&phba->hbalock, iflag);
7911 return;
7912 }
7913 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05007914 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7915 spin_unlock_irqrestore(&phba->hbalock, iflag);
7916 return;
7917 }
7918 sglq_entry->state = SGL_XRI_ABORTED;
7919 spin_unlock_irqrestore(&phba->hbalock, iflag);
7920 return;
James Smart6fb120a2009-05-22 14:52:59 -04007921}