blob: 8db2fb3b45ec13a40fd36ad3aa4c48cf9659b37c [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart92494142011-02-16 12:39:44 -05004 * Copyright (C) 2004-2011 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050021/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_transport_fc.h>
31
James Smartda0436e2009-05-22 14:51:39 -040032#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050033#include "lpfc_hw.h"
34#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040036#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_disc.h"
38#include "lpfc_scsi.h"
39#include "lpfc.h"
40#include "lpfc_logmsg.h"
41#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050042#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050043#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050044
45static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
46 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050047static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
48 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010049static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
50static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
51 struct lpfc_nodelist *ndlp, uint8_t retry);
52static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
53 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050054
dea31012005-04-17 16:05:31 -050055static int lpfc_max_els_tries = 3;
56
James Smarte59058c2008-08-24 21:49:00 -040057/**
James Smart3621a712009-04-06 18:47:14 -040058 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040059 * @vport: pointer to a host virtual N_Port data structure.
60 *
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
68 * had happened.
69 *
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
74 *
75 * Return codes
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
78 **/
James Smart858c9f62007-06-17 19:56:39 -050079int
James Smart2e0fef82007-06-17 19:56:36 -050080lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050081{
James Smart2e0fef82007-06-17 19:56:36 -050082 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
83 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050084 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050085
James Smart2e0fef82007-06-17 19:56:36 -050086 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040087 phba->link_state == LPFC_LINK_DOWN ||
88 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050089 return 0;
90
91 /* Read the HBA Host Attention Register */
James Smart9940b972011-03-11 16:06:12 -050092 if (lpfc_readl(phba->HAregaddr, &ha_copy))
93 return 1;
dea31012005-04-17 16:05:31 -050094
95 if (!(ha_copy & HA_LATT))
96 return 0;
97
98 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040099 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
100 "0237 Pending Link Event during "
101 "Discovery: State x%x\n",
102 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500103
104 /* CLEAR_LA should re-enable link attention events and
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300105 * we should then immediately take a LATT event. The
dea31012005-04-17 16:05:31 -0500106 * LATT processing should call lpfc_linkdown() which
107 * will cleanup any left over in-progress discovery
108 * events.
109 */
James Smart2e0fef82007-06-17 19:56:36 -0500110 spin_lock_irq(shost->host_lock);
111 vport->fc_flag |= FC_ABORT_DISCOVERY;
112 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500113
James Smart92d7f7b2007-06-17 19:56:38 -0500114 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500115 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500116
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500117 return 1;
dea31012005-04-17 16:05:31 -0500118}
119
James Smarte59058c2008-08-24 21:49:00 -0400120/**
James Smart3621a712009-04-06 18:47:14 -0400121 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400122 * @vport: pointer to a host virtual N_Port data structure.
123 * @expectRsp: flag indicating whether response is expected.
124 * @cmdSize: size of the ELS command.
125 * @retry: number of retries to the command IOCB when it fails.
126 * @ndlp: pointer to a node-list data structure.
127 * @did: destination identifier.
128 * @elscmd: the ELS command code.
129 *
130 * This routine is used for allocating a lpfc-IOCB data structure from
131 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
132 * passed into the routine for discovery state machine to issue an Extended
133 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
134 * and preparation routine that is used by all the discovery state machine
135 * routines and the ELS command-specific fields will be later set up by
136 * the individual discovery machine routines after calling this routine
137 * allocating and preparing a generic IOCB data structure. It fills in the
138 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
139 * payload and response payload (if expected). The reference count on the
140 * ndlp is incremented by 1 and the reference to the ndlp is put into
141 * context1 of the IOCB data structure for this IOCB to hold the ndlp
142 * reference for the command's callback function to access later.
143 *
144 * Return code
145 * Pointer to the newly allocated/prepared els iocb data structure
146 * NULL - when els iocb data structure allocation/preparation failed
147 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400148struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500149lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
150 uint16_t cmdSize, uint8_t retry,
151 struct lpfc_nodelist *ndlp, uint32_t did,
152 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500153{
James Smart2e0fef82007-06-17 19:56:36 -0500154 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400155 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500156 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
157 struct ulp_bde64 *bpl;
158 IOCB_t *icmd;
159
dea31012005-04-17 16:05:31 -0500160
James Smart2e0fef82007-06-17 19:56:36 -0500161 if (!lpfc_is_link_up(phba))
162 return NULL;
dea31012005-04-17 16:05:31 -0500163
dea31012005-04-17 16:05:31 -0500164 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400165 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500166
167 if (elsiocb == NULL)
168 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500169
James Smart0c287582009-06-10 17:22:56 -0400170 /*
171 * If this command is for fabric controller and HBA running
172 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
173 */
174 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400175 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400176 ((elscmd == ELS_CMD_FLOGI) ||
177 (elscmd == ELS_CMD_FDISC) ||
178 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500179 switch (elscmd) {
180 case ELS_CMD_FLOGI:
James Smartf0d9bcc2010-10-22 11:07:09 -0400181 elsiocb->iocb_flag |=
182 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500183 & LPFC_FIP_ELS_ID_MASK);
184 break;
185 case ELS_CMD_FDISC:
James Smartf0d9bcc2010-10-22 11:07:09 -0400186 elsiocb->iocb_flag |=
187 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500188 & LPFC_FIP_ELS_ID_MASK);
189 break;
190 case ELS_CMD_LOGO:
James Smartf0d9bcc2010-10-22 11:07:09 -0400191 elsiocb->iocb_flag |=
192 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500193 & LPFC_FIP_ELS_ID_MASK);
194 break;
195 }
James Smart0c287582009-06-10 17:22:56 -0400196 else
James Smartc8685952009-11-18 15:39:16 -0500197 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400198
dea31012005-04-17 16:05:31 -0500199 icmd = &elsiocb->iocb;
200
201 /* fill in BDEs for command */
202 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400203 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
204 if (pcmd)
205 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500206 if (!pcmd || !pcmd->virt)
207 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500208
209 INIT_LIST_HEAD(&pcmd->list);
210
211 /* Allocate buffer for response payload */
212 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500213 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500214 if (prsp)
215 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
216 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500217 if (!prsp || !prsp->virt)
218 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500219 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500220 } else
dea31012005-04-17 16:05:31 -0500221 prsp = NULL;
dea31012005-04-17 16:05:31 -0500222
223 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500224 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500225 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500226 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
227 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500228 if (!pbuflist || !pbuflist->virt)
229 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500230
231 INIT_LIST_HEAD(&pbuflist->list);
232
233 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
234 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400235 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart2e0fef82007-06-17 19:56:36 -0500236 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500237 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500238 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500239 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400240 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500241 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500242 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500243 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
244 }
dea31012005-04-17 16:05:31 -0500245 icmd->ulpBdeCount = 1;
246 icmd->ulpLe = 1;
247 icmd->ulpClass = CLASS3;
248
James Smart92d7f7b2007-06-17 19:56:38 -0500249 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
250 icmd->un.elsreq64.myID = vport->fc_myDID;
251
252 /* For ELS_REQUEST64_CR, use the VPI by default */
James Smart6d368e52011-05-24 11:44:12 -0400253 icmd->ulpContext = phba->vpi_ids[vport->vpi];
James Smart92d7f7b2007-06-17 19:56:38 -0500254 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500255 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
256 if (elscmd == ELS_CMD_ECHO)
257 icmd->ulpCt_l = 0; /* context = invalid RPI */
258 else
259 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500260 }
261
dea31012005-04-17 16:05:31 -0500262 bpl = (struct ulp_bde64 *) pbuflist->virt;
263 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
264 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
265 bpl->tus.f.bdeSize = cmdSize;
266 bpl->tus.f.bdeFlags = 0;
267 bpl->tus.w = le32_to_cpu(bpl->tus.w);
268
269 if (expectRsp) {
270 bpl++;
271 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
272 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
273 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400274 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500275 bpl->tus.w = le32_to_cpu(bpl->tus.w);
276 }
277
James Smartfa4066b2008-01-11 01:53:27 -0500278 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400279 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500280 if (!elsiocb->context1)
281 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400282 elsiocb->context2 = pcmd;
283 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500284 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500285 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500286 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
287
288 if (prsp) {
289 list_add(&prsp->list, &pcmd->list);
290 }
dea31012005-04-17 16:05:31 -0500291 if (expectRsp) {
292 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400293 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
294 "0116 Xmit ELS command x%x to remote "
295 "NPORT x%x I/O tag: x%x, port state: x%x\n",
296 elscmd, did, elsiocb->iotag,
297 vport->port_state);
dea31012005-04-17 16:05:31 -0500298 } else {
299 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400300 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
301 "0117 Xmit ELS response x%x to remote "
302 "NPORT x%x I/O tag: x%x, size: x%x\n",
303 elscmd, ndlp->nlp_DID, elsiocb->iotag,
304 cmdSize);
dea31012005-04-17 16:05:31 -0500305 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500306 return elsiocb;
dea31012005-04-17 16:05:31 -0500307
James Smartfa4066b2008-01-11 01:53:27 -0500308els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500309 if (expectRsp)
310 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500311 kfree(pbuflist);
312
313els_iocb_free_prsp_exit:
314 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
315 kfree(prsp);
316
317els_iocb_free_pcmb_exit:
318 kfree(pcmd);
319 lpfc_sli_release_iocbq(phba, elsiocb);
320 return NULL;
321}
dea31012005-04-17 16:05:31 -0500322
James Smarte59058c2008-08-24 21:49:00 -0400323/**
James Smart3621a712009-04-06 18:47:14 -0400324 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400325 * @vport: pointer to a host virtual N_Port data structure.
326 *
327 * This routine issues a fabric registration login for a @vport. An
328 * active ndlp node with Fabric_DID must already exist for this @vport.
329 * The routine invokes two mailbox commands to carry out fabric registration
330 * login through the HBA firmware: the first mailbox command requests the
331 * HBA to perform link configuration for the @vport; and the second mailbox
332 * command requests the HBA to perform the actual fabric registration login
333 * with the @vport.
334 *
335 * Return code
336 * 0 - successfully issued fabric registration login for @vport
337 * -ENXIO -- failed to issue fabric registration login for @vport
338 **/
James Smart3772a992009-05-22 14:50:54 -0400339int
James Smart92d7f7b2007-06-17 19:56:38 -0500340lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
341{
342 struct lpfc_hba *phba = vport->phba;
343 LPFC_MBOXQ_t *mbox;
344 struct lpfc_dmabuf *mp;
345 struct lpfc_nodelist *ndlp;
346 struct serv_parm *sp;
347 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400348 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500349
350 sp = &phba->fc_fabparam;
351 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500352 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400353 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500354 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400355 }
James Smart92d7f7b2007-06-17 19:56:38 -0500356
357 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400358 if (!mbox) {
359 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500360 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400361 }
James Smart92d7f7b2007-06-17 19:56:38 -0500362
363 vport->port_state = LPFC_FABRIC_CFG_LINK;
364 lpfc_config_link(phba, mbox);
365 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
366 mbox->vport = vport;
367
James Smart0b727fe2007-10-27 13:37:25 -0400368 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400369 if (rc == MBX_NOT_FINISHED) {
370 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500371 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400372 }
James Smart92d7f7b2007-06-17 19:56:38 -0500373
374 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400375 if (!mbox) {
376 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500377 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400378 }
James Smart40426292010-12-15 17:58:10 -0500379 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
380 ndlp->nlp_rpi);
James Smart98c9ea52007-10-27 13:37:33 -0400381 if (rc) {
382 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500383 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400384 }
James Smart92d7f7b2007-06-17 19:56:38 -0500385
386 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
387 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500388 /* increment the reference count on ndlp to hold reference
389 * for the callback routine.
390 */
James Smart92d7f7b2007-06-17 19:56:38 -0500391 mbox->context2 = lpfc_nlp_get(ndlp);
392
James Smart0b727fe2007-10-27 13:37:25 -0400393 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400394 if (rc == MBX_NOT_FINISHED) {
395 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500396 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400397 }
James Smart92d7f7b2007-06-17 19:56:38 -0500398
399 return 0;
400
401fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500402 /* decrement the reference count on ndlp just incremented
403 * for the failed mbox command.
404 */
James Smart92d7f7b2007-06-17 19:56:38 -0500405 lpfc_nlp_put(ndlp);
406 mp = (struct lpfc_dmabuf *) mbox->context1;
407 lpfc_mbuf_free(phba, mp->virt, mp->phys);
408 kfree(mp);
409fail_free_mbox:
410 mempool_free(mbox, phba->mbox_mem_pool);
411
412fail:
413 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400414 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400415 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500416 return -ENXIO;
417}
418
James Smarte59058c2008-08-24 21:49:00 -0400419/**
James Smart6fb120a2009-05-22 14:52:59 -0400420 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
421 * @vport: pointer to a host virtual N_Port data structure.
422 *
423 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
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 Smart9589b0622011-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 Smartdbb6b3a2010-06-08 18:31:37 -0400928 (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
James Smart9589b0622011-04-16 11:03:17 -0400929 !((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
930 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500931 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400932 "2611 FLOGI failed on FCF (x%x), "
933 "status:x%x/x%x, tmo:x%x, perform "
934 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -0400935 phba->fcf.current_rec.fcf_indx,
936 irsp->ulpStatus, irsp->un.ulpWord[4],
937 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -0400938 lpfc_sli4_set_fcf_flogi_fail(phba,
939 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500940 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -0400941 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
942 if (rc)
943 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500944 }
945
James Smart38b92ef2010-08-04 16:11:39 -0400946 /* FLOGI failure */
947 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
948 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
949 irsp->ulpStatus, irsp->un.ulpWord[4],
950 irsp->ulpTimeout);
951
dea31012005-04-17 16:05:31 -0500952 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500953 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500954 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500955
James Smart76a95d72010-11-20 23:11:48 -0500956 /* FLOGI failure */
957 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
958 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
959 irsp->ulpStatus, irsp->un.ulpWord[4],
960 irsp->ulpTimeout);
961
dea31012005-04-17 16:05:31 -0500962 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500963 spin_lock_irq(shost->host_lock);
964 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
965 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500966
James Smart329f9bc2007-04-25 09:53:01 -0400967 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500968 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
969 * alpa map would take too long otherwise.
970 */
James Smart1b511972011-12-13 13:23:09 -0500971 if (phba->alpa_map[0] == 0)
James Smart3de2a652007-08-02 11:09:59 -0400972 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -0500973 if ((phba->sli_rev == LPFC_SLI_REV4) &&
974 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
975 (vport->fc_prevDID != vport->fc_myDID))) {
976 if (vport->fc_flag & FC_VFI_REGISTERED)
977 lpfc_sli4_unreg_all_rpis(vport);
978 lpfc_issue_reg_vfi(vport);
979 lpfc_nlp_put(ndlp);
980 goto out;
dea31012005-04-17 16:05:31 -0500981 }
dea31012005-04-17 16:05:31 -0500982 goto flogifail;
983 }
James Smart695a8142010-01-26 23:08:03 -0500984 spin_lock_irq(shost->host_lock);
985 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400986 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500987 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500988
989 /*
990 * The FLogI succeeded. Sync the data for the CPU before
991 * accessing it.
992 */
993 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
994
995 sp = prsp->virt + sizeof(uint32_t);
996
997 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400998 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200999 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -04001000 "Data: x%x x%x x%x x%x\n",
1001 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1002 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -05001003
James Smart2e0fef82007-06-17 19:56:36 -05001004 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -05001005 /*
1006 * If Common Service Parameters indicate Nport
1007 * we are point to point, if Fport we are Fabric.
1008 */
1009 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -05001010 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -05001011 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001012 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -04001013 else {
1014 lpfc_printf_vlog(vport, KERN_ERR,
1015 LOG_FIP | LOG_ELS,
1016 "2831 FLOGI response with cleared Fabric "
1017 "bit fcf_index 0x%x "
1018 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1019 "Fabric Name "
1020 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1021 phba->fcf.current_rec.fcf_indx,
1022 phba->fcf.current_rec.switch_name[0],
1023 phba->fcf.current_rec.switch_name[1],
1024 phba->fcf.current_rec.switch_name[2],
1025 phba->fcf.current_rec.switch_name[3],
1026 phba->fcf.current_rec.switch_name[4],
1027 phba->fcf.current_rec.switch_name[5],
1028 phba->fcf.current_rec.switch_name[6],
1029 phba->fcf.current_rec.switch_name[7],
1030 phba->fcf.current_rec.fabric_name[0],
1031 phba->fcf.current_rec.fabric_name[1],
1032 phba->fcf.current_rec.fabric_name[2],
1033 phba->fcf.current_rec.fabric_name[3],
1034 phba->fcf.current_rec.fabric_name[4],
1035 phba->fcf.current_rec.fabric_name[5],
1036 phba->fcf.current_rec.fabric_name[6],
1037 phba->fcf.current_rec.fabric_name[7]);
1038 lpfc_nlp_put(ndlp);
1039 spin_lock_irq(&phba->hbalock);
1040 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001041 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -04001042 spin_unlock_irq(&phba->hbalock);
1043 goto out;
1044 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001045 if (!rc) {
1046 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -04001047 if (phba->hba_flag & HBA_FIP_SUPPORT)
1048 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1049 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001050 "2769 FLOGI to FCF (x%x) "
1051 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -04001052 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001053 spin_lock_irq(&phba->hbalock);
1054 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001055 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -05001056 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001057 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001058 }
dea31012005-04-17 16:05:31 -05001059 }
1060
1061flogifail:
James Smart329f9bc2007-04-25 09:53:01 -04001062 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001063
James Smart858c9f62007-06-17 19:56:39 -05001064 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001065 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001066 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001067
1068 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001069 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001070 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1071 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
1072 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
1073 (phba->link_state != LPFC_CLEAR_LA)) {
1074 /* If FLOGI failed enable link interrupt. */
1075 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001076 }
dea31012005-04-17 16:05:31 -05001077out:
1078 lpfc_els_free_iocb(phba, cmdiocb);
1079}
1080
James Smarte59058c2008-08-24 21:49:00 -04001081/**
James Smart3621a712009-04-06 18:47:14 -04001082 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001083 * @vport: pointer to a host virtual N_Port data structure.
1084 * @ndlp: pointer to a node-list data structure.
1085 * @retry: number of retries to the command IOCB.
1086 *
1087 * This routine issues a Fabric Login (FLOGI) Request ELS command
1088 * for a @vport. The initiator service parameters are put into the payload
1089 * of the FLOGI Request IOCB and the top-level callback function pointer
1090 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1091 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1092 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1093 *
1094 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1095 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1096 * will be stored into the context1 field of the IOCB for the completion
1097 * callback function to the FLOGI ELS command.
1098 *
1099 * Return code
1100 * 0 - successfully issued flogi iocb for @vport
1101 * 1 - failed to issue flogi iocb for @vport
1102 **/
dea31012005-04-17 16:05:31 -05001103static int
James Smart2e0fef82007-06-17 19:56:36 -05001104lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001105 uint8_t retry)
1106{
James Smart2e0fef82007-06-17 19:56:36 -05001107 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001108 struct serv_parm *sp;
1109 IOCB_t *icmd;
1110 struct lpfc_iocbq *elsiocb;
1111 struct lpfc_sli_ring *pring;
1112 uint8_t *pcmd;
1113 uint16_t cmdsize;
1114 uint32_t tmo;
1115 int rc;
1116
1117 pring = &phba->sli.ring[LPFC_ELS_RING];
1118
James Smart92d7f7b2007-06-17 19:56:38 -05001119 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001120 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1121 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001122
James Smart488d1462006-03-07 15:02:37 -05001123 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001124 return 1;
dea31012005-04-17 16:05:31 -05001125
1126 icmd = &elsiocb->iocb;
1127 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1128
1129 /* For FLOGI request, remainder of payload is service parameters */
1130 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001131 pcmd += sizeof(uint32_t);
1132 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001133 sp = (struct serv_parm *) pcmd;
1134
1135 /* Setup CSPs accordingly for Fabric */
1136 sp->cmn.e_d_tov = 0;
1137 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001138 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001139 sp->cls1.classValid = 0;
1140 sp->cls2.seqDelivery = 1;
1141 sp->cls3.seqDelivery = 1;
1142 if (sp->cmn.fcphLow < FC_PH3)
1143 sp->cmn.fcphLow = FC_PH3;
1144 if (sp->cmn.fcphHigh < FC_PH3)
1145 sp->cmn.fcphHigh = FC_PH3;
1146
James Smartc31098c2011-04-16 11:03:33 -04001147 if (phba->sli_rev == LPFC_SLI_REV4) {
1148 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1149 LPFC_SLI_INTF_IF_TYPE_0) {
1150 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1151 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1152 /* FLOGI needs to be 3 for WQE FCFI */
1153 /* Set the fcfi to the fcfi we registered with */
1154 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1155 }
James Smart5248a742011-07-22 18:37:06 -04001156 } else {
1157 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1158 sp->cmn.request_multiple_Nport = 1;
1159 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1160 icmd->ulpCt_h = 1;
1161 icmd->ulpCt_l = 0;
1162 } else
1163 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001164 }
1165
James Smart76a95d72010-11-20 23:11:48 -05001166 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001167 icmd->un.elsreq64.myID = 0;
1168 icmd->un.elsreq64.fl = 1;
1169 }
1170
dea31012005-04-17 16:05:31 -05001171 tmo = phba->fc_ratov;
1172 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001173 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001174 phba->fc_ratov = tmo;
1175
1176 phba->fc_stat.elsXmitFLOGI++;
1177 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001178
1179 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1180 "Issue FLOGI: opt:x%x",
1181 phba->sli3_options, 0, 0);
1182
James Smart92d7f7b2007-06-17 19:56:38 -05001183 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001184 if (rc == IOCB_ERROR) {
1185 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001186 return 1;
dea31012005-04-17 16:05:31 -05001187 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001188 return 0;
dea31012005-04-17 16:05:31 -05001189}
1190
James Smarte59058c2008-08-24 21:49:00 -04001191/**
James Smart3621a712009-04-06 18:47:14 -04001192 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001193 * @phba: pointer to lpfc hba data structure.
1194 *
1195 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1196 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1197 * list and issues an abort IOCB commond on each outstanding IOCB that
1198 * contains a active Fabric_DID ndlp. Note that this function is to issue
1199 * the abort IOCB command on all the outstanding IOCBs, thus when this
1200 * function returns, it does not guarantee all the IOCBs are actually aborted.
1201 *
1202 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001203 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001204 **/
dea31012005-04-17 16:05:31 -05001205int
James Smart2e0fef82007-06-17 19:56:36 -05001206lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001207{
1208 struct lpfc_sli_ring *pring;
1209 struct lpfc_iocbq *iocb, *next_iocb;
1210 struct lpfc_nodelist *ndlp;
1211 IOCB_t *icmd;
1212
1213 /* Abort outstanding I/O on NPort <nlp_DID> */
1214 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001215 "0201 Abort outstanding I/O on NPort x%x\n",
1216 Fabric_DID);
dea31012005-04-17 16:05:31 -05001217
1218 pring = &phba->sli.ring[LPFC_ELS_RING];
1219
1220 /*
1221 * Check the txcmplq for an iocb that matches the nport the driver is
1222 * searching for.
1223 */
James Smart2e0fef82007-06-17 19:56:36 -05001224 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001225 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1226 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001227 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001228 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001229 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1230 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001231 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001232 }
1233 }
James Smart2e0fef82007-06-17 19:56:36 -05001234 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001235
1236 return 0;
1237}
1238
James Smarte59058c2008-08-24 21:49:00 -04001239/**
James Smart3621a712009-04-06 18:47:14 -04001240 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001241 * @vport: pointer to a host virtual N_Port data structure.
1242 *
1243 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1244 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1245 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1246 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1247 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1248 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1249 * @vport.
1250 *
1251 * Return code
1252 * 0 - failed to issue initial flogi for @vport
1253 * 1 - successfully issued initial flogi for @vport
1254 **/
dea31012005-04-17 16:05:31 -05001255int
James Smart2e0fef82007-06-17 19:56:36 -05001256lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001257{
James Smart2e0fef82007-06-17 19:56:36 -05001258 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001259 struct lpfc_nodelist *ndlp;
1260
James Smart98c9ea52007-10-27 13:37:33 -04001261 vport->port_state = LPFC_FLOGI;
1262 lpfc_set_disctmo(vport);
1263
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001264 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001265 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001266 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001267 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001268 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1269 if (!ndlp)
1270 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001271 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001272 /* Set the node type */
1273 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001274 /* Put ndlp onto node list */
1275 lpfc_enqueue_node(vport, ndlp);
1276 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1277 /* re-setup ndlp without removing from node list */
1278 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1279 if (!ndlp)
1280 return 0;
dea31012005-04-17 16:05:31 -05001281 }
James Smart87af33f2007-10-27 13:37:43 -04001282
James Smart5ac6b302010-10-22 11:05:36 -04001283 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001284 /* This decrement of reference count to node shall kick off
1285 * the release of the node.
1286 */
James Smart329f9bc2007-04-25 09:53:01 -04001287 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001288 return 0;
1289 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001290 return 1;
dea31012005-04-17 16:05:31 -05001291}
1292
James Smarte59058c2008-08-24 21:49:00 -04001293/**
James Smart3621a712009-04-06 18:47:14 -04001294 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001295 * @vport: pointer to a host virtual N_Port data structure.
1296 *
1297 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1298 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1299 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1300 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1301 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1302 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1303 * @vport.
1304 *
1305 * Return code
1306 * 0 - failed to issue initial fdisc for @vport
1307 * 1 - successfully issued initial fdisc for @vport
1308 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001309int
1310lpfc_initial_fdisc(struct lpfc_vport *vport)
1311{
1312 struct lpfc_hba *phba = vport->phba;
1313 struct lpfc_nodelist *ndlp;
1314
1315 /* First look for the Fabric ndlp */
1316 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1317 if (!ndlp) {
1318 /* Cannot find existing Fabric ndlp, so allocate a new one */
1319 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1320 if (!ndlp)
1321 return 0;
1322 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001323 /* Put ndlp onto node list */
1324 lpfc_enqueue_node(vport, ndlp);
1325 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1326 /* re-setup ndlp without removing from node list */
1327 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1328 if (!ndlp)
1329 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001330 }
James Smarte47c9092008-02-08 18:49:26 -05001331
James Smart92d7f7b2007-06-17 19:56:38 -05001332 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001333 /* decrement node reference count to trigger the release of
1334 * the node.
1335 */
James Smart92d7f7b2007-06-17 19:56:38 -05001336 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001337 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001338 }
1339 return 1;
1340}
James Smart87af33f2007-10-27 13:37:43 -04001341
James Smarte59058c2008-08-24 21:49:00 -04001342/**
James Smart3621a712009-04-06 18:47:14 -04001343 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001344 * @vport: pointer to a host virtual N_Port data structure.
1345 *
1346 * This routine checks whether there are more remaining Port Logins
1347 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1348 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1349 * to issue ELS PLOGIs up to the configured discover threads with the
1350 * @vport (@vport->cfg_discovery_threads). The function also decrement
1351 * the @vport's num_disc_node by 1 if it is not already 0.
1352 **/
James Smart87af33f2007-10-27 13:37:43 -04001353void
James Smart2e0fef82007-06-17 19:56:36 -05001354lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001355{
1356 int sentplogi;
1357
James Smart2e0fef82007-06-17 19:56:36 -05001358 if (vport->num_disc_nodes)
1359 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001360
1361 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001362 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1363 "0232 Continue discovery with %d PLOGIs to go "
1364 "Data: x%x x%x x%x\n",
1365 vport->num_disc_nodes, vport->fc_plogi_cnt,
1366 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001367 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001368 if (vport->fc_flag & FC_NLP_MORE)
1369 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1370 sentplogi = lpfc_els_disc_plogi(vport);
1371
dea31012005-04-17 16:05:31 -05001372 return;
1373}
1374
James Smarte59058c2008-08-24 21:49:00 -04001375/**
James Smart3621a712009-04-06 18:47:14 -04001376 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001377 * @phba: pointer to lpfc hba data structure.
1378 * @prsp: pointer to response IOCB payload.
1379 * @ndlp: pointer to a node-list data structure.
1380 *
1381 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1382 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1383 * The following cases are considered N_Port confirmed:
1384 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1385 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1386 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1387 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1388 * 1) if there is a node on vport list other than the @ndlp with the same
1389 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1390 * on that node to release the RPI associated with the node; 2) if there is
1391 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1392 * into, a new node shall be allocated (or activated). In either case, the
1393 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1394 * be released and the new_ndlp shall be put on to the vport node list and
1395 * its pointer returned as the confirmed node.
1396 *
1397 * Note that before the @ndlp got "released", the keepDID from not-matching
1398 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1399 * of the @ndlp. This is because the release of @ndlp is actually to put it
1400 * into an inactive state on the vport node list and the vport node list
1401 * management algorithm does not allow two node with a same DID.
1402 *
1403 * Return code
1404 * pointer to the PLOGI N_Port @ndlp
1405 **/
James Smart488d1462006-03-07 15:02:37 -05001406static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001407lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001408 struct lpfc_nodelist *ndlp)
1409{
James Smart2e0fef82007-06-17 19:56:36 -05001410 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001411 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001412 struct lpfc_rport_data *rdata;
1413 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001414 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001415 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001416 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001417 int put_node;
1418 int put_rport;
James Smart19ca7602010-11-20 23:11:55 -05001419 struct lpfc_node_rrqs rrq;
James Smart488d1462006-03-07 15:02:37 -05001420
James Smart2fb9bd82006-12-02 13:33:57 -05001421 /* Fabric nodes can have the same WWPN so we don't bother searching
1422 * by WWPN. Just return the ndlp that was given to us.
1423 */
1424 if (ndlp->nlp_type & NLP_FABRIC)
1425 return ndlp;
1426
James Smart92d7f7b2007-06-17 19:56:38 -05001427 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001428 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001429
James Smart685f0bf2007-04-25 09:53:08 -04001430 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001431 * we have for that ndlp. If not, we have some work to do.
1432 */
James Smart2e0fef82007-06-17 19:56:36 -05001433 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001434
James Smarte47c9092008-02-08 18:49:26 -05001435 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001436 return ndlp;
James Smart19ca7602010-11-20 23:11:55 -05001437 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
James Smart488d1462006-03-07 15:02:37 -05001438
1439 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001440 rc = memcmp(&ndlp->nlp_portname, name,
1441 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001442 if (!rc)
1443 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001444 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1445 if (!new_ndlp)
1446 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001447 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001448 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001449 rc = memcmp(&ndlp->nlp_portname, name,
1450 sizeof(struct lpfc_name));
1451 if (!rc)
1452 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001453 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1454 NLP_STE_UNUSED_NODE);
1455 if (!new_ndlp)
1456 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001457 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001458 if (phba->sli_rev == LPFC_SLI_REV4)
1459 memcpy(&rrq.xri_bitmap,
1460 &new_ndlp->active_rrqs.xri_bitmap,
1461 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1462 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001463 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001464 if (phba->sli_rev == LPFC_SLI_REV4)
1465 memcpy(&rrq.xri_bitmap,
1466 &new_ndlp->active_rrqs.xri_bitmap,
1467 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1468 }
James Smart488d1462006-03-07 15:02:37 -05001469
James Smart2e0fef82007-06-17 19:56:36 -05001470 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001471 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001472 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001473 if (phba->sli_rev == LPFC_SLI_REV4)
1474 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1475 &ndlp->active_rrqs.xri_bitmap,
1476 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart0ff10d42008-01-11 01:52:36 -05001477
1478 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1479 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1480 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1481
James Smarte47c9092008-02-08 18:49:26 -05001482 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001483 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001484
James Smart2e0fef82007-06-17 19:56:36 -05001485 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001486 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1487 /* The new_ndlp is replacing ndlp totally, so we need
1488 * to put ndlp on UNUSED list and try to free it.
1489 */
James Smart0ff10d42008-01-11 01:52:36 -05001490
1491 /* Fix up the rport accordingly */
1492 rport = ndlp->rport;
1493 if (rport) {
1494 rdata = rport->dd_data;
1495 if (rdata->pnode == ndlp) {
1496 lpfc_nlp_put(ndlp);
1497 ndlp->rport = NULL;
1498 rdata->pnode = lpfc_nlp_get(new_ndlp);
1499 new_ndlp->rport = rport;
1500 }
1501 new_ndlp->nlp_type = ndlp->nlp_type;
1502 }
James Smart58da1ff2008-04-07 10:15:56 -04001503 /* We shall actually free the ndlp with both nlp_DID and
1504 * nlp_portname fields equals 0 to avoid any ndlp on the
1505 * nodelist never to be used.
1506 */
1507 if (ndlp->nlp_DID == 0) {
1508 spin_lock_irq(&phba->ndlp_lock);
1509 NLP_SET_FREE_REQ(ndlp);
1510 spin_unlock_irq(&phba->ndlp_lock);
1511 }
James Smart0ff10d42008-01-11 01:52:36 -05001512
James Smart58da1ff2008-04-07 10:15:56 -04001513 /* Two ndlps cannot have the same did on the nodelist */
1514 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001515 if (phba->sli_rev == LPFC_SLI_REV4)
1516 memcpy(&ndlp->active_rrqs.xri_bitmap,
1517 &rrq.xri_bitmap,
1518 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001519 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001520 }
James Smart92795652006-07-06 15:50:02 -04001521 else {
James Smart2e0fef82007-06-17 19:56:36 -05001522 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001523 /* Two ndlps cannot have the same did */
1524 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001525 if (phba->sli_rev == LPFC_SLI_REV4)
1526 memcpy(&ndlp->active_rrqs.xri_bitmap,
1527 &rrq.xri_bitmap,
1528 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart38b92ef2010-08-04 16:11:39 -04001529 /* Since we are swapping the ndlp passed in with the new one
1530 * and the did has already been swapped, copy over the
1531 * state and names.
1532 */
1533 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1534 sizeof(struct lpfc_name));
1535 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1536 sizeof(struct lpfc_name));
1537 new_ndlp->nlp_state = ndlp->nlp_state;
James Smarteff4a012012-01-18 16:25:25 -05001538 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart38b92ef2010-08-04 16:11:39 -04001539 /* Fix up the rport accordingly */
1540 rport = ndlp->rport;
1541 if (rport) {
1542 rdata = rport->dd_data;
1543 put_node = rdata->pnode != NULL;
1544 put_rport = ndlp->rport != NULL;
1545 rdata->pnode = NULL;
1546 ndlp->rport = NULL;
1547 if (put_node)
1548 lpfc_nlp_put(ndlp);
1549 if (put_rport)
1550 put_device(&rport->dev);
1551 }
James Smart92795652006-07-06 15:50:02 -04001552 }
James Smart488d1462006-03-07 15:02:37 -05001553 return new_ndlp;
1554}
1555
James Smarte59058c2008-08-24 21:49:00 -04001556/**
James Smart3621a712009-04-06 18:47:14 -04001557 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001558 * @vport: pointer to a host virtual N_Port data structure.
1559 *
1560 * This routine checks whether more Registration State Change
1561 * Notifications (RSCNs) came in while the discovery state machine was in
1562 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1563 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1564 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1565 * handling the RSCNs.
1566 **/
James Smart87af33f2007-10-27 13:37:43 -04001567void
1568lpfc_end_rscn(struct lpfc_vport *vport)
1569{
1570 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1571
1572 if (vport->fc_flag & FC_RSCN_MODE) {
1573 /*
1574 * Check to see if more RSCNs came in while we were
1575 * processing this one.
1576 */
1577 if (vport->fc_rscn_id_cnt ||
1578 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1579 lpfc_els_handle_rscn(vport);
1580 else {
1581 spin_lock_irq(shost->host_lock);
1582 vport->fc_flag &= ~FC_RSCN_MODE;
1583 spin_unlock_irq(shost->host_lock);
1584 }
1585 }
1586}
1587
James Smarte59058c2008-08-24 21:49:00 -04001588/**
James Smart19ca7602010-11-20 23:11:55 -05001589 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1590 * @phba: pointer to lpfc hba data structure.
1591 * @cmdiocb: pointer to lpfc command iocb data structure.
1592 * @rspiocb: pointer to lpfc response iocb data structure.
1593 *
1594 * This routine will call the clear rrq function to free the rrq and
1595 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1596 * exist then the clear_rrq is still called because the rrq needs to
1597 * be freed.
1598 **/
1599
1600static void
1601lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1602 struct lpfc_iocbq *rspiocb)
1603{
1604 struct lpfc_vport *vport = cmdiocb->vport;
1605 IOCB_t *irsp;
1606 struct lpfc_nodelist *ndlp;
1607 struct lpfc_node_rrq *rrq;
1608
1609 /* we pass cmdiocb to state machine which needs rspiocb as well */
1610 rrq = cmdiocb->context_un.rrq;
1611 cmdiocb->context_un.rsp_iocb = rspiocb;
1612
1613 irsp = &rspiocb->iocb;
1614 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1615 "RRQ cmpl: status:x%x/x%x did:x%x",
1616 irsp->ulpStatus, irsp->un.ulpWord[4],
1617 irsp->un.elsreq64.remoteID);
1618
1619 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1620 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1621 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1622 "2882 RRQ completes to NPort x%x "
1623 "with no ndlp. Data: x%x x%x x%x\n",
1624 irsp->un.elsreq64.remoteID,
1625 irsp->ulpStatus, irsp->un.ulpWord[4],
1626 irsp->ulpIoTag);
1627 goto out;
1628 }
1629
1630 /* rrq completes to NPort <nlp_DID> */
1631 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1632 "2880 RRQ completes to NPort x%x "
1633 "Data: x%x x%x x%x x%x x%x\n",
1634 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1635 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1636
1637 if (irsp->ulpStatus) {
1638 /* Check for retry */
1639 /* RRQ failed Don't print the vport to vport rjts */
1640 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1641 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1642 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1643 (phba)->pport->cfg_log_verbose & LOG_ELS)
1644 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1645 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1646 ndlp->nlp_DID, irsp->ulpStatus,
1647 irsp->un.ulpWord[4]);
1648 }
1649out:
1650 if (rrq)
1651 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1652 lpfc_els_free_iocb(phba, cmdiocb);
1653 return;
1654}
1655/**
James Smart3621a712009-04-06 18:47:14 -04001656 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001657 * @phba: pointer to lpfc hba data structure.
1658 * @cmdiocb: pointer to lpfc command iocb data structure.
1659 * @rspiocb: pointer to lpfc response iocb data structure.
1660 *
1661 * This routine is the completion callback function for issuing the Port
1662 * Login (PLOGI) command. For PLOGI completion, there must be an active
1663 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001664 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001665 * ignored and command IOCB released. The PLOGI response IOCB status is
1666 * checked for error conditons. If there is error status reported, PLOGI
1667 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1668 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1669 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1670 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1671 * there are additional N_Port nodes with the vport that need to perform
1672 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1673 * PLOGIs.
1674 **/
dea31012005-04-17 16:05:31 -05001675static void
James Smart2e0fef82007-06-17 19:56:36 -05001676lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1677 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001678{
James Smart2e0fef82007-06-17 19:56:36 -05001679 struct lpfc_vport *vport = cmdiocb->vport;
1680 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001681 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001682 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001683 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001684 int disc, rc, did, type;
1685
dea31012005-04-17 16:05:31 -05001686 /* we pass cmdiocb to state machine which needs rspiocb as well */
1687 cmdiocb->context_un.rsp_iocb = rspiocb;
1688
1689 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001690 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1691 "PLOGI cmpl: status:x%x/x%x did:x%x",
1692 irsp->ulpStatus, irsp->un.ulpWord[4],
1693 irsp->un.elsreq64.remoteID);
1694
James Smart2e0fef82007-06-17 19:56:36 -05001695 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001696 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001697 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1698 "0136 PLOGI completes to NPort x%x "
1699 "with no ndlp. Data: x%x x%x x%x\n",
1700 irsp->un.elsreq64.remoteID,
1701 irsp->ulpStatus, irsp->un.ulpWord[4],
1702 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001703 goto out;
James Smarted957682007-06-17 19:56:37 -05001704 }
dea31012005-04-17 16:05:31 -05001705
1706 /* Since ndlp can be freed in the disc state machine, note if this node
1707 * is being used during discovery.
1708 */
James Smart2e0fef82007-06-17 19:56:36 -05001709 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001710 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001711 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001712 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001713 rc = 0;
1714
1715 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001716 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1717 "0102 PLOGI completes to NPort x%x "
1718 "Data: x%x x%x x%x x%x x%x\n",
1719 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1720 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001721 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001722 if (lpfc_els_chk_latt(vport)) {
1723 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001724 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001725 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001726 goto out;
1727 }
1728
1729 /* ndlp could be freed in DSM, save these values now */
1730 type = ndlp->nlp_type;
1731 did = ndlp->nlp_DID;
1732
1733 if (irsp->ulpStatus) {
1734 /* Check for retry */
1735 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1736 /* ELS command is being retried */
1737 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001738 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001739 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001740 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001741 }
1742 goto out;
1743 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001744 /* PLOGI failed Don't print the vport to vport rjts */
1745 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1746 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1747 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1748 (phba)->pport->cfg_log_verbose & LOG_ELS)
1749 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001750 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1751 ndlp->nlp_DID, irsp->ulpStatus,
1752 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001753 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001754 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001755 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001756 else
James Smart2e0fef82007-06-17 19:56:36 -05001757 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001758 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001759 } else {
1760 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001761 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001762 cmdiocb->context2)->list.next,
1763 struct lpfc_dmabuf, list);
1764 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001765 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001766 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001767 }
1768
James Smart2e0fef82007-06-17 19:56:36 -05001769 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001770 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001771 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001772
James Smart2e0fef82007-06-17 19:56:36 -05001773 if (vport->num_disc_nodes == 0) {
1774 spin_lock_irq(shost->host_lock);
1775 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1776 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001777
James Smart2e0fef82007-06-17 19:56:36 -05001778 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001779 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001780 }
1781 }
1782
1783out:
1784 lpfc_els_free_iocb(phba, cmdiocb);
1785 return;
1786}
1787
James Smarte59058c2008-08-24 21:49:00 -04001788/**
James Smart3621a712009-04-06 18:47:14 -04001789 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001790 * @vport: pointer to a host virtual N_Port data structure.
1791 * @did: destination port identifier.
1792 * @retry: number of retries to the command IOCB.
1793 *
1794 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1795 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1796 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1797 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1798 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1799 *
1800 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1801 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1802 * will be stored into the context1 field of the IOCB for the completion
1803 * callback function to the PLOGI ELS command.
1804 *
1805 * Return code
1806 * 0 - Successfully issued a plogi for @vport
1807 * 1 - failed to issue a plogi for @vport
1808 **/
dea31012005-04-17 16:05:31 -05001809int
James Smart2e0fef82007-06-17 19:56:36 -05001810lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001811{
James Smart2e0fef82007-06-17 19:56:36 -05001812 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001813 struct serv_parm *sp;
1814 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001815 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001816 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001817 struct lpfc_sli *psli;
1818 uint8_t *pcmd;
1819 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001820 int ret;
dea31012005-04-17 16:05:31 -05001821
1822 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001823
James Smart98c9ea52007-10-27 13:37:33 -04001824 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001825 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1826 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001827
James Smarte47c9092008-02-08 18:49:26 -05001828 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001829 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001830 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001831 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001832 if (!elsiocb)
1833 return 1;
dea31012005-04-17 16:05:31 -05001834
1835 icmd = &elsiocb->iocb;
1836 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1837
1838 /* For PLOGI request, remainder of payload is service parameters */
1839 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001840 pcmd += sizeof(uint32_t);
1841 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001842 sp = (struct serv_parm *) pcmd;
1843
James Smart5ac6b302010-10-22 11:05:36 -04001844 /*
1845 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1846 * to device on remote loops work.
1847 */
1848 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1849 sp->cmn.altBbCredit = 1;
1850
dea31012005-04-17 16:05:31 -05001851 if (sp->cmn.fcphLow < FC_PH_4_3)
1852 sp->cmn.fcphLow = FC_PH_4_3;
1853
1854 if (sp->cmn.fcphHigh < FC_PH3)
1855 sp->cmn.fcphHigh = FC_PH3;
1856
James Smart858c9f62007-06-17 19:56:39 -05001857 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1858 "Issue PLOGI: did:x%x",
1859 did, 0, 0);
1860
dea31012005-04-17 16:05:31 -05001861 phba->fc_stat.elsXmitPLOGI++;
1862 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001863 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001864
1865 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001866 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001867 return 1;
dea31012005-04-17 16:05:31 -05001868 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001869 return 0;
dea31012005-04-17 16:05:31 -05001870}
1871
James Smarte59058c2008-08-24 21:49:00 -04001872/**
James Smart3621a712009-04-06 18:47:14 -04001873 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001874 * @phba: pointer to lpfc hba data structure.
1875 * @cmdiocb: pointer to lpfc command iocb data structure.
1876 * @rspiocb: pointer to lpfc response iocb data structure.
1877 *
1878 * This routine is the completion callback function for a Process Login
1879 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1880 * status. If there is error status reported, PRLI retry shall be attempted
1881 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1882 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1883 * ndlp to mark the PRLI completion.
1884 **/
dea31012005-04-17 16:05:31 -05001885static void
James Smart2e0fef82007-06-17 19:56:36 -05001886lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1887 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001888{
James Smart2e0fef82007-06-17 19:56:36 -05001889 struct lpfc_vport *vport = cmdiocb->vport;
1890 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001891 IOCB_t *irsp;
1892 struct lpfc_sli *psli;
1893 struct lpfc_nodelist *ndlp;
1894
1895 psli = &phba->sli;
1896 /* we pass cmdiocb to state machine which needs rspiocb as well */
1897 cmdiocb->context_un.rsp_iocb = rspiocb;
1898
1899 irsp = &(rspiocb->iocb);
1900 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001901 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001902 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001903 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001904
James Smart858c9f62007-06-17 19:56:39 -05001905 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1906 "PRLI cmpl: status:x%x/x%x did:x%x",
1907 irsp->ulpStatus, irsp->un.ulpWord[4],
1908 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001909 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001910 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1911 "0103 PRLI completes to NPort x%x "
1912 "Data: x%x x%x x%x x%x\n",
1913 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1914 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001915
James Smart2e0fef82007-06-17 19:56:36 -05001916 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001917 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001918 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001919 goto out;
1920
1921 if (irsp->ulpStatus) {
1922 /* Check for retry */
1923 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1924 /* ELS command is being retried */
1925 goto out;
1926 }
1927 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001928 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1929 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1930 ndlp->nlp_DID, irsp->ulpStatus,
1931 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001932 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001933 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001934 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001935 else
James Smart2e0fef82007-06-17 19:56:36 -05001936 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001937 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001938 } else
dea31012005-04-17 16:05:31 -05001939 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001940 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001941 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001942out:
1943 lpfc_els_free_iocb(phba, cmdiocb);
1944 return;
1945}
1946
James Smarte59058c2008-08-24 21:49:00 -04001947/**
James Smart3621a712009-04-06 18:47:14 -04001948 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001949 * @vport: pointer to a host virtual N_Port data structure.
1950 * @ndlp: pointer to a node-list data structure.
1951 * @retry: number of retries to the command IOCB.
1952 *
1953 * This routine issues a Process Login (PRLI) ELS command for the
1954 * @vport. The PRLI service parameters are set up in the payload of the
1955 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1956 * is put to the IOCB completion callback func field before invoking the
1957 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1958 *
1959 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1960 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1961 * will be stored into the context1 field of the IOCB for the completion
1962 * callback function to the PRLI ELS command.
1963 *
1964 * Return code
1965 * 0 - successfully issued prli iocb command for @vport
1966 * 1 - failed to issue prli iocb command for @vport
1967 **/
dea31012005-04-17 16:05:31 -05001968int
James Smart2e0fef82007-06-17 19:56:36 -05001969lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001970 uint8_t retry)
1971{
James Smart2e0fef82007-06-17 19:56:36 -05001972 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1973 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001974 PRLI *npr;
1975 IOCB_t *icmd;
1976 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001977 uint8_t *pcmd;
1978 uint16_t cmdsize;
1979
James Smart92d7f7b2007-06-17 19:56:38 -05001980 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001981 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1982 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001983 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001984 return 1;
dea31012005-04-17 16:05:31 -05001985
1986 icmd = &elsiocb->iocb;
1987 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1988
1989 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001990 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001991 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001992 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001993
1994 /* For PRLI, remainder of payload is PRLI parameter page */
1995 npr = (PRLI *) pcmd;
1996 /*
1997 * If our firmware version is 3.20 or later,
1998 * set the following bits for FC-TAPE support.
1999 */
2000 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2001 npr->ConfmComplAllowed = 1;
2002 npr->Retry = 1;
2003 npr->TaskRetryIdReq = 1;
2004 }
2005 npr->estabImagePair = 1;
2006 npr->readXferRdyDis = 1;
2007
2008 /* For FCP support */
2009 npr->prliType = PRLI_FCP_TYPE;
2010 npr->initiatorFunc = 1;
2011
James Smart858c9f62007-06-17 19:56:39 -05002012 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2013 "Issue PRLI: did:x%x",
2014 ndlp->nlp_DID, 0, 0);
2015
dea31012005-04-17 16:05:31 -05002016 phba->fc_stat.elsXmitPRLI++;
2017 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05002018 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002019 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002020 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002021 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2022 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002023 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002024 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002025 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002026 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002027 return 1;
dea31012005-04-17 16:05:31 -05002028 }
James Smart2e0fef82007-06-17 19:56:36 -05002029 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002030 return 0;
dea31012005-04-17 16:05:31 -05002031}
2032
James Smarte59058c2008-08-24 21:49:00 -04002033/**
James Smart3621a712009-04-06 18:47:14 -04002034 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002035 * @vport: pointer to a host virtual N_Port data structure.
2036 *
2037 * This routine performs Registration State Change Notification (RSCN)
2038 * discovery for a @vport. If the @vport's node port recovery count is not
2039 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2040 * the nodes that need recovery. If none of the PLOGI were needed through
2041 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2042 * invoked to check and handle possible more RSCN came in during the period
2043 * of processing the current ones.
2044 **/
2045static void
2046lpfc_rscn_disc(struct lpfc_vport *vport)
2047{
2048 lpfc_can_disctmo(vport);
2049
2050 /* RSCN discovery */
2051 /* go thru NPR nodes and issue ELS PLOGIs */
2052 if (vport->fc_npr_cnt)
2053 if (lpfc_els_disc_plogi(vport))
2054 return;
2055
2056 lpfc_end_rscn(vport);
2057}
2058
2059/**
James Smart3621a712009-04-06 18:47:14 -04002060 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002061 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2062 *
2063 * This function is called when the final ADISC is completed during discovery.
2064 * This function handles clearing link attention or issuing reg_vpi depending
2065 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2066 * discovery.
2067 * This function is called with no locks held.
2068 **/
2069static void
2070lpfc_adisc_done(struct lpfc_vport *vport)
2071{
2072 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2073 struct lpfc_hba *phba = vport->phba;
2074
2075 /*
2076 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2077 * and continue discovery.
2078 */
2079 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002080 !(vport->fc_flag & FC_RSCN_MODE) &&
2081 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04002082 lpfc_issue_reg_vpi(phba, vport);
2083 return;
2084 }
2085 /*
2086 * For SLI2, we need to set port_state to READY
2087 * and continue discovery.
2088 */
2089 if (vport->port_state < LPFC_VPORT_READY) {
2090 /* If we get here, there is nothing to ADISC */
2091 if (vport->port_type == LPFC_PHYSICAL_PORT)
2092 lpfc_issue_clear_la(phba, vport);
2093 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2094 vport->num_disc_nodes = 0;
2095 /* go thru NPR list, issue ELS PLOGIs */
2096 if (vport->fc_npr_cnt)
2097 lpfc_els_disc_plogi(vport);
2098 if (!vport->num_disc_nodes) {
2099 spin_lock_irq(shost->host_lock);
2100 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2101 spin_unlock_irq(shost->host_lock);
2102 lpfc_can_disctmo(vport);
2103 lpfc_end_rscn(vport);
2104 }
2105 }
2106 vport->port_state = LPFC_VPORT_READY;
2107 } else
2108 lpfc_rscn_disc(vport);
2109}
2110
2111/**
James Smart3621a712009-04-06 18:47:14 -04002112 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002113 * @vport: pointer to a host virtual N_Port data structure.
2114 *
2115 * This routine determines whether there are more ndlps on a @vport
2116 * node list need to have Address Discover (ADISC) issued. If so, it will
2117 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2118 * remaining nodes which need to have ADISC sent.
2119 **/
James Smart0ff10d42008-01-11 01:52:36 -05002120void
James Smart2e0fef82007-06-17 19:56:36 -05002121lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002122{
2123 int sentadisc;
2124
James Smart2e0fef82007-06-17 19:56:36 -05002125 if (vport->num_disc_nodes)
2126 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002127 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002128 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2129 "0210 Continue discovery with %d ADISCs to go "
2130 "Data: x%x x%x x%x\n",
2131 vport->num_disc_nodes, vport->fc_adisc_cnt,
2132 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002133 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002134 if (vport->fc_flag & FC_NLP_MORE) {
2135 lpfc_set_disctmo(vport);
2136 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2137 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002138 }
James Smart90160e02008-08-24 21:49:45 -04002139 if (!vport->num_disc_nodes)
2140 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002141 return;
2142}
2143
James Smarte59058c2008-08-24 21:49:00 -04002144/**
James Smart3621a712009-04-06 18:47:14 -04002145 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002146 * @phba: pointer to lpfc hba data structure.
2147 * @cmdiocb: pointer to lpfc command iocb data structure.
2148 * @rspiocb: pointer to lpfc response iocb data structure.
2149 *
2150 * This routine is the completion function for issuing the Address Discover
2151 * (ADISC) command. It first checks to see whether link went down during
2152 * the discovery process. If so, the node will be marked as node port
2153 * recovery for issuing discover IOCB by the link attention handler and
2154 * exit. Otherwise, the response status is checked. If error was reported
2155 * in the response status, the ADISC command shall be retried by invoking
2156 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2157 * the response status, the state machine is invoked to set transition
2158 * with respect to NLP_EVT_CMPL_ADISC event.
2159 **/
dea31012005-04-17 16:05:31 -05002160static void
James Smart2e0fef82007-06-17 19:56:36 -05002161lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2162 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002163{
James Smart2e0fef82007-06-17 19:56:36 -05002164 struct lpfc_vport *vport = cmdiocb->vport;
2165 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002166 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002167 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002168 int disc;
dea31012005-04-17 16:05:31 -05002169
2170 /* we pass cmdiocb to state machine which needs rspiocb as well */
2171 cmdiocb->context_un.rsp_iocb = rspiocb;
2172
2173 irsp = &(rspiocb->iocb);
2174 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002175
James Smart858c9f62007-06-17 19:56:39 -05002176 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2177 "ADISC cmpl: status:x%x/x%x did:x%x",
2178 irsp->ulpStatus, irsp->un.ulpWord[4],
2179 ndlp->nlp_DID);
2180
dea31012005-04-17 16:05:31 -05002181 /* Since ndlp can be freed in the disc state machine, note if this node
2182 * is being used during discovery.
2183 */
James Smart2e0fef82007-06-17 19:56:36 -05002184 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002185 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002186 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002187 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002188 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002189 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2190 "0104 ADISC completes to NPort x%x "
2191 "Data: x%x x%x x%x x%x x%x\n",
2192 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2193 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002194 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002195 if (lpfc_els_chk_latt(vport)) {
2196 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002197 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002198 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002199 goto out;
2200 }
2201
2202 if (irsp->ulpStatus) {
2203 /* Check for retry */
2204 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2205 /* ELS command is being retried */
2206 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002207 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002208 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002209 spin_unlock_irq(shost->host_lock);
2210 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002211 }
2212 goto out;
2213 }
2214 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002215 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2216 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2217 ndlp->nlp_DID, irsp->ulpStatus,
2218 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002219 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002220 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002221 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002222 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002223 } else
dea31012005-04-17 16:05:31 -05002224 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002225 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002226 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002227
James Smart90160e02008-08-24 21:49:45 -04002228 /* Check to see if there are more ADISCs to be sent */
2229 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002230 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002231out:
2232 lpfc_els_free_iocb(phba, cmdiocb);
2233 return;
2234}
2235
James Smarte59058c2008-08-24 21:49:00 -04002236/**
James Smart3621a712009-04-06 18:47:14 -04002237 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002238 * @vport: pointer to a virtual N_Port data structure.
2239 * @ndlp: pointer to a node-list data structure.
2240 * @retry: number of retries to the command IOCB.
2241 *
2242 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2243 * @vport. It prepares the payload of the ADISC ELS command, updates the
2244 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2245 * to issue the ADISC ELS command.
2246 *
2247 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2248 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2249 * will be stored into the context1 field of the IOCB for the completion
2250 * callback function to the ADISC ELS command.
2251 *
2252 * Return code
2253 * 0 - successfully issued adisc
2254 * 1 - failed to issue adisc
2255 **/
dea31012005-04-17 16:05:31 -05002256int
James Smart2e0fef82007-06-17 19:56:36 -05002257lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002258 uint8_t retry)
2259{
James Smart2e0fef82007-06-17 19:56:36 -05002260 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2261 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002262 ADISC *ap;
2263 IOCB_t *icmd;
2264 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002265 uint8_t *pcmd;
2266 uint16_t cmdsize;
2267
James Smart92d7f7b2007-06-17 19:56:38 -05002268 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002269 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2270 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002271 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002272 return 1;
dea31012005-04-17 16:05:31 -05002273
2274 icmd = &elsiocb->iocb;
2275 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2276
2277 /* For ADISC request, remainder of payload is service parameters */
2278 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002279 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002280
2281 /* Fill in ADISC payload */
2282 ap = (ADISC *) pcmd;
2283 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002284 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2285 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002286 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002287
James Smart858c9f62007-06-17 19:56:39 -05002288 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2289 "Issue ADISC: did:x%x",
2290 ndlp->nlp_DID, 0, 0);
2291
dea31012005-04-17 16:05:31 -05002292 phba->fc_stat.elsXmitADISC++;
2293 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002294 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002295 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002296 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002297 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2298 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002299 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002300 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002301 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002302 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002303 return 1;
dea31012005-04-17 16:05:31 -05002304 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002305 return 0;
dea31012005-04-17 16:05:31 -05002306}
2307
James Smarte59058c2008-08-24 21:49:00 -04002308/**
James Smart3621a712009-04-06 18:47:14 -04002309 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002310 * @phba: pointer to lpfc hba data structure.
2311 * @cmdiocb: pointer to lpfc command iocb data structure.
2312 * @rspiocb: pointer to lpfc response iocb data structure.
2313 *
2314 * This routine is the completion function for issuing the ELS Logout (LOGO)
2315 * command. If no error status was reported from the LOGO response, the
2316 * state machine of the associated ndlp shall be invoked for transition with
2317 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2318 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2319 **/
dea31012005-04-17 16:05:31 -05002320static void
James Smart2e0fef82007-06-17 19:56:36 -05002321lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2322 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002323{
James Smart2e0fef82007-06-17 19:56:36 -05002324 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2325 struct lpfc_vport *vport = ndlp->vport;
2326 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002327 IOCB_t *irsp;
2328 struct lpfc_sli *psli;
James Smart92494142011-02-16 12:39:44 -05002329 struct lpfcMboxq *mbox;
dea31012005-04-17 16:05:31 -05002330
2331 psli = &phba->sli;
2332 /* we pass cmdiocb to state machine which needs rspiocb as well */
2333 cmdiocb->context_un.rsp_iocb = rspiocb;
2334
2335 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002336 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002337 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002338 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002339
James Smart858c9f62007-06-17 19:56:39 -05002340 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2341 "LOGO cmpl: status:x%x/x%x did:x%x",
2342 irsp->ulpStatus, irsp->un.ulpWord[4],
2343 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002344 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002345 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2346 "0105 LOGO completes to NPort x%x "
2347 "Data: x%x x%x x%x x%x\n",
2348 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2349 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002350 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002351 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002352 goto out;
2353
James Smart92d7f7b2007-06-17 19:56:38 -05002354 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2355 /* NLP_EVT_DEVICE_RM should unregister the RPI
2356 * which should abort all outstanding IOs.
2357 */
2358 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2359 NLP_EVT_DEVICE_RM);
2360 goto out;
2361 }
2362
dea31012005-04-17 16:05:31 -05002363 if (irsp->ulpStatus) {
2364 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002365 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002366 /* ELS command is being retried */
2367 goto out;
dea31012005-04-17 16:05:31 -05002368 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002369 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2370 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2371 ndlp->nlp_DID, irsp->ulpStatus,
2372 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002373 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002374 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002375 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002376 else
James Smart2e0fef82007-06-17 19:56:36 -05002377 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002378 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002379 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002380 /* Good status, call state machine.
2381 * This will unregister the rpi if needed.
2382 */
James Smart2e0fef82007-06-17 19:56:36 -05002383 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002384 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002385out:
2386 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002387 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2388 if ((vport->fc_flag & FC_PT2PT) &&
2389 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2390 phba->pport->fc_myDID = 0;
2391 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2392 if (mbox) {
2393 lpfc_config_link(phba, mbox);
2394 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2395 mbox->vport = vport;
2396 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2397 MBX_NOT_FINISHED) {
2398 mempool_free(mbox, phba->mbox_mem_pool);
2399 }
2400 }
2401 }
dea31012005-04-17 16:05:31 -05002402 return;
2403}
2404
James Smarte59058c2008-08-24 21:49:00 -04002405/**
James Smart3621a712009-04-06 18:47:14 -04002406 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002407 * @vport: pointer to a virtual N_Port data structure.
2408 * @ndlp: pointer to a node-list data structure.
2409 * @retry: number of retries to the command IOCB.
2410 *
2411 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2412 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2413 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2414 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2415 *
2416 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2417 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2418 * will be stored into the context1 field of the IOCB for the completion
2419 * callback function to the LOGO ELS command.
2420 *
2421 * Return code
2422 * 0 - successfully issued logo
2423 * 1 - failed to issue logo
2424 **/
dea31012005-04-17 16:05:31 -05002425int
James Smart2e0fef82007-06-17 19:56:36 -05002426lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002427 uint8_t retry)
2428{
James Smart2e0fef82007-06-17 19:56:36 -05002429 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2430 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002431 IOCB_t *icmd;
2432 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002433 uint8_t *pcmd;
2434 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002435 int rc;
dea31012005-04-17 16:05:31 -05002436
James Smart98c9ea52007-10-27 13:37:33 -04002437 spin_lock_irq(shost->host_lock);
2438 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2439 spin_unlock_irq(shost->host_lock);
2440 return 0;
2441 }
2442 spin_unlock_irq(shost->host_lock);
2443
James Smart92d7f7b2007-06-17 19:56:38 -05002444 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002445 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2446 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002447 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002448 return 1;
dea31012005-04-17 16:05:31 -05002449
2450 icmd = &elsiocb->iocb;
2451 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2452 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002453 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002454
2455 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002456 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002457 pcmd += sizeof(uint32_t);
2458 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002459
James Smart858c9f62007-06-17 19:56:39 -05002460 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2461 "Issue LOGO: did:x%x",
2462 ndlp->nlp_DID, 0, 0);
2463
dea31012005-04-17 16:05:31 -05002464 phba->fc_stat.elsXmitLOGO++;
2465 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002466 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002467 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002468 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002469 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002470
2471 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002472 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002473 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002474 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002475 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002476 return 1;
dea31012005-04-17 16:05:31 -05002477 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002478 return 0;
dea31012005-04-17 16:05:31 -05002479}
2480
James Smarte59058c2008-08-24 21:49:00 -04002481/**
James Smart3621a712009-04-06 18:47:14 -04002482 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002483 * @phba: pointer to lpfc hba data structure.
2484 * @cmdiocb: pointer to lpfc command iocb data structure.
2485 * @rspiocb: pointer to lpfc response iocb data structure.
2486 *
2487 * This routine is a generic completion callback function for ELS commands.
2488 * Specifically, it is the callback function which does not need to perform
2489 * any command specific operations. It is currently used by the ELS command
2490 * issuing routines for the ELS State Change Request (SCR),
2491 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2492 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2493 * certain debug loggings, this callback function simply invokes the
2494 * lpfc_els_chk_latt() routine to check whether link went down during the
2495 * discovery process.
2496 **/
dea31012005-04-17 16:05:31 -05002497static void
James Smart2e0fef82007-06-17 19:56:36 -05002498lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2499 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002500{
James Smart2e0fef82007-06-17 19:56:36 -05002501 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002502 IOCB_t *irsp;
2503
2504 irsp = &rspiocb->iocb;
2505
James Smart858c9f62007-06-17 19:56:39 -05002506 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2507 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2508 irsp->ulpStatus, irsp->un.ulpWord[4],
2509 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002510 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002511 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2512 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2513 irsp->ulpIoTag, irsp->ulpStatus,
2514 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002515 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002516 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002517 lpfc_els_free_iocb(phba, cmdiocb);
2518 return;
2519}
2520
James Smarte59058c2008-08-24 21:49:00 -04002521/**
James Smart3621a712009-04-06 18:47:14 -04002522 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002523 * @vport: pointer to a host virtual N_Port data structure.
2524 * @nportid: N_Port identifier to the remote node.
2525 * @retry: number of retries to the command IOCB.
2526 *
2527 * This routine issues a State Change Request (SCR) to a fabric node
2528 * on a @vport. The remote node @nportid is passed into the function. It
2529 * first search the @vport node list to find the matching ndlp. If no such
2530 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2531 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2532 * routine is invoked to send the SCR IOCB.
2533 *
2534 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2535 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2536 * will be stored into the context1 field of the IOCB for the completion
2537 * callback function to the SCR ELS command.
2538 *
2539 * Return code
2540 * 0 - Successfully issued scr command
2541 * 1 - Failed to issue scr command
2542 **/
dea31012005-04-17 16:05:31 -05002543int
James Smart2e0fef82007-06-17 19:56:36 -05002544lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002545{
James Smart2e0fef82007-06-17 19:56:36 -05002546 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002547 IOCB_t *icmd;
2548 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002549 struct lpfc_sli *psli;
2550 uint8_t *pcmd;
2551 uint16_t cmdsize;
2552 struct lpfc_nodelist *ndlp;
2553
2554 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002555 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002556
James Smarte47c9092008-02-08 18:49:26 -05002557 ndlp = lpfc_findnode_did(vport, nportid);
2558 if (!ndlp) {
2559 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2560 if (!ndlp)
2561 return 1;
2562 lpfc_nlp_init(vport, ndlp, nportid);
2563 lpfc_enqueue_node(vport, ndlp);
2564 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2565 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2566 if (!ndlp)
2567 return 1;
2568 }
dea31012005-04-17 16:05:31 -05002569
James Smart2e0fef82007-06-17 19:56:36 -05002570 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2571 ndlp->nlp_DID, ELS_CMD_SCR);
2572
James Smart488d1462006-03-07 15:02:37 -05002573 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002574 /* This will trigger the release of the node just
2575 * allocated
2576 */
James Smart329f9bc2007-04-25 09:53:01 -04002577 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002578 return 1;
dea31012005-04-17 16:05:31 -05002579 }
2580
2581 icmd = &elsiocb->iocb;
2582 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2583
2584 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002585 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002586
2587 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002588 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002589 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2590
James Smart858c9f62007-06-17 19:56:39 -05002591 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2592 "Issue SCR: did:x%x",
2593 ndlp->nlp_DID, 0, 0);
2594
dea31012005-04-17 16:05:31 -05002595 phba->fc_stat.elsXmitSCR++;
2596 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002597 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2598 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002599 /* The additional lpfc_nlp_put will cause the following
2600 * lpfc_els_free_iocb routine to trigger the rlease of
2601 * the node.
2602 */
James Smart329f9bc2007-04-25 09:53:01 -04002603 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002604 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002605 return 1;
dea31012005-04-17 16:05:31 -05002606 }
James Smartfa4066b2008-01-11 01:53:27 -05002607 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2608 * trigger the release of node.
2609 */
James Smart329f9bc2007-04-25 09:53:01 -04002610 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002611 return 0;
dea31012005-04-17 16:05:31 -05002612}
2613
James Smarte59058c2008-08-24 21:49:00 -04002614/**
James Smart3621a712009-04-06 18:47:14 -04002615 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002616 * @vport: pointer to a host virtual N_Port data structure.
2617 * @nportid: N_Port identifier to the remote node.
2618 * @retry: number of retries to the command IOCB.
2619 *
2620 * This routine issues a Fibre Channel Address Resolution Response
2621 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2622 * is passed into the function. It first search the @vport node list to find
2623 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2624 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2625 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2626 *
2627 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2628 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2629 * will be stored into the context1 field of the IOCB for the completion
2630 * callback function to the PARPR ELS command.
2631 *
2632 * Return code
2633 * 0 - Successfully issued farpr command
2634 * 1 - Failed to issue farpr command
2635 **/
dea31012005-04-17 16:05:31 -05002636static int
James Smart2e0fef82007-06-17 19:56:36 -05002637lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002638{
James Smart2e0fef82007-06-17 19:56:36 -05002639 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002640 IOCB_t *icmd;
2641 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002642 struct lpfc_sli *psli;
2643 FARP *fp;
2644 uint8_t *pcmd;
2645 uint32_t *lp;
2646 uint16_t cmdsize;
2647 struct lpfc_nodelist *ondlp;
2648 struct lpfc_nodelist *ndlp;
2649
2650 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002651 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002652
James Smarte47c9092008-02-08 18:49:26 -05002653 ndlp = lpfc_findnode_did(vport, nportid);
2654 if (!ndlp) {
2655 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2656 if (!ndlp)
2657 return 1;
2658 lpfc_nlp_init(vport, ndlp, nportid);
2659 lpfc_enqueue_node(vport, ndlp);
2660 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2661 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2662 if (!ndlp)
2663 return 1;
2664 }
James Smart2e0fef82007-06-17 19:56:36 -05002665
2666 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2667 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002668 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002669 /* This will trigger the release of the node just
2670 * allocated
2671 */
James Smart329f9bc2007-04-25 09:53:01 -04002672 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002673 return 1;
dea31012005-04-17 16:05:31 -05002674 }
2675
2676 icmd = &elsiocb->iocb;
2677 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2678
2679 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002680 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002681
2682 /* Fill in FARPR payload */
2683 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002684 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002685 lp = (uint32_t *) pcmd;
2686 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002687 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002688 fp->Rflags = 0;
2689 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2690
James Smart92d7f7b2007-06-17 19:56:38 -05002691 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2692 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002693 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002694 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002695 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002696 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002697 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002698 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002699 }
2700
James Smart858c9f62007-06-17 19:56:39 -05002701 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2702 "Issue FARPR: did:x%x",
2703 ndlp->nlp_DID, 0, 0);
2704
dea31012005-04-17 16:05:31 -05002705 phba->fc_stat.elsXmitFARPR++;
2706 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002707 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2708 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002709 /* The additional lpfc_nlp_put will cause the following
2710 * lpfc_els_free_iocb routine to trigger the release of
2711 * the node.
2712 */
James Smart329f9bc2007-04-25 09:53:01 -04002713 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002714 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002715 return 1;
dea31012005-04-17 16:05:31 -05002716 }
James Smartfa4066b2008-01-11 01:53:27 -05002717 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2718 * trigger the release of the node.
2719 */
James Smart329f9bc2007-04-25 09:53:01 -04002720 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002721 return 0;
dea31012005-04-17 16:05:31 -05002722}
2723
James Smarte59058c2008-08-24 21:49:00 -04002724/**
James Smart3621a712009-04-06 18:47:14 -04002725 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002726 * @vport: pointer to a host virtual N_Port data structure.
2727 * @nlp: pointer to a node-list data structure.
2728 *
2729 * This routine cancels the timer with a delayed IOCB-command retry for
2730 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2731 * removes the ELS retry event if it presents. In addition, if the
2732 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2733 * commands are sent for the @vport's nodes that require issuing discovery
2734 * ADISC.
2735 **/
dea31012005-04-17 16:05:31 -05002736void
James Smart2e0fef82007-06-17 19:56:36 -05002737lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002738{
James Smart2e0fef82007-06-17 19:56:36 -05002739 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002740 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002741
James Smart0d2b6b82008-06-14 22:52:47 -04002742 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2743 return;
James Smart2e0fef82007-06-17 19:56:36 -05002744 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002745 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002746 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002747 del_timer_sync(&nlp->nlp_delayfunc);
2748 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002749 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002750 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002751 /* Decrement nlp reference count held for the delayed retry */
2752 evtp = &nlp->els_retry_evt;
2753 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2754 }
James Smartfdcebe22006-03-07 15:04:01 -05002755 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002756 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002757 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002758 spin_unlock_irq(shost->host_lock);
2759 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002760 if (vport->port_state < LPFC_VPORT_READY) {
2761 /* Check if there are more ADISCs to be sent */
2762 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002763 } else {
2764 /* Check if there are more PLOGIs to be sent */
2765 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002766 if (vport->num_disc_nodes == 0) {
2767 spin_lock_irq(shost->host_lock);
2768 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2769 spin_unlock_irq(shost->host_lock);
2770 lpfc_can_disctmo(vport);
2771 lpfc_end_rscn(vport);
2772 }
James Smartfdcebe22006-03-07 15:04:01 -05002773 }
2774 }
2775 }
2776 return;
2777}
2778
James Smarte59058c2008-08-24 21:49:00 -04002779/**
James Smart3621a712009-04-06 18:47:14 -04002780 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002781 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2782 *
2783 * This routine is invoked by the ndlp delayed-function timer to check
2784 * whether there is any pending ELS retry event(s) with the node. If not, it
2785 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2786 * adds the delayed events to the HBA work list and invokes the
2787 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2788 * event. Note that lpfc_nlp_get() is called before posting the event to
2789 * the work list to hold reference count of ndlp so that it guarantees the
2790 * reference to ndlp will still be available when the worker thread gets
2791 * to the event associated with the ndlp.
2792 **/
James Smartfdcebe22006-03-07 15:04:01 -05002793void
dea31012005-04-17 16:05:31 -05002794lpfc_els_retry_delay(unsigned long ptr)
2795{
James Smart2e0fef82007-06-17 19:56:36 -05002796 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2797 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002798 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002799 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002800 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002801
James Smart92d7f7b2007-06-17 19:56:38 -05002802 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002803 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002804 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002805 return;
2806 }
2807
James Smartfa4066b2008-01-11 01:53:27 -05002808 /* We need to hold the node by incrementing the reference
2809 * count until the queued work is done
2810 */
2811 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002812 if (evtp->evt_arg1) {
2813 evtp->evt = LPFC_EVT_ELS_RETRY;
2814 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002815 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002816 }
James Smart92d7f7b2007-06-17 19:56:38 -05002817 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002818 return;
2819}
2820
James Smarte59058c2008-08-24 21:49:00 -04002821/**
James Smart3621a712009-04-06 18:47:14 -04002822 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002823 * @ndlp: pointer to a node-list data structure.
2824 *
2825 * This routine is the worker-thread handler for processing the @ndlp delayed
2826 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2827 * the last ELS command from the associated ndlp and invokes the proper ELS
2828 * function according to the delayed ELS command to retry the command.
2829 **/
dea31012005-04-17 16:05:31 -05002830void
2831lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2832{
James Smart2e0fef82007-06-17 19:56:36 -05002833 struct lpfc_vport *vport = ndlp->vport;
2834 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2835 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002836
James Smart2e0fef82007-06-17 19:56:36 -05002837 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002838 did = ndlp->nlp_DID;
2839 cmd = ndlp->nlp_last_elscmd;
2840 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002841
2842 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002843 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002844 return;
2845 }
2846
2847 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002848 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002849 /*
2850 * If a discovery event readded nlp_delayfunc after timer
2851 * firing and before processing the timer, cancel the
2852 * nlp_delayfunc.
2853 */
2854 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002855 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002856 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002857
2858 switch (cmd) {
2859 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002860 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002861 break;
2862 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002863 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002864 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002865 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002866 }
dea31012005-04-17 16:05:31 -05002867 break;
2868 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002869 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002870 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002871 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002872 }
dea31012005-04-17 16:05:31 -05002873 break;
2874 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002875 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002876 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002877 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002878 }
dea31012005-04-17 16:05:31 -05002879 break;
2880 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002881 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002882 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002883 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002884 }
dea31012005-04-17 16:05:31 -05002885 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002886 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05002887 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
2888 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05002889 break;
dea31012005-04-17 16:05:31 -05002890 }
2891 return;
2892}
2893
James Smarte59058c2008-08-24 21:49:00 -04002894/**
James Smart3621a712009-04-06 18:47:14 -04002895 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002896 * @phba: pointer to lpfc hba data structure.
2897 * @cmdiocb: pointer to lpfc command iocb data structure.
2898 * @rspiocb: pointer to lpfc response iocb data structure.
2899 *
2900 * This routine makes a retry decision on an ELS command IOCB, which has
2901 * failed. The following ELS IOCBs use this function for retrying the command
2902 * when previously issued command responsed with error status: FLOGI, PLOGI,
2903 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2904 * returned error status, it makes the decision whether a retry shall be
2905 * issued for the command, and whether a retry shall be made immediately or
2906 * delayed. In the former case, the corresponding ELS command issuing-function
2907 * is called to retry the command. In the later case, the ELS command shall
2908 * be posted to the ndlp delayed event and delayed function timer set to the
2909 * ndlp for the delayed command issusing.
2910 *
2911 * Return code
2912 * 0 - No retry of els command is made
2913 * 1 - Immediate or delayed retry of els command is made
2914 **/
dea31012005-04-17 16:05:31 -05002915static int
James Smart2e0fef82007-06-17 19:56:36 -05002916lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2917 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002918{
James Smart2e0fef82007-06-17 19:56:36 -05002919 struct lpfc_vport *vport = cmdiocb->vport;
2920 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2921 IOCB_t *irsp = &rspiocb->iocb;
2922 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2923 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002924 uint32_t *elscmd;
2925 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002926 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002927 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002928 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002929 uint32_t did;
dea31012005-04-17 16:05:31 -05002930
James Smart488d1462006-03-07 15:02:37 -05002931
dea31012005-04-17 16:05:31 -05002932 /* Note: context2 may be 0 for internal driver abort
2933 * of delays ELS command.
2934 */
2935
2936 if (pcmd && pcmd->virt) {
2937 elscmd = (uint32_t *) (pcmd->virt);
2938 cmd = *elscmd++;
2939 }
2940
James Smarte47c9092008-02-08 18:49:26 -05002941 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002942 did = ndlp->nlp_DID;
2943 else {
2944 /* We should only hit this case for retrying PLOGI */
2945 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002946 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002947 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2948 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002949 return 1;
2950 }
2951
James Smart858c9f62007-06-17 19:56:39 -05002952 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2953 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2954 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2955
dea31012005-04-17 16:05:31 -05002956 switch (irsp->ulpStatus) {
2957 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05002958 break;
James Smart1151e3e2011-02-16 12:39:35 -05002959 case IOSTAT_REMOTE_STOP:
2960 if (phba->sli_rev == LPFC_SLI_REV4) {
2961 /* This IO was aborted by the target, we don't
2962 * know the rxid and because we did not send the
2963 * ABTS we cannot generate and RRQ.
2964 */
2965 lpfc_set_rrq_active(phba, ndlp,
2966 cmdiocb->sli4_xritag, 0, 0);
2967 }
2968 break;
dea31012005-04-17 16:05:31 -05002969 case IOSTAT_LOCAL_REJECT:
2970 switch ((irsp->un.ulpWord[4] & 0xff)) {
2971 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002972 if (cmd == ELS_CMD_FLOGI) {
2973 if (PCI_DEVICE_ID_HORNET ==
2974 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05002975 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05002976 phba->pport->fc_myDID = 0;
2977 phba->alpa_map[0] = 0;
2978 phba->alpa_map[1] = 0;
2979 }
2980 }
James Smart2e0fef82007-06-17 19:56:36 -05002981 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002982 delay = 1000;
dea31012005-04-17 16:05:31 -05002983 retry = 1;
2984 break;
2985
James Smart92d7f7b2007-06-17 19:56:38 -05002986 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002987 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2988 "0124 Retry illegal cmd x%x "
2989 "retry:x%x delay:x%x\n",
2990 cmd, cmdiocb->retry, delay);
2991 retry = 1;
2992 /* All command's retry policy */
2993 maxretry = 8;
2994 if (cmdiocb->retry > 2)
2995 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002996 break;
2997
dea31012005-04-17 16:05:31 -05002998 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002999 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05003000 retry = 1;
3001 if (cmdiocb->retry > 100)
3002 delay = 100;
3003 maxretry = 250;
3004 break;
3005
3006 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05003007 delay = 100;
dea31012005-04-17 16:05:31 -05003008 retry = 1;
3009 break;
3010
James Smart858c9f62007-06-17 19:56:39 -05003011 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05003012 case IOERR_INVALID_RPI:
3013 retry = 1;
3014 break;
3015 }
3016 break;
3017
3018 case IOSTAT_NPORT_RJT:
3019 case IOSTAT_FABRIC_RJT:
3020 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3021 retry = 1;
3022 break;
3023 }
3024 break;
3025
3026 case IOSTAT_NPORT_BSY:
3027 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04003028 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05003029 retry = 1;
3030 break;
3031
3032 case IOSTAT_LS_RJT:
3033 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3034 /* Added for Vendor specifc support
3035 * Just keep retrying for these Rsn / Exp codes
3036 */
3037 switch (stat.un.b.lsRjtRsnCode) {
3038 case LSRJT_UNABLE_TPC:
3039 if (stat.un.b.lsRjtRsnCodeExp ==
3040 LSEXP_CMD_IN_PROGRESS) {
3041 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003042 delay = 1000;
dea31012005-04-17 16:05:31 -05003043 maxretry = 48;
3044 }
3045 retry = 1;
3046 break;
3047 }
James Smartffc95492010-06-07 15:23:17 -04003048 if (stat.un.b.lsRjtRsnCodeExp ==
3049 LSEXP_CANT_GIVE_DATA) {
3050 if (cmd == ELS_CMD_PLOGI) {
3051 delay = 1000;
3052 maxretry = 48;
3053 }
3054 retry = 1;
3055 break;
3056 }
dea31012005-04-17 16:05:31 -05003057 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003058 delay = 1000;
dea31012005-04-17 16:05:31 -05003059 maxretry = lpfc_max_els_tries + 1;
3060 retry = 1;
3061 break;
3062 }
James Smart92d7f7b2007-06-17 19:56:38 -05003063 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3064 (cmd == ELS_CMD_FDISC) &&
3065 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003066 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3067 "0125 FDISC Failed (x%x). "
3068 "Fabric out of resources\n",
3069 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003070 lpfc_vport_set_state(vport,
3071 FC_VPORT_NO_FABRIC_RSCS);
3072 }
dea31012005-04-17 16:05:31 -05003073 break;
3074
3075 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003076 if ((cmd == ELS_CMD_PLOGI) ||
3077 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003078 delay = 1000;
dea31012005-04-17 16:05:31 -05003079 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003080 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003081 /* FDISC retry policy */
3082 maxretry = 48;
3083 if (cmdiocb->retry >= 32)
3084 delay = 1000;
dea31012005-04-17 16:05:31 -05003085 }
3086 retry = 1;
3087 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003088
3089 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003090 /* There are some cases where switches return this
3091 * error when they are not ready and should be returning
3092 * Logical Busy. We should delay every time.
3093 */
3094 if (cmd == ELS_CMD_FDISC &&
3095 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3096 maxretry = 3;
3097 delay = 1000;
3098 retry = 1;
3099 break;
3100 }
James Smart92d7f7b2007-06-17 19:56:38 -05003101 case LSRJT_PROTOCOL_ERR:
3102 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3103 (cmd == ELS_CMD_FDISC) &&
3104 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3105 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3106 ) {
James Smarte8b62012007-08-02 11:10:09 -04003107 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003108 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003109 "Fabric Detected Bad WWN\n",
3110 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003111 lpfc_vport_set_state(vport,
3112 FC_VPORT_FABRIC_REJ_WWN);
3113 }
3114 break;
dea31012005-04-17 16:05:31 -05003115 }
3116 break;
3117
3118 case IOSTAT_INTERMED_RSP:
3119 case IOSTAT_BA_RJT:
3120 break;
3121
3122 default:
3123 break;
3124 }
3125
James Smart488d1462006-03-07 15:02:37 -05003126 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003127 retry = 1;
dea31012005-04-17 16:05:31 -05003128
James Smartdf9e1b52011-12-13 13:22:17 -05003129 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05003130 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003131 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003132 /* FLOGI retry policy */
3133 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05003134 /* retry FLOGI forever */
James Smart6669f9b2009-10-02 15:16:45 -04003135 maxretry = 0;
3136 if (cmdiocb->retry >= 100)
3137 delay = 5000;
3138 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003139 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05003140 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3141 /* retry FDISCs every second up to devloss */
3142 retry = 1;
3143 maxretry = vport->cfg_devloss_tmo;
3144 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04003145 }
3146
James Smart6669f9b2009-10-02 15:16:45 -04003147 cmdiocb->retry++;
3148 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003149 phba->fc_stat.elsRetryExceeded++;
3150 retry = 0;
3151 }
3152
James Smarted957682007-06-17 19:56:37 -05003153 if ((vport->load_flag & FC_UNLOADING) != 0)
3154 retry = 0;
3155
dea31012005-04-17 16:05:31 -05003156 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003157 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3158 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3159 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3160 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3161 "2849 Stop retry ELS command "
3162 "x%x to remote NPORT x%x, "
3163 "Data: x%x x%x\n", cmd, did,
3164 cmdiocb->retry, delay);
3165 return 0;
3166 }
3167 }
dea31012005-04-17 16:05:31 -05003168
3169 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003170 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3171 "0107 Retry ELS command x%x to remote "
3172 "NPORT x%x Data: x%x x%x\n",
3173 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003174
James Smart858c9f62007-06-17 19:56:39 -05003175 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3176 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3177 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
3178 /* Don't reset timer for no resources */
3179
dea31012005-04-17 16:05:31 -05003180 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003181 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003182 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003183 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003184 }
3185
3186 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003187 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003188 phba->fc_stat.elsDelayRetry++;
3189 ndlp->nlp_retry = cmdiocb->retry;
3190
James Smart92d7f7b2007-06-17 19:56:38 -05003191 /* delay is specified in milliseconds */
3192 mod_timer(&ndlp->nlp_delayfunc,
3193 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003194 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003195 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003196 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003197
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003198 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003199 if (cmd == ELS_CMD_PRLI)
3200 lpfc_nlp_set_state(vport, ndlp,
3201 NLP_STE_REG_LOGIN_ISSUE);
3202 else
3203 lpfc_nlp_set_state(vport, ndlp,
3204 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003205 ndlp->nlp_last_elscmd = cmd;
3206
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003207 return 1;
dea31012005-04-17 16:05:31 -05003208 }
3209 switch (cmd) {
3210 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003211 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003212 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003213 case ELS_CMD_FDISC:
3214 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3215 return 1;
dea31012005-04-17 16:05:31 -05003216 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003217 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003218 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003219 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003220 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003221 }
James Smart2e0fef82007-06-17 19:56:36 -05003222 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003223 return 1;
dea31012005-04-17 16:05:31 -05003224 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003225 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003226 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3227 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003228 return 1;
dea31012005-04-17 16:05:31 -05003229 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003230 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003231 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3232 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003233 return 1;
dea31012005-04-17 16:05:31 -05003234 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003235 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003236 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3237 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003238 return 1;
dea31012005-04-17 16:05:31 -05003239 }
3240 }
dea31012005-04-17 16:05:31 -05003241 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003242 if (logerr) {
3243 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3244 "0137 No retry ELS command x%x to remote "
3245 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3246 cmd, did, irsp->ulpStatus,
3247 irsp->un.ulpWord[4]);
3248 }
3249 else {
3250 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003251 "0108 No retry ELS command x%x to remote "
3252 "NPORT x%x Retried:%d Error:x%x/%x\n",
3253 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3254 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003255 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003256 return 0;
dea31012005-04-17 16:05:31 -05003257}
3258
James Smarte59058c2008-08-24 21:49:00 -04003259/**
James Smart3621a712009-04-06 18:47:14 -04003260 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003261 * @phba: pointer to lpfc hba data structure.
3262 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3263 *
3264 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3265 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3266 * checks to see whether there is a lpfc DMA buffer associated with the
3267 * response of the command IOCB. If so, it will be released before releasing
3268 * the lpfc DMA buffer associated with the IOCB itself.
3269 *
3270 * Return code
3271 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3272 **/
James Smart09372822008-01-11 01:52:54 -05003273static int
James Smart87af33f2007-10-27 13:37:43 -04003274lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3275{
3276 struct lpfc_dmabuf *buf_ptr;
3277
James Smarte59058c2008-08-24 21:49:00 -04003278 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003279 if (!list_empty(&buf_ptr1->list)) {
3280 list_remove_head(&buf_ptr1->list, buf_ptr,
3281 struct lpfc_dmabuf,
3282 list);
3283 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3284 kfree(buf_ptr);
3285 }
3286 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3287 kfree(buf_ptr1);
3288 return 0;
3289}
3290
James Smarte59058c2008-08-24 21:49:00 -04003291/**
James Smart3621a712009-04-06 18:47:14 -04003292 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003293 * @phba: pointer to lpfc hba data structure.
3294 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3295 *
3296 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3297 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3298 * pool.
3299 *
3300 * Return code
3301 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3302 **/
James Smart09372822008-01-11 01:52:54 -05003303static int
James Smart87af33f2007-10-27 13:37:43 -04003304lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3305{
3306 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3307 kfree(buf_ptr);
3308 return 0;
3309}
3310
James Smarte59058c2008-08-24 21:49:00 -04003311/**
James Smart3621a712009-04-06 18:47:14 -04003312 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003313 * @phba: pointer to lpfc hba data structure.
3314 * @elsiocb: pointer to lpfc els command iocb data structure.
3315 *
3316 * This routine frees a command IOCB and its associated resources. The
3317 * command IOCB data structure contains the reference to various associated
3318 * resources, these fields must be set to NULL if the associated reference
3319 * not present:
3320 * context1 - reference to ndlp
3321 * context2 - reference to cmd
3322 * context2->next - reference to rsp
3323 * context3 - reference to bpl
3324 *
3325 * It first properly decrements the reference count held on ndlp for the
3326 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3327 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3328 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3329 * adds the DMA buffer the @phba data structure for the delayed release.
3330 * If reference to the Buffer Pointer List (BPL) is present, the
3331 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3332 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3333 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3334 *
3335 * Return code
3336 * 0 - Success (currently, always return 0)
3337 **/
James Smart87af33f2007-10-27 13:37:43 -04003338int
James Smart329f9bc2007-04-25 09:53:01 -04003339lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003340{
3341 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003342 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003343
James Smarta8adb832007-10-27 13:37:53 -04003344 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3345 if (ndlp) {
3346 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3347 lpfc_nlp_put(ndlp);
3348
3349 /* If the ndlp is not being used by another discovery
3350 * thread, free it.
3351 */
3352 if (!lpfc_nlp_not_used(ndlp)) {
3353 /* If ndlp is being used by another discovery
3354 * thread, just clear NLP_DEFER_RM
3355 */
3356 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3357 }
3358 }
3359 else
3360 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003361 elsiocb->context1 = NULL;
3362 }
dea31012005-04-17 16:05:31 -05003363 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3364 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003365 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3366 /* Firmware could still be in progress of DMAing
3367 * payload, so don't free data buffer till after
3368 * a hbeat.
3369 */
3370 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3371 buf_ptr = elsiocb->context2;
3372 elsiocb->context2 = NULL;
3373 if (buf_ptr) {
3374 buf_ptr1 = NULL;
3375 spin_lock_irq(&phba->hbalock);
3376 if (!list_empty(&buf_ptr->list)) {
3377 list_remove_head(&buf_ptr->list,
3378 buf_ptr1, struct lpfc_dmabuf,
3379 list);
3380 INIT_LIST_HEAD(&buf_ptr1->list);
3381 list_add_tail(&buf_ptr1->list,
3382 &phba->elsbuf);
3383 phba->elsbuf_cnt++;
3384 }
3385 INIT_LIST_HEAD(&buf_ptr->list);
3386 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3387 phba->elsbuf_cnt++;
3388 spin_unlock_irq(&phba->hbalock);
3389 }
3390 } else {
3391 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3392 lpfc_els_free_data(phba, buf_ptr1);
3393 }
dea31012005-04-17 16:05:31 -05003394 }
3395
3396 if (elsiocb->context3) {
3397 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003398 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003399 }
James Bottomley604a3e32005-10-29 10:28:33 -05003400 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003401 return 0;
3402}
3403
James Smarte59058c2008-08-24 21:49:00 -04003404/**
James Smart3621a712009-04-06 18:47:14 -04003405 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003406 * @phba: pointer to lpfc hba data structure.
3407 * @cmdiocb: pointer to lpfc command iocb data structure.
3408 * @rspiocb: pointer to lpfc response iocb data structure.
3409 *
3410 * This routine is the completion callback function to the Logout (LOGO)
3411 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3412 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3413 * release the ndlp if it has the last reference remaining (reference count
3414 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3415 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3416 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3417 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3418 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3419 * IOCB data structure.
3420 **/
dea31012005-04-17 16:05:31 -05003421static void
James Smart2e0fef82007-06-17 19:56:36 -05003422lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3423 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003424{
James Smart2e0fef82007-06-17 19:56:36 -05003425 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3426 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003427 IOCB_t *irsp;
3428
3429 irsp = &rspiocb->iocb;
3430 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3431 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3432 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003433 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003434 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3435 "0109 ACC to LOGO completes to NPort x%x "
3436 "Data: x%x x%x x%x\n",
3437 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3438 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003439
3440 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3441 /* NPort Recovery mode or node is just allocated */
3442 if (!lpfc_nlp_not_used(ndlp)) {
3443 /* If the ndlp is being used by another discovery
3444 * thread, just unregister the RPI.
3445 */
3446 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003447 } else {
3448 /* Indicate the node has already released, should
3449 * not reference to it from within lpfc_els_free_iocb.
3450 */
3451 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003452 }
dea31012005-04-17 16:05:31 -05003453 }
James Smart73d91e52011-10-10 21:32:10 -04003454
3455 /*
3456 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05003457 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04003458 */
dea31012005-04-17 16:05:31 -05003459 lpfc_els_free_iocb(phba, cmdiocb);
James Smartdf9e1b52011-12-13 13:22:17 -05003460
3461 /*
3462 * Remove the ndlp reference if it's a fabric node that has
3463 * sent us an unsolicted LOGO.
3464 */
3465 if (ndlp->nlp_type & NLP_FABRIC)
3466 lpfc_nlp_put(ndlp);
3467
dea31012005-04-17 16:05:31 -05003468 return;
3469}
3470
James Smarte59058c2008-08-24 21:49:00 -04003471/**
James Smart3621a712009-04-06 18:47:14 -04003472 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003473 * @phba: pointer to lpfc hba data structure.
3474 * @pmb: pointer to the driver internal queue element for mailbox command.
3475 *
3476 * This routine is the completion callback function for unregister default
3477 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3478 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3479 * decrements the ndlp reference count held for this completion callback
3480 * function. After that, it invokes the lpfc_nlp_not_used() to check
3481 * whether there is only one reference left on the ndlp. If so, it will
3482 * perform one more decrement and trigger the release of the ndlp.
3483 **/
James Smart858c9f62007-06-17 19:56:39 -05003484void
3485lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3486{
3487 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3488 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3489
3490 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003491 pmb->context2 = NULL;
3492
James Smart858c9f62007-06-17 19:56:39 -05003493 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3494 kfree(mp);
3495 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003496 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003497 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003498 /* This is the end of the default RPI cleanup logic for this
3499 * ndlp. If no other discovery threads are using this ndlp.
3500 * we should free all resources associated with it.
3501 */
3502 lpfc_nlp_not_used(ndlp);
3503 }
James Smart3772a992009-05-22 14:50:54 -04003504
James Smart858c9f62007-06-17 19:56:39 -05003505 return;
3506}
3507
James Smarte59058c2008-08-24 21:49:00 -04003508/**
James Smart3621a712009-04-06 18:47:14 -04003509 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003510 * @phba: pointer to lpfc hba data structure.
3511 * @cmdiocb: pointer to lpfc command iocb data structure.
3512 * @rspiocb: pointer to lpfc response iocb data structure.
3513 *
3514 * This routine is the completion callback function for ELS Response IOCB
3515 * command. In normal case, this callback function just properly sets the
3516 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3517 * field in the command IOCB is not NULL, the referred mailbox command will
3518 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3519 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3520 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3521 * routine shall be invoked trying to release the ndlp if no other threads
3522 * are currently referring it.
3523 **/
dea31012005-04-17 16:05:31 -05003524static void
James Smart858c9f62007-06-17 19:56:39 -05003525lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003526 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003527{
James Smart2e0fef82007-06-17 19:56:36 -05003528 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3529 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3530 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003531 IOCB_t *irsp;
3532 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003533 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003534 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003535 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003536
James Smart33ccf8d2006-08-17 11:57:58 -04003537 irsp = &rspiocb->iocb;
3538
dea31012005-04-17 16:05:31 -05003539 if (cmdiocb->context_un.mbox)
3540 mbox = cmdiocb->context_un.mbox;
3541
James Smartfa4066b2008-01-11 01:53:27 -05003542 /* First determine if this is a LS_RJT cmpl. Note, this callback
3543 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3544 */
James Smart87af33f2007-10-27 13:37:43 -04003545 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003546 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3547 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003548 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003549 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003550 */
3551 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3552 ls_rjt = 1;
3553 }
3554
dea31012005-04-17 16:05:31 -05003555 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003556 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003557 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003558 mp = (struct lpfc_dmabuf *) mbox->context1;
3559 if (mp) {
3560 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3561 kfree(mp);
3562 }
James Smart329f9bc2007-04-25 09:53:01 -04003563 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003564 }
James Smart58da1ff2008-04-07 10:15:56 -04003565 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3566 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003567 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003568 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003569 /* Indicate the node has already released,
3570 * should not reference to it from within
3571 * the routine lpfc_els_free_iocb.
3572 */
3573 cmdiocb->context1 = NULL;
3574 }
dea31012005-04-17 16:05:31 -05003575 goto out;
3576 }
3577
James Smart858c9f62007-06-17 19:56:39 -05003578 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003579 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003580 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003581 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003582 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003583 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3584 "0110 ELS response tag x%x completes "
3585 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3586 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3587 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3588 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3589 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003590 if (mbox) {
3591 if ((rspiocb->iocb.ulpStatus == 0)
3592 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003593 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003594 /* Increment reference count to ndlp to hold the
3595 * reference to ndlp for the callback function.
3596 */
James Smart329f9bc2007-04-25 09:53:01 -04003597 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003598 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003599 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3600 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3601 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3602 }
3603 else {
3604 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3605 ndlp->nlp_prev_state = ndlp->nlp_state;
3606 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003607 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003608 }
James Smart0b727fe2007-10-27 13:37:25 -04003609 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003610 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003611 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003612 else
3613 /* Decrement the ndlp reference count we
3614 * set for this failed mailbox command.
3615 */
3616 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003617
3618 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3619 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3620 "0138 ELS rsp: Cannot issue reg_login for x%x "
3621 "Data: x%x x%x x%x\n",
3622 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3623 ndlp->nlp_rpi);
3624
James Smartfa4066b2008-01-11 01:53:27 -05003625 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003626 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003627 /* Indicate node has already been released,
3628 * should not reference to it from within
3629 * the routine lpfc_els_free_iocb.
3630 */
3631 cmdiocb->context1 = NULL;
3632 }
dea31012005-04-17 16:05:31 -05003633 } else {
James Smart858c9f62007-06-17 19:56:39 -05003634 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3635 if (!lpfc_error_lost_link(irsp) &&
3636 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003637 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003638 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003639 /* Indicate node has already been
3640 * released, should not reference
3641 * to it from within the routine
3642 * lpfc_els_free_iocb.
3643 */
3644 cmdiocb->context1 = NULL;
3645 }
dea31012005-04-17 16:05:31 -05003646 }
3647 }
James Smart14691152006-12-02 13:34:28 -05003648 mp = (struct lpfc_dmabuf *) mbox->context1;
3649 if (mp) {
3650 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3651 kfree(mp);
3652 }
3653 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003654 }
3655out:
James Smart58da1ff2008-04-07 10:15:56 -04003656 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003657 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003658 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003659 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003660
3661 /* If the node is not being used by another discovery thread,
3662 * and we are sending a reject, we are done with it.
3663 * Release driver reference count here and free associated
3664 * resources.
3665 */
3666 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003667 if (lpfc_nlp_not_used(ndlp))
3668 /* Indicate node has already been released,
3669 * should not reference to it from within
3670 * the routine lpfc_els_free_iocb.
3671 */
3672 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003673 }
James Smart87af33f2007-10-27 13:37:43 -04003674
dea31012005-04-17 16:05:31 -05003675 lpfc_els_free_iocb(phba, cmdiocb);
3676 return;
3677}
3678
James Smarte59058c2008-08-24 21:49:00 -04003679/**
James Smart3621a712009-04-06 18:47:14 -04003680 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003681 * @vport: pointer to a host virtual N_Port data structure.
3682 * @flag: the els command code to be accepted.
3683 * @oldiocb: pointer to the original lpfc command iocb data structure.
3684 * @ndlp: pointer to a node-list data structure.
3685 * @mbox: pointer to the driver internal queue element for mailbox command.
3686 *
3687 * This routine prepares and issues an Accept (ACC) response IOCB
3688 * command. It uses the @flag to properly set up the IOCB field for the
3689 * specific ACC response command to be issued and invokes the
3690 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3691 * @mbox pointer is passed in, it will be put into the context_un.mbox
3692 * field of the IOCB for the completion callback function to issue the
3693 * mailbox command to the HBA later when callback is invoked.
3694 *
3695 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3696 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3697 * will be stored into the context1 field of the IOCB for the completion
3698 * callback function to the corresponding response ELS IOCB command.
3699 *
3700 * Return code
3701 * 0 - Successfully issued acc response
3702 * 1 - Failed to issue acc response
3703 **/
dea31012005-04-17 16:05:31 -05003704int
James Smart2e0fef82007-06-17 19:56:36 -05003705lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3706 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003707 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003708{
James Smart2e0fef82007-06-17 19:56:36 -05003709 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3710 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003711 IOCB_t *icmd;
3712 IOCB_t *oldcmd;
3713 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003714 struct lpfc_sli *psli;
3715 uint8_t *pcmd;
3716 uint16_t cmdsize;
3717 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003718 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003719
3720 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003721 oldcmd = &oldiocb->iocb;
3722
3723 switch (flag) {
3724 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003725 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003726 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3727 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003728 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003729 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003730 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003731 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003732 return 1;
dea31012005-04-17 16:05:31 -05003733 }
James Smart2e0fef82007-06-17 19:56:36 -05003734
dea31012005-04-17 16:05:31 -05003735 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003736 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3737 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003738 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3739 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003740 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003741
3742 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3743 "Issue ACC: did:x%x flg:x%x",
3744 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003745 break;
3746 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003747 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003748 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3749 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003750 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003751 return 1;
James Smart488d1462006-03-07 15:02:37 -05003752
dea31012005-04-17 16:05:31 -05003753 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003754 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3755 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003756 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3757
3758 if (mbox)
3759 elsiocb->context_un.mbox = mbox;
3760
3761 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003762 pcmd += sizeof(uint32_t);
3763 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003764
3765 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3766 "Issue ACC PLOGI: did:x%x flg:x%x",
3767 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003768 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003769 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003770 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003771 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003772 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3773 if (!elsiocb)
3774 return 1;
3775
3776 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003777 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3778 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04003779 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3780
3781 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003782 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003783 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3784 els_pkt_ptr = (ELS_PKT *) pcmd;
3785 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003786
3787 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3788 "Issue ACC PRLO: did:x%x flg:x%x",
3789 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003790 break;
dea31012005-04-17 16:05:31 -05003791 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003792 return 1;
dea31012005-04-17 16:05:31 -05003793 }
dea31012005-04-17 16:05:31 -05003794 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003795 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3796 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3797 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3798 elsiocb->iotag, elsiocb->iocb.ulpContext,
3799 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3800 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003801 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003802 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003803 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003804 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003805 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3806 } else {
James Smart858c9f62007-06-17 19:56:39 -05003807 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003808 }
3809
3810 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003811 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003812 if (rc == IOCB_ERROR) {
3813 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003814 return 1;
dea31012005-04-17 16:05:31 -05003815 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003816 return 0;
dea31012005-04-17 16:05:31 -05003817}
3818
James Smarte59058c2008-08-24 21:49:00 -04003819/**
James Smart3621a712009-04-06 18:47:14 -04003820 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003821 * @vport: pointer to a virtual N_Port data structure.
3822 * @rejectError:
3823 * @oldiocb: pointer to the original lpfc command iocb data structure.
3824 * @ndlp: pointer to a node-list data structure.
3825 * @mbox: pointer to the driver internal queue element for mailbox command.
3826 *
3827 * This routine prepares and issue an Reject (RJT) response IOCB
3828 * command. If a @mbox pointer is passed in, it will be put into the
3829 * context_un.mbox field of the IOCB for the completion callback function
3830 * to issue to the HBA later.
3831 *
3832 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3833 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3834 * will be stored into the context1 field of the IOCB for the completion
3835 * callback function to the reject response ELS IOCB command.
3836 *
3837 * Return code
3838 * 0 - Successfully issued reject response
3839 * 1 - Failed to issue reject response
3840 **/
dea31012005-04-17 16:05:31 -05003841int
James Smart2e0fef82007-06-17 19:56:36 -05003842lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003843 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3844 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003845{
James Smart2e0fef82007-06-17 19:56:36 -05003846 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003847 IOCB_t *icmd;
3848 IOCB_t *oldcmd;
3849 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003850 struct lpfc_sli *psli;
3851 uint8_t *pcmd;
3852 uint16_t cmdsize;
3853 int rc;
3854
3855 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003856 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003857 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3858 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003859 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003860 return 1;
dea31012005-04-17 16:05:31 -05003861
3862 icmd = &elsiocb->iocb;
3863 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003864 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3865 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003866 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3867
3868 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003869 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003870 *((uint32_t *) (pcmd)) = rejectError;
3871
James Smart51ef4c22007-08-02 11:10:31 -04003872 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003873 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003874
dea31012005-04-17 16:05:31 -05003875 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003876 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3877 "0129 Xmit ELS RJT x%x response tag x%x "
3878 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3879 "rpi x%x\n",
3880 rejectError, elsiocb->iotag,
3881 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3882 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003883 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3884 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3885 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3886
dea31012005-04-17 16:05:31 -05003887 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003888 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003889 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003890
dea31012005-04-17 16:05:31 -05003891 if (rc == IOCB_ERROR) {
3892 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003893 return 1;
dea31012005-04-17 16:05:31 -05003894 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003895 return 0;
dea31012005-04-17 16:05:31 -05003896}
3897
James Smarte59058c2008-08-24 21:49:00 -04003898/**
James Smart3621a712009-04-06 18:47:14 -04003899 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003900 * @vport: pointer to a virtual N_Port data structure.
3901 * @oldiocb: pointer to the original lpfc command iocb data structure.
3902 * @ndlp: pointer to a node-list data structure.
3903 *
3904 * This routine prepares and issues an Accept (ACC) response to Address
3905 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3906 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3907 *
3908 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3909 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3910 * will be stored into the context1 field of the IOCB for the completion
3911 * callback function to the ADISC Accept response ELS IOCB command.
3912 *
3913 * Return code
3914 * 0 - Successfully issued acc adisc response
3915 * 1 - Failed to issue adisc acc response
3916 **/
dea31012005-04-17 16:05:31 -05003917int
James Smart2e0fef82007-06-17 19:56:36 -05003918lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3919 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003920{
James Smart2e0fef82007-06-17 19:56:36 -05003921 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003922 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003923 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003924 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003925 uint8_t *pcmd;
3926 uint16_t cmdsize;
3927 int rc;
3928
James Smart92d7f7b2007-06-17 19:56:38 -05003929 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003930 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3931 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003932 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003933 return 1;
dea31012005-04-17 16:05:31 -05003934
dea31012005-04-17 16:05:31 -05003935 icmd = &elsiocb->iocb;
3936 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003937 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3938 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04003939
3940 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003941 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3942 "0130 Xmit ADISC ACC response iotag x%x xri: "
3943 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3944 elsiocb->iotag, elsiocb->iocb.ulpContext,
3945 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3946 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003947 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3948
3949 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003950 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003951
3952 ap = (ADISC *) (pcmd);
3953 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003954 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3955 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003956 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003957
James Smart858c9f62007-06-17 19:56:39 -05003958 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3959 "Issue ACC ADISC: did:x%x flg:x%x",
3960 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3961
dea31012005-04-17 16:05:31 -05003962 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003963 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003964 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003965 if (rc == IOCB_ERROR) {
3966 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003967 return 1;
dea31012005-04-17 16:05:31 -05003968 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003969 return 0;
dea31012005-04-17 16:05:31 -05003970}
3971
James Smarte59058c2008-08-24 21:49:00 -04003972/**
James Smart3621a712009-04-06 18:47:14 -04003973 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003974 * @vport: pointer to a virtual N_Port data structure.
3975 * @oldiocb: pointer to the original lpfc command iocb data structure.
3976 * @ndlp: pointer to a node-list data structure.
3977 *
3978 * This routine prepares and issues an Accept (ACC) response to Process
3979 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3980 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3981 *
3982 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3983 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3984 * will be stored into the context1 field of the IOCB for the completion
3985 * callback function to the PRLI Accept response ELS IOCB command.
3986 *
3987 * Return code
3988 * 0 - Successfully issued acc prli response
3989 * 1 - Failed to issue acc prli response
3990 **/
dea31012005-04-17 16:05:31 -05003991int
James Smart2e0fef82007-06-17 19:56:36 -05003992lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003993 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003994{
James Smart2e0fef82007-06-17 19:56:36 -05003995 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003996 PRLI *npr;
3997 lpfc_vpd_t *vpd;
3998 IOCB_t *icmd;
3999 IOCB_t *oldcmd;
4000 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004001 struct lpfc_sli *psli;
4002 uint8_t *pcmd;
4003 uint16_t cmdsize;
4004 int rc;
4005
4006 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05004007
James Smart92d7f7b2007-06-17 19:56:38 -05004008 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05004009 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05004010 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004011 if (!elsiocb)
4012 return 1;
dea31012005-04-17 16:05:31 -05004013
dea31012005-04-17 16:05:31 -05004014 icmd = &elsiocb->iocb;
4015 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004016 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4017 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4018
James Smart5b8bd0c2007-04-25 09:52:49 -04004019 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004020 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4021 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4022 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4023 elsiocb->iotag, elsiocb->iocb.ulpContext,
4024 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4025 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004026 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4027
4028 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05004029 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004030
4031 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05004032 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05004033
4034 npr = (PRLI *) pcmd;
4035 vpd = &phba->vpd;
4036 /*
James Smart0d2b6b82008-06-14 22:52:47 -04004037 * If the remote port is a target and our firmware version is 3.20 or
4038 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05004039 */
James Smart0d2b6b82008-06-14 22:52:47 -04004040 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4041 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05004042 npr->ConfmComplAllowed = 1;
4043 npr->Retry = 1;
4044 npr->TaskRetryIdReq = 1;
4045 }
4046
4047 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4048 npr->estabImagePair = 1;
4049 npr->readXferRdyDis = 1;
4050 npr->ConfmComplAllowed = 1;
4051
4052 npr->prliType = PRLI_FCP_TYPE;
4053 npr->initiatorFunc = 1;
4054
James Smart858c9f62007-06-17 19:56:39 -05004055 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4056 "Issue ACC PRLI: did:x%x flg:x%x",
4057 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4058
dea31012005-04-17 16:05:31 -05004059 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004060 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004061
James Smart3772a992009-05-22 14:50:54 -04004062 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004063 if (rc == IOCB_ERROR) {
4064 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004065 return 1;
dea31012005-04-17 16:05:31 -05004066 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004067 return 0;
dea31012005-04-17 16:05:31 -05004068}
4069
James Smarte59058c2008-08-24 21:49:00 -04004070/**
James Smart3621a712009-04-06 18:47:14 -04004071 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004072 * @vport: pointer to a virtual N_Port data structure.
4073 * @format: rnid command format.
4074 * @oldiocb: pointer to the original lpfc command iocb data structure.
4075 * @ndlp: pointer to a node-list data structure.
4076 *
4077 * This routine issues a Request Node Identification Data (RNID) Accept
4078 * (ACC) response. It constructs the RNID ACC response command according to
4079 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4080 * issue the response. Note that this command does not need to hold the ndlp
4081 * reference count for the callback. So, the ndlp reference count taken by
4082 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4083 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4084 * there is no ndlp reference available.
4085 *
4086 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4087 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4088 * will be stored into the context1 field of the IOCB for the completion
4089 * callback function. However, for the RNID Accept Response ELS command,
4090 * this is undone later by this routine after the IOCB is allocated.
4091 *
4092 * Return code
4093 * 0 - Successfully issued acc rnid response
4094 * 1 - Failed to issue acc rnid response
4095 **/
dea31012005-04-17 16:05:31 -05004096static int
James Smart2e0fef82007-06-17 19:56:36 -05004097lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004098 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004099{
James Smart2e0fef82007-06-17 19:56:36 -05004100 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004101 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004102 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004103 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004104 struct lpfc_sli *psli;
4105 uint8_t *pcmd;
4106 uint16_t cmdsize;
4107 int rc;
4108
4109 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004110 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4111 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004112 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004113 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004114
James Smart2e0fef82007-06-17 19:56:36 -05004115 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4116 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004117 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004118 return 1;
dea31012005-04-17 16:05:31 -05004119
dea31012005-04-17 16:05:31 -05004120 icmd = &elsiocb->iocb;
4121 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004122 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4123 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4124
James Smart5b8bd0c2007-04-25 09:52:49 -04004125 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004126 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4127 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4128 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004129 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004130 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004131 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004132
James Smart92d7f7b2007-06-17 19:56:38 -05004133 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004134 rn = (RNID *) (pcmd);
4135 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004136 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4137 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4138 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004139 switch (format) {
4140 case 0:
4141 rn->SpecificLen = 0;
4142 break;
4143 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004144 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004145 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004146 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004147 rn->un.topologyDisc.unitType = RNID_HBA;
4148 rn->un.topologyDisc.physPort = 0;
4149 rn->un.topologyDisc.attachedNodes = 0;
4150 break;
4151 default:
4152 rn->CommonLen = 0;
4153 rn->SpecificLen = 0;
4154 break;
4155 }
4156
James Smart858c9f62007-06-17 19:56:39 -05004157 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4158 "Issue ACC RNID: did:x%x flg:x%x",
4159 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4160
dea31012005-04-17 16:05:31 -05004161 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004162 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004163
James Smart3772a992009-05-22 14:50:54 -04004164 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004165 if (rc == IOCB_ERROR) {
4166 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004167 return 1;
dea31012005-04-17 16:05:31 -05004168 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004169 return 0;
dea31012005-04-17 16:05:31 -05004170}
4171
James Smarte59058c2008-08-24 21:49:00 -04004172/**
James Smart19ca7602010-11-20 23:11:55 -05004173 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4174 * @vport: pointer to a virtual N_Port data structure.
4175 * @iocb: pointer to the lpfc command iocb data structure.
4176 * @ndlp: pointer to a node-list data structure.
4177 *
4178 * Return
4179 **/
4180static void
4181lpfc_els_clear_rrq(struct lpfc_vport *vport,
4182 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4183{
4184 struct lpfc_hba *phba = vport->phba;
4185 uint8_t *pcmd;
4186 struct RRQ *rrq;
4187 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004188 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004189 struct lpfc_node_rrq *prrq;
4190
4191
4192 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4193 pcmd += sizeof(uint32_t);
4194 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004195 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b0622011-04-16 11:03:17 -04004196 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004197
4198 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4199 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4200 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004201 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b0622011-04-16 11:03:17 -04004202 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004203 rxid,
4204 iocb->iotag, iocb->iocb.ulpContext);
4205
4206 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4207 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4208 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004209 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b0622011-04-16 11:03:17 -04004210 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004211 else
4212 xri = rxid;
4213 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004214 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004215 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004216 return;
4217}
4218
4219/**
James Smart12265f62010-10-22 11:05:53 -04004220 * lpfc_els_rsp_echo_acc - Issue echo acc response
4221 * @vport: pointer to a virtual N_Port data structure.
4222 * @data: pointer to echo data to return in the accept.
4223 * @oldiocb: pointer to the original lpfc command iocb data structure.
4224 * @ndlp: pointer to a node-list data structure.
4225 *
4226 * Return code
4227 * 0 - Successfully issued acc echo response
4228 * 1 - Failed to issue acc echo response
4229 **/
4230static int
4231lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4232 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4233{
4234 struct lpfc_hba *phba = vport->phba;
4235 struct lpfc_iocbq *elsiocb;
4236 struct lpfc_sli *psli;
4237 uint8_t *pcmd;
4238 uint16_t cmdsize;
4239 int rc;
4240
4241 psli = &phba->sli;
4242 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4243
James Smartbf086112011-08-21 21:48:13 -04004244 /* The accumulated length can exceed the BPL_SIZE. For
4245 * now, use this as the limit
4246 */
4247 if (cmdsize > LPFC_BPL_SIZE)
4248 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04004249 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4250 ndlp->nlp_DID, ELS_CMD_ACC);
4251 if (!elsiocb)
4252 return 1;
4253
James Smart7851fe22011-07-22 18:36:52 -04004254 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4255 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4256
James Smart12265f62010-10-22 11:05:53 -04004257 /* Xmit ECHO ACC response tag <ulpIoTag> */
4258 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4259 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4260 elsiocb->iotag, elsiocb->iocb.ulpContext);
4261 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4262 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4263 pcmd += sizeof(uint32_t);
4264 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4265
4266 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4267 "Issue ACC ECHO: did:x%x flg:x%x",
4268 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4269
4270 phba->fc_stat.elsXmitACC++;
4271 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04004272
4273 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4274 if (rc == IOCB_ERROR) {
4275 lpfc_els_free_iocb(phba, elsiocb);
4276 return 1;
4277 }
4278 return 0;
4279}
4280
4281/**
James Smart3621a712009-04-06 18:47:14 -04004282 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004283 * @vport: pointer to a host virtual N_Port data structure.
4284 *
4285 * This routine issues Address Discover (ADISC) ELS commands to those
4286 * N_Ports which are in node port recovery state and ADISC has not been issued
4287 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4288 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4289 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4290 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4291 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4292 * IOCBs quit for later pick up. On the other hand, after walking through
4293 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4294 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4295 * no more ADISC need to be sent.
4296 *
4297 * Return code
4298 * The number of N_Ports with adisc issued.
4299 **/
dea31012005-04-17 16:05:31 -05004300int
James Smart2e0fef82007-06-17 19:56:36 -05004301lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004302{
James Smart2e0fef82007-06-17 19:56:36 -05004303 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004304 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004305 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004306
James Smart685f0bf2007-04-25 09:53:08 -04004307 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004308 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004309 if (!NLP_CHK_NODE_ACT(ndlp))
4310 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004311 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4312 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4313 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004314 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004315 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004316 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004317 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004318 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4319 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004320 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004321 vport->num_disc_nodes++;
4322 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004323 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004324 spin_lock_irq(shost->host_lock);
4325 vport->fc_flag |= FC_NLP_MORE;
4326 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004327 break;
dea31012005-04-17 16:05:31 -05004328 }
4329 }
4330 }
4331 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004332 spin_lock_irq(shost->host_lock);
4333 vport->fc_flag &= ~FC_NLP_MORE;
4334 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004335 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004336 return sentadisc;
dea31012005-04-17 16:05:31 -05004337}
4338
James Smarte59058c2008-08-24 21:49:00 -04004339/**
James Smart3621a712009-04-06 18:47:14 -04004340 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004341 * @vport: pointer to a host virtual N_Port data structure.
4342 *
4343 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4344 * which are in node port recovery state, with a @vport. Each time an ELS
4345 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4346 * the per @vport number of discover count (num_disc_nodes) shall be
4347 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4348 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4349 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4350 * later pick up. On the other hand, after walking through all the ndlps with
4351 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4352 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4353 * PLOGI need to be sent.
4354 *
4355 * Return code
4356 * The number of N_Ports with plogi issued.
4357 **/
dea31012005-04-17 16:05:31 -05004358int
James Smart2e0fef82007-06-17 19:56:36 -05004359lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004360{
James Smart2e0fef82007-06-17 19:56:36 -05004361 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004362 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004363 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004364
James Smart2e0fef82007-06-17 19:56:36 -05004365 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4366 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004367 if (!NLP_CHK_NODE_ACT(ndlp))
4368 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004369 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4370 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4371 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4372 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4373 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004374 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4375 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004376 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004377 vport->num_disc_nodes++;
4378 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004379 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004380 spin_lock_irq(shost->host_lock);
4381 vport->fc_flag |= FC_NLP_MORE;
4382 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004383 break;
dea31012005-04-17 16:05:31 -05004384 }
4385 }
4386 }
James Smart87af33f2007-10-27 13:37:43 -04004387 if (sentplogi) {
4388 lpfc_set_disctmo(vport);
4389 }
4390 else {
James Smart2e0fef82007-06-17 19:56:36 -05004391 spin_lock_irq(shost->host_lock);
4392 vport->fc_flag &= ~FC_NLP_MORE;
4393 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004394 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004395 return sentplogi;
dea31012005-04-17 16:05:31 -05004396}
4397
James Smarte59058c2008-08-24 21:49:00 -04004398/**
James Smart3621a712009-04-06 18:47:14 -04004399 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004400 * @vport: pointer to a host virtual N_Port data structure.
4401 *
4402 * This routine cleans up any Registration State Change Notification
4403 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4404 * @vport together with the host_lock is used to prevent multiple thread
4405 * trying to access the RSCN array on a same @vport at the same time.
4406 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004407void
James Smart2e0fef82007-06-17 19:56:36 -05004408lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004409{
James Smart2e0fef82007-06-17 19:56:36 -05004410 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4411 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004412 int i;
4413
James Smart7f5f3d02008-02-08 18:50:14 -05004414 spin_lock_irq(shost->host_lock);
4415 if (vport->fc_rscn_flush) {
4416 /* Another thread is walking fc_rscn_id_list on this vport */
4417 spin_unlock_irq(shost->host_lock);
4418 return;
4419 }
4420 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4421 vport->fc_rscn_flush = 1;
4422 spin_unlock_irq(shost->host_lock);
4423
James Smart2e0fef82007-06-17 19:56:36 -05004424 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004425 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004426 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004427 }
James Smart2e0fef82007-06-17 19:56:36 -05004428 spin_lock_irq(shost->host_lock);
4429 vport->fc_rscn_id_cnt = 0;
4430 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4431 spin_unlock_irq(shost->host_lock);
4432 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004433 /* Indicate we are done walking this fc_rscn_id_list */
4434 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004435}
4436
James Smarte59058c2008-08-24 21:49:00 -04004437/**
James Smart3621a712009-04-06 18:47:14 -04004438 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004439 * @vport: pointer to a host virtual N_Port data structure.
4440 * @did: remote destination port identifier.
4441 *
4442 * This routine checks whether there is any pending Registration State
4443 * Configuration Notification (RSCN) to a @did on @vport.
4444 *
4445 * Return code
4446 * None zero - The @did matched with a pending rscn
4447 * 0 - not able to match @did with a pending rscn
4448 **/
dea31012005-04-17 16:05:31 -05004449int
James Smart2e0fef82007-06-17 19:56:36 -05004450lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004451{
4452 D_ID ns_did;
4453 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004454 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004455 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004456 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004457
4458 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004459
4460 /* Never match fabric nodes for RSCNs */
4461 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004462 return 0;
dea31012005-04-17 16:05:31 -05004463
4464 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004465 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004466 return did;
dea31012005-04-17 16:05:31 -05004467
James Smart7f5f3d02008-02-08 18:50:14 -05004468 spin_lock_irq(shost->host_lock);
4469 if (vport->fc_rscn_flush) {
4470 /* Another thread is walking fc_rscn_id_list on this vport */
4471 spin_unlock_irq(shost->host_lock);
4472 return 0;
4473 }
4474 /* Indicate we are walking fc_rscn_id_list on this vport */
4475 vport->fc_rscn_flush = 1;
4476 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004477 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004478 lp = vport->fc_rscn_id_list[i]->virt;
4479 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4480 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004481 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004482 rscn_did.un.word = be32_to_cpu(*lp++);
4483 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004484 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4485 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004486 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4487 && (ns_did.un.b.area == rscn_did.un.b.area)
4488 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004489 goto return_did_out;
dea31012005-04-17 16:05:31 -05004490 break;
James Smarteaf15d52008-12-04 22:39:29 -05004491 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004492 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4493 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004494 goto return_did_out;
dea31012005-04-17 16:05:31 -05004495 break;
James Smarteaf15d52008-12-04 22:39:29 -05004496 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004497 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004498 goto return_did_out;
dea31012005-04-17 16:05:31 -05004499 break;
James Smarteaf15d52008-12-04 22:39:29 -05004500 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004501 goto return_did_out;
dea31012005-04-17 16:05:31 -05004502 }
4503 }
James Smart92d7f7b2007-06-17 19:56:38 -05004504 }
James Smart7f5f3d02008-02-08 18:50:14 -05004505 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4506 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004507 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004508return_did_out:
4509 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4510 vport->fc_rscn_flush = 0;
4511 return did;
dea31012005-04-17 16:05:31 -05004512}
4513
James Smarte59058c2008-08-24 21:49:00 -04004514/**
James Smart3621a712009-04-06 18:47:14 -04004515 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004516 * @vport: pointer to a host virtual N_Port data structure.
4517 *
4518 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4519 * state machine for a @vport's nodes that are with pending RSCN (Registration
4520 * State Change Notification).
4521 *
4522 * Return code
4523 * 0 - Successful (currently alway return 0)
4524 **/
dea31012005-04-17 16:05:31 -05004525static int
James Smart2e0fef82007-06-17 19:56:36 -05004526lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004527{
James Smart685f0bf2007-04-25 09:53:08 -04004528 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004529
James Smart0d2b6b82008-06-14 22:52:47 -04004530 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004531 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004532 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004533 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4534 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004535 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004536 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004537 NLP_EVT_DEVICE_RECOVERY);
4538 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004539 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004540 return 0;
dea31012005-04-17 16:05:31 -05004541}
4542
James Smarte59058c2008-08-24 21:49:00 -04004543/**
James Smart3621a712009-04-06 18:47:14 -04004544 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004545 * @vport: pointer to a host virtual N_Port data structure.
4546 * @cmdiocb: pointer to lpfc command iocb data structure.
4547 *
4548 * lpfc_send_rscn_event sends an RSCN netlink event to management
4549 * applications.
4550 */
4551static void
4552lpfc_send_rscn_event(struct lpfc_vport *vport,
4553 struct lpfc_iocbq *cmdiocb)
4554{
4555 struct lpfc_dmabuf *pcmd;
4556 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4557 uint32_t *payload_ptr;
4558 uint32_t payload_len;
4559 struct lpfc_rscn_event_header *rscn_event_data;
4560
4561 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4562 payload_ptr = (uint32_t *) pcmd->virt;
4563 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4564
4565 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4566 payload_len, GFP_KERNEL);
4567 if (!rscn_event_data) {
4568 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4569 "0147 Failed to allocate memory for RSCN event\n");
4570 return;
4571 }
4572 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4573 rscn_event_data->payload_length = payload_len;
4574 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4575 payload_len);
4576
4577 fc_host_post_vendor_event(shost,
4578 fc_get_event_number(),
4579 sizeof(struct lpfc_els_event_header) + payload_len,
4580 (char *)rscn_event_data,
4581 LPFC_NL_VENDOR_ID);
4582
4583 kfree(rscn_event_data);
4584}
4585
4586/**
James Smart3621a712009-04-06 18:47:14 -04004587 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004588 * @vport: pointer to a host virtual N_Port data structure.
4589 * @cmdiocb: pointer to lpfc command iocb data structure.
4590 * @ndlp: pointer to a node-list data structure.
4591 *
4592 * This routine processes an unsolicited RSCN (Registration State Change
4593 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4594 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4595 * discover state machine is about to begin discovery, it just accepts the
4596 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4597 * contains N_Port IDs for other vports on this HBA, it just accepts the
4598 * RSCN and ignore processing it. If the state machine is in the recovery
4599 * state, the fc_rscn_id_list of this @vport is walked and the
4600 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4601 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4602 * routine is invoked to handle the RSCN event.
4603 *
4604 * Return code
4605 * 0 - Just sent the acc response
4606 * 1 - Sent the acc response and waited for name server completion
4607 **/
dea31012005-04-17 16:05:31 -05004608static int
James Smart2e0fef82007-06-17 19:56:36 -05004609lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004610 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004611{
James Smart2e0fef82007-06-17 19:56:36 -05004612 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4613 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004614 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004615 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004616 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004617 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004618 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004619 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004620 int i;
dea31012005-04-17 16:05:31 -05004621
4622 icmd = &cmdiocb->iocb;
4623 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4624 lp = (uint32_t *) pcmd->virt;
4625
James Smart92d7f7b2007-06-17 19:56:38 -05004626 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4627 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004628 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004629 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4630 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004631 vport->fc_flag, payload_len, *lp,
4632 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004633
4634 /* Send an RSCN event to the management application */
4635 lpfc_send_rscn_event(vport, cmdiocb);
4636
James Smartd2873e42006-08-18 17:46:43 -04004637 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004638 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004639 FCH_EVT_RSCN, lp[i]);
4640
dea31012005-04-17 16:05:31 -05004641 /* If we are about to begin discovery, just ACC the RSCN.
4642 * Discovery processing will satisfy it.
4643 */
James Smart2e0fef82007-06-17 19:56:36 -05004644 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004645 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4646 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4647 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4648
James Smart51ef4c22007-08-02 11:10:31 -04004649 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004650 return 0;
dea31012005-04-17 16:05:31 -05004651 }
4652
James Smart92d7f7b2007-06-17 19:56:38 -05004653 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4654 * just ACC and ignore it.
4655 */
4656 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004657 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004658 i = payload_len;
4659 datap = lp;
4660 while (i > 0) {
4661 nportid = *datap++;
4662 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4663 i -= sizeof(uint32_t);
4664 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004665 if (lpfc_find_vport_by_did(phba, nportid))
4666 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004667 }
4668 if (rscn_id == hba_id) {
4669 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004670 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004671 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004672 "Data: x%x x%x x%x x%x\n",
4673 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004674 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004675 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4676 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4677 ndlp->nlp_DID, vport->port_state,
4678 ndlp->nlp_flag);
4679
James Smart92d7f7b2007-06-17 19:56:38 -05004680 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004681 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004682 return 0;
4683 }
4684 }
4685
James Smart7f5f3d02008-02-08 18:50:14 -05004686 spin_lock_irq(shost->host_lock);
4687 if (vport->fc_rscn_flush) {
4688 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004689 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004690 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004691 /* Send back ACC */
4692 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004693 return 0;
4694 }
4695 /* Indicate we are walking fc_rscn_id_list on this vport */
4696 vport->fc_rscn_flush = 1;
4697 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004698 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004699 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004700 /* If we are already processing an RSCN, save the received
4701 * RSCN payload buffer, cmdiocb->context2 to process later.
4702 */
James Smart2e0fef82007-06-17 19:56:36 -05004703 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004704 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4705 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4706 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4707
James Smart09372822008-01-11 01:52:54 -05004708 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004709 vport->fc_flag |= FC_RSCN_DEFERRED;
4710 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004711 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004712 vport->fc_flag |= FC_RSCN_MODE;
4713 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004714 if (rscn_cnt) {
4715 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4716 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4717 }
4718 if ((rscn_cnt) &&
4719 (payload_len + length <= LPFC_BPL_SIZE)) {
4720 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004721 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004722 memcpy(((uint8_t *)cmd) + length, lp,
4723 payload_len);
4724 } else {
4725 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4726 vport->fc_rscn_id_cnt++;
4727 /* If we zero, cmdiocb->context2, the calling
4728 * routine will not try to free it.
4729 */
4730 cmdiocb->context2 = NULL;
4731 }
dea31012005-04-17 16:05:31 -05004732 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004733 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4734 "0235 Deferred RSCN "
4735 "Data: x%x x%x x%x\n",
4736 vport->fc_rscn_id_cnt, vport->fc_flag,
4737 vport->port_state);
dea31012005-04-17 16:05:31 -05004738 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004739 vport->fc_flag |= FC_RSCN_DISCOVERY;
4740 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004741 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004742 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4743 "0234 ReDiscovery RSCN "
4744 "Data: x%x x%x x%x\n",
4745 vport->fc_rscn_id_cnt, vport->fc_flag,
4746 vport->port_state);
dea31012005-04-17 16:05:31 -05004747 }
James Smart7f5f3d02008-02-08 18:50:14 -05004748 /* Indicate we are done walking fc_rscn_id_list on this vport */
4749 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004750 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004751 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004752 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004753 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004754 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004755 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004756 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004757 return 0;
dea31012005-04-17 16:05:31 -05004758 }
James Smart858c9f62007-06-17 19:56:39 -05004759 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4760 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4761 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4762
James Smart2e0fef82007-06-17 19:56:36 -05004763 spin_lock_irq(shost->host_lock);
4764 vport->fc_flag |= FC_RSCN_MODE;
4765 spin_unlock_irq(shost->host_lock);
4766 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004767 /* Indicate we are done walking fc_rscn_id_list on this vport */
4768 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004769 /*
4770 * If we zero, cmdiocb->context2, the calling routine will
4771 * not try to free it.
4772 */
4773 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004774 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004775 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004776 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004777 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004778 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004779 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004780}
4781
James Smarte59058c2008-08-24 21:49:00 -04004782/**
James Smart3621a712009-04-06 18:47:14 -04004783 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004784 * @vport: pointer to a host virtual N_Port data structure.
4785 *
4786 * This routine handles the Registration State Configuration Notification
4787 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4788 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4789 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4790 * NameServer shall be issued. If CT command to the NameServer fails to be
4791 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4792 * RSCN activities with the @vport.
4793 *
4794 * Return code
4795 * 0 - Cleaned up rscn on the @vport
4796 * 1 - Wait for plogi to name server before proceed
4797 **/
dea31012005-04-17 16:05:31 -05004798int
James Smart2e0fef82007-06-17 19:56:36 -05004799lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004800{
4801 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004802 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004803
James Smart92d7f7b2007-06-17 19:56:38 -05004804 /* Ignore RSCN if the port is being torn down. */
4805 if (vport->load_flag & FC_UNLOADING) {
4806 lpfc_els_flush_rscn(vport);
4807 return 0;
4808 }
4809
dea31012005-04-17 16:05:31 -05004810 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004811 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004812
4813 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004814 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4815 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4816 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4817 vport->port_state);
dea31012005-04-17 16:05:31 -05004818
4819 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004820 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004821 vport->num_disc_nodes = 0;
4822
James Smart2e0fef82007-06-17 19:56:36 -05004823 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004824 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4825 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004826 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004827 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004828 /* Wait for NameServer query cmpl before we can
4829 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004830 return 1;
dea31012005-04-17 16:05:31 -05004831 } else {
4832 /* If login to NameServer does not exist, issue one */
4833 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004834 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004835 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004836 /* Wait for NameServer login cmpl before we can
4837 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004838 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004839
James Smarte47c9092008-02-08 18:49:26 -05004840 if (ndlp) {
4841 ndlp = lpfc_enable_node(vport, ndlp,
4842 NLP_STE_PLOGI_ISSUE);
4843 if (!ndlp) {
4844 lpfc_els_flush_rscn(vport);
4845 return 0;
4846 }
4847 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004848 } else {
James Smarte47c9092008-02-08 18:49:26 -05004849 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4850 if (!ndlp) {
4851 lpfc_els_flush_rscn(vport);
4852 return 0;
4853 }
James Smart2e0fef82007-06-17 19:56:36 -05004854 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004855 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004856 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004857 }
James Smarte47c9092008-02-08 18:49:26 -05004858 ndlp->nlp_type |= NLP_FABRIC;
4859 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4860 /* Wait for NameServer login cmpl before we can
4861 * continue
4862 */
4863 return 1;
dea31012005-04-17 16:05:31 -05004864 }
4865
James Smart2e0fef82007-06-17 19:56:36 -05004866 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004867 return 0;
dea31012005-04-17 16:05:31 -05004868}
4869
James Smarte59058c2008-08-24 21:49:00 -04004870/**
James Smart3621a712009-04-06 18:47:14 -04004871 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004872 * @vport: pointer to a host virtual N_Port data structure.
4873 * @cmdiocb: pointer to lpfc command iocb data structure.
4874 * @ndlp: pointer to a node-list data structure.
4875 *
4876 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4877 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4878 * point topology. As an unsolicited FLOGI should not be received in a loop
4879 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4880 * lpfc_check_sparm() routine is invoked to check the parameters in the
4881 * unsolicited FLOGI. If parameters validation failed, the routine
4882 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4883 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4884 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4885 * will initiate PLOGI. The higher lexicographical value party shall has
4886 * higher priority (as the winning port) and will initiate PLOGI and
4887 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4888 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4889 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4890 *
4891 * Return code
4892 * 0 - Successfully processed the unsolicited flogi
4893 * 1 - Failed to process the unsolicited flogi
4894 **/
dea31012005-04-17 16:05:31 -05004895static int
James Smart2e0fef82007-06-17 19:56:36 -05004896lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004897 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004898{
James Smart2e0fef82007-06-17 19:56:36 -05004899 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4900 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004901 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4902 uint32_t *lp = (uint32_t *) pcmd->virt;
4903 IOCB_t *icmd = &cmdiocb->iocb;
4904 struct serv_parm *sp;
4905 LPFC_MBOXQ_t *mbox;
4906 struct ls_rjt stat;
4907 uint32_t cmd, did;
4908 int rc;
4909
4910 cmd = *lp++;
4911 sp = (struct serv_parm *) lp;
4912
4913 /* FLOGI received */
4914
James Smart2e0fef82007-06-17 19:56:36 -05004915 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004916
James Smart76a95d72010-11-20 23:11:48 -05004917 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004918 /* We should never receive a FLOGI in loop mode, ignore it */
4919 did = icmd->un.elsreq64.remoteID;
4920
4921 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4922 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004923 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4924 "0113 An FLOGI ELS command x%x was "
4925 "received from DID x%x in Loop Mode\n",
4926 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004927 return 1;
dea31012005-04-17 16:05:31 -05004928 }
4929
4930 did = Fabric_DID;
4931
James Smart341af102010-01-26 23:07:37 -05004932 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004933 /* For a FLOGI we accept, then if our portname is greater
4934 * then the remote portname we initiate Nport login.
4935 */
4936
James Smart2e0fef82007-06-17 19:56:36 -05004937 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004938 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004939
4940 if (!rc) {
James Smart1b511972011-12-13 13:23:09 -05004941 if (phba->sli_rev < LPFC_SLI_REV4) {
4942 mbox = mempool_alloc(phba->mbox_mem_pool,
4943 GFP_KERNEL);
4944 if (!mbox)
4945 return 1;
4946 lpfc_linkdown(phba);
4947 lpfc_init_link(phba, mbox,
4948 phba->cfg_topology,
4949 phba->cfg_link_speed);
4950 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
4951 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4952 mbox->vport = vport;
4953 rc = lpfc_sli_issue_mbox(phba, mbox,
4954 MBX_NOWAIT);
4955 lpfc_set_loopback_flag(phba);
4956 if (rc == MBX_NOT_FINISHED)
4957 mempool_free(mbox, phba->mbox_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004958 return 1;
James Smart1b511972011-12-13 13:23:09 -05004959 } else {
4960 /* abort the flogi coming back to ourselves
4961 * due to external loopback on the port.
4962 */
4963 lpfc_els_abort_flogi(phba);
4964 return 0;
dea31012005-04-17 16:05:31 -05004965 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004966 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004967 spin_lock_irq(shost->host_lock);
4968 vport->fc_flag |= FC_PT2PT_PLOGI;
4969 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004970 }
James Smart2e0fef82007-06-17 19:56:36 -05004971 spin_lock_irq(shost->host_lock);
4972 vport->fc_flag |= FC_PT2PT;
4973 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4974 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004975 } else {
4976 /* Reject this request because invalid parameters */
4977 stat.un.b.lsRjtRsvd0 = 0;
4978 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4979 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4980 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004981 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4982 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004983 return 1;
dea31012005-04-17 16:05:31 -05004984 }
4985
4986 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004987 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004988
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004989 return 0;
dea31012005-04-17 16:05:31 -05004990}
4991
James Smarte59058c2008-08-24 21:49:00 -04004992/**
James Smart3621a712009-04-06 18:47:14 -04004993 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004994 * @vport: pointer to a host virtual N_Port data structure.
4995 * @cmdiocb: pointer to lpfc command iocb data structure.
4996 * @ndlp: pointer to a node-list data structure.
4997 *
4998 * This routine processes Request Node Identification Data (RNID) IOCB
4999 * received as an ELS unsolicited event. Only when the RNID specified format
5000 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
5001 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
5002 * Accept (ACC) the RNID ELS command. All the other RNID formats are
5003 * rejected by invoking the lpfc_els_rsp_reject() routine.
5004 *
5005 * Return code
5006 * 0 - Successfully processed rnid iocb (currently always return 0)
5007 **/
dea31012005-04-17 16:05:31 -05005008static int
James Smart2e0fef82007-06-17 19:56:36 -05005009lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5010 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005011{
5012 struct lpfc_dmabuf *pcmd;
5013 uint32_t *lp;
5014 IOCB_t *icmd;
5015 RNID *rn;
5016 struct ls_rjt stat;
5017 uint32_t cmd, did;
5018
5019 icmd = &cmdiocb->iocb;
5020 did = icmd->un.elsreq64.remoteID;
5021 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5022 lp = (uint32_t *) pcmd->virt;
5023
5024 cmd = *lp++;
5025 rn = (RNID *) lp;
5026
5027 /* RNID received */
5028
5029 switch (rn->Format) {
5030 case 0:
5031 case RNID_TOPOLOGY_DISC:
5032 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05005033 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005034 break;
5035 default:
5036 /* Reject this request because format not supported */
5037 stat.un.b.lsRjtRsvd0 = 0;
5038 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5039 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5040 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005041 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5042 NULL);
dea31012005-04-17 16:05:31 -05005043 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005044 return 0;
dea31012005-04-17 16:05:31 -05005045}
5046
James Smarte59058c2008-08-24 21:49:00 -04005047/**
James Smart12265f62010-10-22 11:05:53 -04005048 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
5049 * @vport: pointer to a host virtual N_Port data structure.
5050 * @cmdiocb: pointer to lpfc command iocb data structure.
5051 * @ndlp: pointer to a node-list data structure.
5052 *
5053 * Return code
5054 * 0 - Successfully processed echo iocb (currently always return 0)
5055 **/
5056static int
5057lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5058 struct lpfc_nodelist *ndlp)
5059{
5060 uint8_t *pcmd;
5061
5062 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
5063
5064 /* skip over first word of echo command to find echo data */
5065 pcmd += sizeof(uint32_t);
5066
5067 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
5068 return 0;
5069}
5070
5071/**
James Smart3621a712009-04-06 18:47:14 -04005072 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04005073 * @vport: pointer to a host virtual N_Port data structure.
5074 * @cmdiocb: pointer to lpfc command iocb data structure.
5075 * @ndlp: pointer to a node-list data structure.
5076 *
5077 * This routine processes a Link Incident Report Registration(LIRR) IOCB
5078 * received as an ELS unsolicited event. Currently, this function just invokes
5079 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
5080 *
5081 * Return code
5082 * 0 - Successfully processed lirr iocb (currently always return 0)
5083 **/
dea31012005-04-17 16:05:31 -05005084static int
James Smart2e0fef82007-06-17 19:56:36 -05005085lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5086 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005087{
5088 struct ls_rjt stat;
5089
5090 /* For now, unconditionally reject this command */
5091 stat.un.b.lsRjtRsvd0 = 0;
5092 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5093 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5094 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005095 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005096 return 0;
5097}
5098
James Smarte59058c2008-08-24 21:49:00 -04005099/**
James Smart5ffc2662009-11-18 15:39:44 -05005100 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5101 * @vport: pointer to a host virtual N_Port data structure.
5102 * @cmdiocb: pointer to lpfc command iocb data structure.
5103 * @ndlp: pointer to a node-list data structure.
5104 *
5105 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5106 * received as an ELS unsolicited event. A request to RRQ shall only
5107 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5108 * Nx_Port N_Port_ID of the target Exchange is the same as the
5109 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5110 * not accepted, an LS_RJT with reason code "Unable to perform
5111 * command request" and reason code explanation "Invalid Originator
5112 * S_ID" shall be returned. For now, we just unconditionally accept
5113 * RRQ from the target.
5114 **/
5115static void
5116lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5117 struct lpfc_nodelist *ndlp)
5118{
5119 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05005120 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5121 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05005122}
5123
5124/**
James Smart12265f62010-10-22 11:05:53 -04005125 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5126 * @phba: pointer to lpfc hba data structure.
5127 * @pmb: pointer to the driver internal queue element for mailbox command.
5128 *
5129 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5130 * mailbox command. This callback function is to actually send the Accept
5131 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5132 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5133 * mailbox command, constructs the RPS response with the link statistics
5134 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5135 * response to the RPS.
5136 *
5137 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5138 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5139 * will be stored into the context1 field of the IOCB for the completion
5140 * callback function to the RPS Accept Response ELS IOCB command.
5141 *
5142 **/
5143static void
5144lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5145{
5146 MAILBOX_t *mb;
5147 IOCB_t *icmd;
5148 struct RLS_RSP *rls_rsp;
5149 uint8_t *pcmd;
5150 struct lpfc_iocbq *elsiocb;
5151 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005152 uint16_t oxid;
5153 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04005154 uint32_t cmdsize;
5155
5156 mb = &pmb->u.mb;
5157
5158 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005159 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5160 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04005161 pmb->context1 = NULL;
5162 pmb->context2 = NULL;
5163
5164 if (mb->mbxStatus) {
5165 mempool_free(pmb, phba->mbox_mem_pool);
5166 return;
5167 }
5168
5169 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
5170 mempool_free(pmb, phba->mbox_mem_pool);
5171 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5172 lpfc_max_els_tries, ndlp,
5173 ndlp->nlp_DID, ELS_CMD_ACC);
5174
5175 /* Decrement the ndlp reference count from previous mbox command */
5176 lpfc_nlp_put(ndlp);
5177
5178 if (!elsiocb)
5179 return;
5180
5181 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005182 icmd->ulpContext = rxid;
5183 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04005184
5185 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5186 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5187 pcmd += sizeof(uint32_t); /* Skip past command */
5188 rls_rsp = (struct RLS_RSP *)pcmd;
5189
5190 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5191 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5192 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5193 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5194 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5195 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
5196
5197 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5198 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5199 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5200 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5201 elsiocb->iotag, elsiocb->iocb.ulpContext,
5202 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5203 ndlp->nlp_rpi);
5204 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5205 phba->fc_stat.elsXmitACC++;
5206 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5207 lpfc_els_free_iocb(phba, elsiocb);
5208}
5209
5210/**
James Smart3621a712009-04-06 18:47:14 -04005211 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005212 * @phba: pointer to lpfc hba data structure.
5213 * @pmb: pointer to the driver internal queue element for mailbox command.
5214 *
5215 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5216 * mailbox command. This callback function is to actually send the Accept
5217 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5218 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5219 * mailbox command, constructs the RPS response with the link statistics
5220 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5221 * response to the RPS.
5222 *
5223 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5224 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5225 * will be stored into the context1 field of the IOCB for the completion
5226 * callback function to the RPS Accept Response ELS IOCB command.
5227 *
5228 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005229static void
James Smart329f9bc2007-04-25 09:53:01 -04005230lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005231{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005232 MAILBOX_t *mb;
5233 IOCB_t *icmd;
5234 RPS_RSP *rps_rsp;
5235 uint8_t *pcmd;
5236 struct lpfc_iocbq *elsiocb;
5237 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005238 uint16_t status;
5239 uint16_t oxid;
5240 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005241 uint32_t cmdsize;
5242
James Smart04c68492009-05-22 14:52:52 -04005243 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005244
5245 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005246 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5247 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07005248 pmb->context1 = NULL;
5249 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005250
5251 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005252 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005253 return;
5254 }
5255
5256 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005257 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005258 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5259 lpfc_max_els_tries, ndlp,
5260 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005261
5262 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005263 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005264
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005265 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005266 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005267
5268 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005269 icmd->ulpContext = rxid;
5270 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005271
5272 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5273 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005274 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005275 rps_rsp = (RPS_RSP *)pcmd;
5276
James Smart76a95d72010-11-20 23:11:48 -05005277 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005278 status = 0x10;
5279 else
5280 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005281 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005282 status |= 0x4;
5283
5284 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005285 rps_rsp->portStatus = cpu_to_be16(status);
5286 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5287 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5288 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5289 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5290 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5291 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005292 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005293 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5294 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5295 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5296 elsiocb->iotag, elsiocb->iocb.ulpContext,
5297 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5298 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005299 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005300 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005301 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005302 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005303 return;
5304}
5305
James Smarte59058c2008-08-24 21:49:00 -04005306/**
James Smart12265f62010-10-22 11:05:53 -04005307 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5308 * @vport: pointer to a host virtual N_Port data structure.
5309 * @cmdiocb: pointer to lpfc command iocb data structure.
5310 * @ndlp: pointer to a node-list data structure.
5311 *
5312 * This routine processes Read Port Status (RPL) IOCB received as an
5313 * ELS unsolicited event. It first checks the remote port state. If the
5314 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5315 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5316 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5317 * for reading the HBA link statistics. It is for the callback function,
5318 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5319 * to actually sending out RPL Accept (ACC) response.
5320 *
5321 * Return codes
5322 * 0 - Successfully processed rls iocb (currently always return 0)
5323 **/
5324static int
5325lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5326 struct lpfc_nodelist *ndlp)
5327{
5328 struct lpfc_hba *phba = vport->phba;
5329 LPFC_MBOXQ_t *mbox;
5330 struct lpfc_dmabuf *pcmd;
5331 struct ls_rjt stat;
5332
5333 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5334 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5335 /* reject the unsolicited RPS request and done with it */
5336 goto reject_out;
5337
5338 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5339
5340 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5341 if (mbox) {
5342 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005343 mbox->context1 = (void *)((unsigned long)
5344 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5345 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04005346 mbox->context2 = lpfc_nlp_get(ndlp);
5347 mbox->vport = vport;
5348 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5349 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5350 != MBX_NOT_FINISHED)
5351 /* Mbox completion will send ELS Response */
5352 return 0;
5353 /* Decrement reference count used for the failed mbox
5354 * command.
5355 */
5356 lpfc_nlp_put(ndlp);
5357 mempool_free(mbox, phba->mbox_mem_pool);
5358 }
5359reject_out:
5360 /* issue rejection response */
5361 stat.un.b.lsRjtRsvd0 = 0;
5362 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5363 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5364 stat.un.b.vendorUnique = 0;
5365 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5366 return 0;
5367}
5368
5369/**
5370 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5371 * @vport: pointer to a host virtual N_Port data structure.
5372 * @cmdiocb: pointer to lpfc command iocb data structure.
5373 * @ndlp: pointer to a node-list data structure.
5374 *
5375 * This routine processes Read Timout Value (RTV) IOCB received as an
5376 * ELS unsolicited event. It first checks the remote port state. If the
5377 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5378 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5379 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5380 * Value (RTV) unsolicited IOCB event.
5381 *
5382 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5383 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5384 * will be stored into the context1 field of the IOCB for the completion
5385 * callback function to the RPS Accept Response ELS IOCB command.
5386 *
5387 * Return codes
5388 * 0 - Successfully processed rtv iocb (currently always return 0)
5389 **/
5390static int
5391lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5392 struct lpfc_nodelist *ndlp)
5393{
5394 struct lpfc_hba *phba = vport->phba;
5395 struct ls_rjt stat;
5396 struct RTV_RSP *rtv_rsp;
5397 uint8_t *pcmd;
5398 struct lpfc_iocbq *elsiocb;
5399 uint32_t cmdsize;
5400
5401
5402 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5403 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5404 /* reject the unsolicited RPS request and done with it */
5405 goto reject_out;
5406
5407 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5408 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5409 lpfc_max_els_tries, ndlp,
5410 ndlp->nlp_DID, ELS_CMD_ACC);
5411
5412 if (!elsiocb)
5413 return 1;
5414
5415 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5416 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5417 pcmd += sizeof(uint32_t); /* Skip past command */
5418
5419 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04005420 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
5421 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04005422
5423 rtv_rsp = (struct RTV_RSP *)pcmd;
5424
5425 /* populate RTV payload */
5426 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5427 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5428 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5429 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5430 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5431
5432 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5433 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5434 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5435 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5436 "Data: x%x x%x x%x\n",
5437 elsiocb->iotag, elsiocb->iocb.ulpContext,
5438 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5439 ndlp->nlp_rpi,
5440 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5441 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5442 phba->fc_stat.elsXmitACC++;
5443 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5444 lpfc_els_free_iocb(phba, elsiocb);
5445 return 0;
5446
5447reject_out:
5448 /* issue rejection response */
5449 stat.un.b.lsRjtRsvd0 = 0;
5450 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5451 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5452 stat.un.b.vendorUnique = 0;
5453 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5454 return 0;
5455}
5456
5457/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005458 * @vport: pointer to a host virtual N_Port data structure.
5459 * @cmdiocb: pointer to lpfc command iocb data structure.
5460 * @ndlp: pointer to a node-list data structure.
5461 *
5462 * This routine processes Read Port Status (RPS) IOCB received as an
5463 * ELS unsolicited event. It first checks the remote port state. If the
5464 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5465 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5466 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5467 * for reading the HBA link statistics. It is for the callback function,
5468 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5469 * to actually sending out RPS Accept (ACC) response.
5470 *
5471 * Return codes
5472 * 0 - Successfully processed rps iocb (currently always return 0)
5473 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005474static int
James Smart2e0fef82007-06-17 19:56:36 -05005475lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5476 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005477{
James Smart2e0fef82007-06-17 19:56:36 -05005478 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005479 uint32_t *lp;
5480 uint8_t flag;
5481 LPFC_MBOXQ_t *mbox;
5482 struct lpfc_dmabuf *pcmd;
5483 RPS *rps;
5484 struct ls_rjt stat;
5485
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005486 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005487 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5488 /* reject the unsolicited RPS request and done with it */
5489 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005490
5491 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5492 lp = (uint32_t *) pcmd->virt;
5493 flag = (be32_to_cpu(*lp++) & 0xf);
5494 rps = (RPS *) lp;
5495
5496 if ((flag == 0) ||
5497 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005498 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005499 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005500
James Smart92d7f7b2007-06-17 19:56:38 -05005501 printk("Fix me....\n");
5502 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005503 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5504 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005505 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005506 mbox->context1 = (void *)((unsigned long)
5507 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5508 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04005509 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005510 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005511 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005512 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005513 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005514 /* Mbox completion will send ELS Response */
5515 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005516 /* Decrement reference count used for the failed mbox
5517 * command.
5518 */
James Smart329f9bc2007-04-25 09:53:01 -04005519 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005520 mempool_free(mbox, phba->mbox_mem_pool);
5521 }
5522 }
James Smart90160e02008-08-24 21:49:45 -04005523
5524reject_out:
5525 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005526 stat.un.b.lsRjtRsvd0 = 0;
5527 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5528 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5529 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005530 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005531 return 0;
5532}
5533
James Smart19ca7602010-11-20 23:11:55 -05005534/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5535 * @vport: pointer to a host virtual N_Port data structure.
5536 * @ndlp: pointer to a node-list data structure.
5537 * @did: DID of the target.
5538 * @rrq: Pointer to the rrq struct.
5539 *
5540 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5541 * Successful the the completion handler will clear the RRQ.
5542 *
5543 * Return codes
5544 * 0 - Successfully sent rrq els iocb.
5545 * 1 - Failed to send rrq els iocb.
5546 **/
5547static int
5548lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5549 uint32_t did, struct lpfc_node_rrq *rrq)
5550{
5551 struct lpfc_hba *phba = vport->phba;
5552 struct RRQ *els_rrq;
5553 IOCB_t *icmd;
5554 struct lpfc_iocbq *elsiocb;
5555 uint8_t *pcmd;
5556 uint16_t cmdsize;
5557 int ret;
5558
5559
5560 if (ndlp != rrq->ndlp)
5561 ndlp = rrq->ndlp;
5562 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5563 return 1;
5564
5565 /* If ndlp is not NULL, we will bump the reference count on it */
5566 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5567 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5568 ELS_CMD_RRQ);
5569 if (!elsiocb)
5570 return 1;
5571
5572 icmd = &elsiocb->iocb;
5573 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5574
5575 /* For RRQ request, remainder of payload is Exchange IDs */
5576 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5577 pcmd += sizeof(uint32_t);
5578 els_rrq = (struct RRQ *) pcmd;
5579
5580 bf_set(rrq_oxid, els_rrq, rrq->xritag);
5581 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5582 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5583 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5584 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5585
5586
5587 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5588 "Issue RRQ: did:x%x",
5589 did, rrq->xritag, rrq->rxid);
5590 elsiocb->context_un.rrq = rrq;
5591 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5592 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5593
5594 if (ret == IOCB_ERROR) {
5595 lpfc_els_free_iocb(phba, elsiocb);
5596 return 1;
5597 }
5598 return 0;
5599}
5600
5601/**
5602 * lpfc_send_rrq - Sends ELS RRQ if needed.
5603 * @phba: pointer to lpfc hba data structure.
5604 * @rrq: pointer to the active rrq.
5605 *
5606 * This routine will call the lpfc_issue_els_rrq if the rrq is
5607 * still active for the xri. If this function returns a failure then
5608 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5609 *
5610 * Returns 0 Success.
5611 * 1 Failure.
5612 **/
5613int
5614lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5615{
5616 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5617 rrq->nlp_DID);
5618 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5619 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5620 rrq->nlp_DID, rrq);
5621 else
5622 return 1;
5623}
5624
James Smarte59058c2008-08-24 21:49:00 -04005625/**
James Smart3621a712009-04-06 18:47:14 -04005626 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005627 * @vport: pointer to a host virtual N_Port data structure.
5628 * @cmdsize: size of the ELS command.
5629 * @oldiocb: pointer to the original lpfc command iocb data structure.
5630 * @ndlp: pointer to a node-list data structure.
5631 *
5632 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5633 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5634 *
5635 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5636 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5637 * will be stored into the context1 field of the IOCB for the completion
5638 * callback function to the RPL Accept Response ELS command.
5639 *
5640 * Return code
5641 * 0 - Successfully issued ACC RPL ELS command
5642 * 1 - Failed to issue ACC RPL ELS command
5643 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005644static int
James Smart2e0fef82007-06-17 19:56:36 -05005645lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5646 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005647{
James Smart2e0fef82007-06-17 19:56:36 -05005648 struct lpfc_hba *phba = vport->phba;
5649 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005650 RPL_RSP rpl_rsp;
5651 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005652 uint8_t *pcmd;
5653
James Smart2e0fef82007-06-17 19:56:36 -05005654 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5655 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005656
James Smart488d1462006-03-07 15:02:37 -05005657 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005658 return 1;
James Smart488d1462006-03-07 15:02:37 -05005659
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005660 icmd = &elsiocb->iocb;
5661 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005662 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5663 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005664
5665 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5666 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005667 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005668 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5669 pcmd += sizeof(uint16_t);
5670
5671 /* Setup the RPL ACC payload */
5672 rpl_rsp.listLen = be32_to_cpu(1);
5673 rpl_rsp.index = 0;
5674 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005675 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5676 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005677 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005678 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005679 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005680 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5681 "0120 Xmit ELS RPL ACC response tag x%x "
5682 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5683 "rpi x%x\n",
5684 elsiocb->iotag, elsiocb->iocb.ulpContext,
5685 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5686 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005687 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005688 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005689 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5690 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005691 lpfc_els_free_iocb(phba, elsiocb);
5692 return 1;
5693 }
5694 return 0;
5695}
5696
James Smarte59058c2008-08-24 21:49:00 -04005697/**
James Smart3621a712009-04-06 18:47:14 -04005698 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005699 * @vport: pointer to a host virtual N_Port data structure.
5700 * @cmdiocb: pointer to lpfc command iocb data structure.
5701 * @ndlp: pointer to a node-list data structure.
5702 *
5703 * This routine processes Read Port List (RPL) IOCB received as an ELS
5704 * unsolicited event. It first checks the remote port state. If the remote
5705 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5706 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5707 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5708 * to accept the RPL.
5709 *
5710 * Return code
5711 * 0 - Successfully processed rpl iocb (currently always return 0)
5712 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005713static int
James Smart2e0fef82007-06-17 19:56:36 -05005714lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5715 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005716{
5717 struct lpfc_dmabuf *pcmd;
5718 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005719 uint32_t maxsize;
5720 uint16_t cmdsize;
5721 RPL *rpl;
5722 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005723
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005724 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5725 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005726 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005727 stat.un.b.lsRjtRsvd0 = 0;
5728 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5729 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5730 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005731 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5732 NULL);
James Smart90160e02008-08-24 21:49:45 -04005733 /* rejected the unsolicited RPL request and done with it */
5734 return 0;
dea31012005-04-17 16:05:31 -05005735 }
5736
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005737 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5738 lp = (uint32_t *) pcmd->virt;
5739 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005740 maxsize = be32_to_cpu(rpl->maxsize);
5741
5742 /* We support only one port */
5743 if ((rpl->index == 0) &&
5744 ((maxsize == 0) ||
5745 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5746 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005747 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005748 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5749 }
James Smart2e0fef82007-06-17 19:56:36 -05005750 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005751
5752 return 0;
5753}
5754
James Smarte59058c2008-08-24 21:49:00 -04005755/**
James Smart3621a712009-04-06 18:47:14 -04005756 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005757 * @vport: pointer to a virtual N_Port data structure.
5758 * @cmdiocb: pointer to lpfc command iocb data structure.
5759 * @ndlp: pointer to a node-list data structure.
5760 *
5761 * This routine processes Fibre Channel Address Resolution Protocol
5762 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5763 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5764 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5765 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5766 * remote PortName is compared against the FC PortName stored in the @vport
5767 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5768 * compared against the FC NodeName stored in the @vport data structure.
5769 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5770 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5771 * invoked to send out FARP Response to the remote node. Before sending the
5772 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5773 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5774 * routine is invoked to log into the remote port first.
5775 *
5776 * Return code
5777 * 0 - Either the FARP Match Mode not supported or successfully processed
5778 **/
dea31012005-04-17 16:05:31 -05005779static int
James Smart2e0fef82007-06-17 19:56:36 -05005780lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5781 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005782{
5783 struct lpfc_dmabuf *pcmd;
5784 uint32_t *lp;
5785 IOCB_t *icmd;
5786 FARP *fp;
5787 uint32_t cmd, cnt, did;
5788
5789 icmd = &cmdiocb->iocb;
5790 did = icmd->un.elsreq64.remoteID;
5791 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5792 lp = (uint32_t *) pcmd->virt;
5793
5794 cmd = *lp++;
5795 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005796 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005797 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5798 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005799 /* We will only support match on WWPN or WWNN */
5800 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005801 return 0;
dea31012005-04-17 16:05:31 -05005802 }
5803
5804 cnt = 0;
5805 /* If this FARP command is searching for my portname */
5806 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005807 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005808 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005809 cnt = 1;
5810 }
5811
5812 /* If this FARP command is searching for my nodename */
5813 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005814 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005815 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005816 cnt = 1;
5817 }
5818
5819 if (cnt) {
5820 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5821 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5822 /* Log back into the node before sending the FARP. */
5823 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005824 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005825 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005826 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005827 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005828 }
5829
5830 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005831 if (fp->Rflags & FARP_REQUEST_FARPR)
5832 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005833 }
5834 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005835 return 0;
dea31012005-04-17 16:05:31 -05005836}
5837
James Smarte59058c2008-08-24 21:49:00 -04005838/**
James Smart3621a712009-04-06 18:47:14 -04005839 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005840 * @vport: pointer to a host virtual N_Port data structure.
5841 * @cmdiocb: pointer to lpfc command iocb data structure.
5842 * @ndlp: pointer to a node-list data structure.
5843 *
5844 * This routine processes Fibre Channel Address Resolution Protocol
5845 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5846 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5847 * the FARP response request.
5848 *
5849 * Return code
5850 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5851 **/
dea31012005-04-17 16:05:31 -05005852static int
James Smart2e0fef82007-06-17 19:56:36 -05005853lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5854 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005855{
5856 struct lpfc_dmabuf *pcmd;
5857 uint32_t *lp;
5858 IOCB_t *icmd;
5859 uint32_t cmd, did;
5860
5861 icmd = &cmdiocb->iocb;
5862 did = icmd->un.elsreq64.remoteID;
5863 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5864 lp = (uint32_t *) pcmd->virt;
5865
5866 cmd = *lp++;
5867 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005868 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5869 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005870 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005871 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005872
5873 return 0;
5874}
5875
James Smarte59058c2008-08-24 21:49:00 -04005876/**
James Smart3621a712009-04-06 18:47:14 -04005877 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005878 * @vport: pointer to a host virtual N_Port data structure.
5879 * @cmdiocb: pointer to lpfc command iocb data structure.
5880 * @fan_ndlp: pointer to a node-list data structure.
5881 *
5882 * This routine processes a Fabric Address Notification (FAN) IOCB
5883 * command received as an ELS unsolicited event. The FAN ELS command will
5884 * only be processed on a physical port (i.e., the @vport represents the
5885 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5886 * compared against those in the phba data structure. If any of those is
5887 * different, the lpfc_initial_flogi() routine is invoked to initialize
5888 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5889 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5890 * is invoked to register login to the fabric.
5891 *
5892 * Return code
5893 * 0 - Successfully processed fan iocb (currently always return 0).
5894 **/
dea31012005-04-17 16:05:31 -05005895static int
James Smart2e0fef82007-06-17 19:56:36 -05005896lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5897 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005898{
James Smart2e0fef82007-06-17 19:56:36 -05005899 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005900 uint32_t *lp;
5901 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005902
James Smart0d2b6b82008-06-14 22:52:47 -04005903 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5904 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5905 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005906 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005907 if ((vport == phba->pport) &&
5908 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005909 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005910 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005911 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005912 sizeof(struct lpfc_name)))) {
5913 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05005914 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005915 } else {
5916 /* FAN verified - skip FLOGI */
5917 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005918 if (phba->sli_rev < LPFC_SLI_REV4)
5919 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05005920 else {
5921 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5922 "3138 Need register VFI: (x%x/%x)\n",
5923 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04005924 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05005925 }
dea31012005-04-17 16:05:31 -05005926 }
dea31012005-04-17 16:05:31 -05005927 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005928 return 0;
dea31012005-04-17 16:05:31 -05005929}
5930
James Smarte59058c2008-08-24 21:49:00 -04005931/**
James Smart3621a712009-04-06 18:47:14 -04005932 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005933 * @ptr: holder for the timer function associated data.
5934 *
5935 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5936 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5937 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5938 * up the worker thread. It is for the worker thread to invoke the routine
5939 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5940 **/
dea31012005-04-17 16:05:31 -05005941void
5942lpfc_els_timeout(unsigned long ptr)
5943{
James Smart2e0fef82007-06-17 19:56:36 -05005944 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5945 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005946 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005947 unsigned long iflag;
5948
James Smart2e0fef82007-06-17 19:56:36 -05005949 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005950 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5951 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005952 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005953 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005954
James Smart5e9d9b82008-06-14 22:52:53 -04005955 if (!tmo_posted)
5956 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005957 return;
5958}
5959
James Smart2a9bf3d2010-06-07 15:24:45 -04005960
James Smarte59058c2008-08-24 21:49:00 -04005961/**
James Smart3621a712009-04-06 18:47:14 -04005962 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005963 * @vport: pointer to a virtual N_Port data structure.
5964 *
5965 * This routine is the actual handler function that processes an ELS timeout
5966 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5967 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5968 * invoking the lpfc_sli_issue_abort_iotag() routine.
5969 **/
dea31012005-04-17 16:05:31 -05005970void
James Smart2e0fef82007-06-17 19:56:36 -05005971lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005972{
James Smart2e0fef82007-06-17 19:56:36 -05005973 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005974 struct lpfc_sli_ring *pring;
5975 struct lpfc_iocbq *tmp_iocb, *piocb;
5976 IOCB_t *cmd = NULL;
5977 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005978 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005979 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005980 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005981 LIST_HEAD(txcmplq_completions);
5982 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005983
James Smart2a9bf3d2010-06-07 15:24:45 -04005984
dea31012005-04-17 16:05:31 -05005985 timeout = (uint32_t)(phba->fc_ratov << 1);
5986
5987 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005988
James Smart2a9bf3d2010-06-07 15:24:45 -04005989 spin_lock_irq(&phba->hbalock);
5990 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5991 spin_unlock_irq(&phba->hbalock);
5992
5993 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005994 cmd = &piocb->iocb;
5995
James Smart2e0fef82007-06-17 19:56:36 -05005996 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5997 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5998 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005999 continue;
James Smart2e0fef82007-06-17 19:56:36 -05006000
6001 if (piocb->vport != vport)
6002 continue;
6003
dea31012005-04-17 16:05:31 -05006004 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05006005 if (pcmd)
6006 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05006007
James Smart92d7f7b2007-06-17 19:56:38 -05006008 if (els_command == ELS_CMD_FARP ||
6009 els_command == ELS_CMD_FARPR ||
6010 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05006011 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05006012
dea31012005-04-17 16:05:31 -05006013 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05006014 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05006015 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05006016 else
dea31012005-04-17 16:05:31 -05006017 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05006018 continue;
6019 }
6020
James Smart2e0fef82007-06-17 19:56:36 -05006021 remote_ID = 0xffffffff;
6022 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05006023 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05006024 else {
6025 struct lpfc_nodelist *ndlp;
6026 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04006027 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05006028 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05006029 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006030 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05006031 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006032 spin_lock_irq(&phba->hbalock);
6033 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05006034 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04006035
James Smart2a9bf3d2010-06-07 15:24:45 -04006036 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
6037 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6038 "0127 ELS timeout Data: x%x x%x x%x "
6039 "x%x\n", els_command,
6040 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
6041 spin_lock_irq(&phba->hbalock);
6042 list_del_init(&piocb->dlist);
6043 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6044 spin_unlock_irq(&phba->hbalock);
6045 }
6046
James Smart2e0fef82007-06-17 19:56:36 -05006047 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
6048 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05006049}
6050
James Smarte59058c2008-08-24 21:49:00 -04006051/**
James Smart3621a712009-04-06 18:47:14 -04006052 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04006053 * @vport: pointer to a host virtual N_Port data structure.
6054 *
6055 * This routine is used to clean up all the outstanding ELS commands on a
6056 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
6057 * routine. After that, it walks the ELS transmit queue to remove all the
6058 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
6059 * the IOCBs with a non-NULL completion callback function, the callback
6060 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6061 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
6062 * callback function, the IOCB will simply be released. Finally, it walks
6063 * the ELS transmit completion queue to issue an abort IOCB to any transmit
6064 * completion queue IOCB that is associated with the @vport and is not
6065 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
6066 * part of the discovery state machine) out to HBA by invoking the
6067 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
6068 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
6069 * the IOCBs are aborted when this function returns.
6070 **/
dea31012005-04-17 16:05:31 -05006071void
James Smart2e0fef82007-06-17 19:56:36 -05006072lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006073{
James Smart2534ba72007-04-25 09:52:20 -04006074 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05006075 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04006076 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006077 struct lpfc_iocbq *tmp_iocb, *piocb;
6078 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006079
6080 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05006081
James Smart2e0fef82007-06-17 19:56:36 -05006082 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006083 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6084 cmd = &piocb->iocb;
6085
6086 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6087 continue;
6088 }
6089
6090 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04006091 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6092 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6093 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6094 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05006095 continue;
dea31012005-04-17 16:05:31 -05006096
James Smart2e0fef82007-06-17 19:56:36 -05006097 if (piocb->vport != vport)
6098 continue;
6099
James Smart2534ba72007-04-25 09:52:20 -04006100 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04006101 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05006102 }
6103
6104 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05006105 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6106 continue;
6107 }
dea31012005-04-17 16:05:31 -05006108
James Smart2e0fef82007-06-17 19:56:36 -05006109 if (piocb->vport != vport)
6110 continue;
6111
James Smart07951072007-04-25 09:51:38 -04006112 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05006113 }
James Smart2e0fef82007-06-17 19:56:36 -05006114 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04006115
James Smarta257bf92009-04-06 18:48:10 -04006116 /* Cancell all the IOCBs from the completions list */
6117 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6118 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04006119
dea31012005-04-17 16:05:31 -05006120 return;
6121}
6122
James Smarte59058c2008-08-24 21:49:00 -04006123/**
James Smart3621a712009-04-06 18:47:14 -04006124 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04006125 * @phba: pointer to lpfc hba data structure.
6126 *
6127 * This routine is used to clean up all the outstanding ELS commands on a
6128 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6129 * routine. After that, it walks the ELS transmit queue to remove all the
6130 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6131 * the IOCBs with the completion callback function associated, the callback
6132 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6133 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6134 * callback function associated, the IOCB will simply be released. Finally,
6135 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6136 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6137 * management plane IOCBs that are not part of the discovery state machine)
6138 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6139 **/
James Smart549e55c2007-08-02 11:09:51 -04006140void
6141lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6142{
6143 LIST_HEAD(completions);
6144 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6145 struct lpfc_iocbq *tmp_iocb, *piocb;
6146 IOCB_t *cmd = NULL;
6147
6148 lpfc_fabric_abort_hba(phba);
6149 spin_lock_irq(&phba->hbalock);
6150 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6151 cmd = &piocb->iocb;
6152 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6153 continue;
6154 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6155 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6156 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6157 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6158 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6159 continue;
6160 list_move_tail(&piocb->list, &completions);
6161 pring->txq_cnt--;
6162 }
6163 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6164 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6165 continue;
6166 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6167 }
6168 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04006169
6170 /* Cancel all the IOCBs from the completions list */
6171 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6172 IOERR_SLI_ABORTED);
6173
James Smart549e55c2007-08-02 11:09:51 -04006174 return;
6175}
6176
James Smarte59058c2008-08-24 21:49:00 -04006177/**
James Smart3621a712009-04-06 18:47:14 -04006178 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04006179 * @phba: Pointer to hba context object.
6180 * @cmdiocbp: Pointer to command iocb which reported error.
6181 * @rspiocbp: Pointer to response iocb which reported error.
6182 *
6183 * This function sends an event when there is an ELS command
6184 * failure.
6185 **/
6186void
6187lpfc_send_els_failure_event(struct lpfc_hba *phba,
6188 struct lpfc_iocbq *cmdiocbp,
6189 struct lpfc_iocbq *rspiocbp)
6190{
6191 struct lpfc_vport *vport = cmdiocbp->vport;
6192 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6193 struct lpfc_lsrjt_event lsrjt_event;
6194 struct lpfc_fabric_event_header fabric_event;
6195 struct ls_rjt stat;
6196 struct lpfc_nodelist *ndlp;
6197 uint32_t *pcmd;
6198
6199 ndlp = cmdiocbp->context1;
6200 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6201 return;
6202
6203 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6204 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6205 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6206 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6207 sizeof(struct lpfc_name));
6208 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6209 sizeof(struct lpfc_name));
6210 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6211 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006212 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006213 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6214 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6215 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6216 fc_host_post_vendor_event(shost,
6217 fc_get_event_number(),
6218 sizeof(lsrjt_event),
6219 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006220 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006221 return;
6222 }
6223 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6224 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6225 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6226 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6227 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6228 else
6229 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6230 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6231 sizeof(struct lpfc_name));
6232 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6233 sizeof(struct lpfc_name));
6234 fc_host_post_vendor_event(shost,
6235 fc_get_event_number(),
6236 sizeof(fabric_event),
6237 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006238 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006239 return;
6240 }
6241
6242}
6243
6244/**
James Smart3621a712009-04-06 18:47:14 -04006245 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006246 * @vport: Pointer to vport object.
6247 * @ndlp: Pointer FC node object.
6248 * @cmd: ELS command code.
6249 *
6250 * This function posts an event when there is an incoming
6251 * unsolicited ELS command.
6252 **/
6253static void
6254lpfc_send_els_event(struct lpfc_vport *vport,
6255 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006256 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006257{
James Smartddcc50f2008-12-04 22:38:46 -05006258 struct lpfc_els_event_header *els_data = NULL;
6259 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006260 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6261
James Smartddcc50f2008-12-04 22:38:46 -05006262 if (*payload == ELS_CMD_LOGO) {
6263 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6264 if (!logo_data) {
6265 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6266 "0148 Failed to allocate memory "
6267 "for LOGO event\n");
6268 return;
6269 }
6270 els_data = &logo_data->header;
6271 } else {
6272 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6273 GFP_KERNEL);
6274 if (!els_data) {
6275 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6276 "0149 Failed to allocate memory "
6277 "for ELS event\n");
6278 return;
6279 }
6280 }
6281 els_data->event_type = FC_REG_ELS_EVENT;
6282 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006283 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006284 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006285 break;
6286 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006287 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006288 break;
6289 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006290 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6291 break;
6292 case ELS_CMD_LOGO:
6293 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6294 /* Copy the WWPN in the LOGO payload */
6295 memcpy(logo_data->logo_wwpn, &payload[2],
6296 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006297 break;
6298 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006299 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006300 return;
6301 }
James Smartddcc50f2008-12-04 22:38:46 -05006302 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6303 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6304 if (*payload == ELS_CMD_LOGO) {
6305 fc_host_post_vendor_event(shost,
6306 fc_get_event_number(),
6307 sizeof(struct lpfc_logo_event),
6308 (char *)logo_data,
6309 LPFC_NL_VENDOR_ID);
6310 kfree(logo_data);
6311 } else {
6312 fc_host_post_vendor_event(shost,
6313 fc_get_event_number(),
6314 sizeof(struct lpfc_els_event_header),
6315 (char *)els_data,
6316 LPFC_NL_VENDOR_ID);
6317 kfree(els_data);
6318 }
James Smartea2151b2008-09-07 11:52:10 -04006319
6320 return;
6321}
6322
6323
6324/**
James Smart3621a712009-04-06 18:47:14 -04006325 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006326 * @phba: pointer to lpfc hba data structure.
6327 * @pring: pointer to a SLI ring.
6328 * @vport: pointer to a host virtual N_Port data structure.
6329 * @elsiocb: pointer to lpfc els command iocb data structure.
6330 *
6331 * This routine is used for processing the IOCB associated with a unsolicited
6332 * event. It first determines whether there is an existing ndlp that matches
6333 * the DID from the unsolicited IOCB. If not, it will create a new one with
6334 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6335 * IOCB is then used to invoke the proper routine and to set up proper state
6336 * of the discovery state machine.
6337 **/
James Smarted957682007-06-17 19:56:37 -05006338static void
6339lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006340 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006341{
James Smart87af33f2007-10-27 13:37:43 -04006342 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006343 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006344 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006345 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05006346 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006347 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006348
James Smarte47c9092008-02-08 18:49:26 -05006349 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006350 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006351
dea31012005-04-17 16:05:31 -05006352 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006353 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6354 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006355 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006356 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006357
James Smart858c9f62007-06-17 19:56:39 -05006358 did = icmd->un.rcvels.remoteID;
6359 if (icmd->ulpStatus) {
6360 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6361 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6362 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006363 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006364 }
dea31012005-04-17 16:05:31 -05006365
6366 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006367 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006368 goto dropit;
dea31012005-04-17 16:05:31 -05006369
James Smartc8685952009-11-18 15:39:16 -05006370 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006371 if (vport->load_flag & FC_UNLOADING)
6372 goto dropit;
6373
James Smart92494142011-02-16 12:39:44 -05006374 /* If NPort discovery is delayed drop incoming ELS */
6375 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6376 (cmd != ELS_CMD_PLOGI))
6377 goto dropit;
6378
James Smart2e0fef82007-06-17 19:56:36 -05006379 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006380 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006381 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006382 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006383 if (!ndlp)
dea31012005-04-17 16:05:31 -05006384 goto dropit;
dea31012005-04-17 16:05:31 -05006385
James Smart2e0fef82007-06-17 19:56:36 -05006386 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006387 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006388 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006389 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006390 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006391 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6392 ndlp = lpfc_enable_node(vport, ndlp,
6393 NLP_STE_UNUSED_NODE);
6394 if (!ndlp)
6395 goto dropit;
6396 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6397 newnode = 1;
6398 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6399 ndlp->nlp_type |= NLP_FABRIC;
6400 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6401 /* This is similar to the new node path */
6402 ndlp = lpfc_nlp_get(ndlp);
6403 if (!ndlp)
6404 goto dropit;
6405 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6406 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006407 }
dea31012005-04-17 16:05:31 -05006408
6409 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006410
James Smart329f9bc2007-04-25 09:53:01 -04006411 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006412 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006413
6414 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6415 cmd &= ELS_CMD_MASK;
6416 }
6417 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006418 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6419 "0112 ELS command x%x received from NPORT x%x "
6420 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006421 switch (cmd) {
6422 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006423 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6424 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6425 did, vport->port_state, ndlp->nlp_flag);
6426
dea31012005-04-17 16:05:31 -05006427 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006428 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6429
James Smartddcc50f2008-12-04 22:38:46 -05006430 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05006431
6432 /* If Nport discovery is delayed, reject PLOGIs */
6433 if (vport->fc_flag & FC_DISC_DELAYED) {
6434 rjt_err = LSRJT_UNABLE_TPC;
6435 break;
6436 }
James Smart858c9f62007-06-17 19:56:39 -05006437 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006438 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6439 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6440 rjt_err = LSRJT_UNABLE_TPC;
6441 break;
6442 }
6443 /* We get here, and drop thru, if we are PT2PT with
6444 * another NPort and the other side has initiated
6445 * the PLOGI before responding to our FLOGI.
6446 */
dea31012005-04-17 16:05:31 -05006447 }
James Smart87af33f2007-10-27 13:37:43 -04006448
6449 shost = lpfc_shost_from_vport(vport);
6450 spin_lock_irq(shost->host_lock);
6451 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6452 spin_unlock_irq(shost->host_lock);
6453
James Smart2e0fef82007-06-17 19:56:36 -05006454 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6455 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006456
dea31012005-04-17 16:05:31 -05006457 break;
6458 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006459 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6460 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6461 did, vport->port_state, ndlp->nlp_flag);
6462
dea31012005-04-17 16:05:31 -05006463 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006464 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006465 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006466 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006467 break;
6468 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006469 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6470 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6471 did, vport->port_state, ndlp->nlp_flag);
6472
dea31012005-04-17 16:05:31 -05006473 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006474 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006475 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006476 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006477 break;
6478 }
James Smart2e0fef82007-06-17 19:56:36 -05006479 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006480 break;
6481 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006482 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6483 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6484 did, vport->port_state, ndlp->nlp_flag);
6485
dea31012005-04-17 16:05:31 -05006486 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006487 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006488 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006489 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006490 break;
6491 }
James Smart2e0fef82007-06-17 19:56:36 -05006492 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006493 break;
6494 case ELS_CMD_RSCN:
6495 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006496 lpfc_els_rcv_rscn(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_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006501 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6502 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6503 did, vport->port_state, ndlp->nlp_flag);
6504
James Smartddcc50f2008-12-04 22:38:46 -05006505 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006506 phba->fc_stat.elsRcvADISC++;
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,
6512 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006513 break;
6514 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006515 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6516 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6517 did, vport->port_state, ndlp->nlp_flag);
6518
dea31012005-04-17 16:05:31 -05006519 phba->fc_stat.elsRcvPDISC++;
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,
6525 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006526 break;
6527 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006528 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6529 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6530 did, vport->port_state, ndlp->nlp_flag);
6531
dea31012005-04-17 16:05:31 -05006532 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006533 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006534 break;
6535 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006536 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6537 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6538 did, vport->port_state, ndlp->nlp_flag);
6539
dea31012005-04-17 16:05:31 -05006540 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006541 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006542 break;
6543 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006544 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6545 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6546 did, vport->port_state, ndlp->nlp_flag);
6547
dea31012005-04-17 16:05:31 -05006548 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006549 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006550 break;
dea31012005-04-17 16:05:31 -05006551 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006552 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6553 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6554 did, vport->port_state, ndlp->nlp_flag);
6555
dea31012005-04-17 16:05:31 -05006556 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006557 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006558 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006559 break;
6560 }
James Smart2e0fef82007-06-17 19:56:36 -05006561 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006562 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006563 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006564 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6565 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6566 did, vport->port_state, ndlp->nlp_flag);
6567
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006568 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006569 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006570 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006571 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006572 break;
James Smart12265f62010-10-22 11:05:53 -04006573 case ELS_CMD_RLS:
6574 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6575 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6576 did, vport->port_state, ndlp->nlp_flag);
6577
6578 phba->fc_stat.elsRcvRLS++;
6579 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6580 if (newnode)
6581 lpfc_nlp_put(ndlp);
6582 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006583 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006584 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6585 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6586 did, vport->port_state, ndlp->nlp_flag);
6587
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006588 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006589 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006590 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006591 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006592 break;
6593 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006594 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6595 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6596 did, vport->port_state, ndlp->nlp_flag);
6597
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006598 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006599 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006600 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006601 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006602 break;
dea31012005-04-17 16:05:31 -05006603 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006604 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6605 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6606 did, vport->port_state, ndlp->nlp_flag);
6607
dea31012005-04-17 16:05:31 -05006608 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006609 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006610 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006611 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006612 break;
James Smart12265f62010-10-22 11:05:53 -04006613 case ELS_CMD_RTV:
6614 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6615 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6616 did, vport->port_state, ndlp->nlp_flag);
6617 phba->fc_stat.elsRcvRTV++;
6618 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6619 if (newnode)
6620 lpfc_nlp_put(ndlp);
6621 break;
James Smart5ffc2662009-11-18 15:39:44 -05006622 case ELS_CMD_RRQ:
6623 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6624 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6625 did, vport->port_state, ndlp->nlp_flag);
6626
6627 phba->fc_stat.elsRcvRRQ++;
6628 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6629 if (newnode)
6630 lpfc_nlp_put(ndlp);
6631 break;
James Smart12265f62010-10-22 11:05:53 -04006632 case ELS_CMD_ECHO:
6633 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6634 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6635 did, vport->port_state, ndlp->nlp_flag);
6636
6637 phba->fc_stat.elsRcvECHO++;
6638 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6639 if (newnode)
6640 lpfc_nlp_put(ndlp);
6641 break;
dea31012005-04-17 16:05:31 -05006642 default:
James Smart858c9f62007-06-17 19:56:39 -05006643 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6644 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6645 cmd, did, vport->port_state);
6646
dea31012005-04-17 16:05:31 -05006647 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006648 rjt_err = LSRJT_CMD_UNSUPPORTED;
dea31012005-04-17 16:05:31 -05006649
6650 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006651 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6652 "0115 Unknown ELS command x%x "
6653 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006654 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006655 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006656 break;
6657 }
6658
6659 /* check if need to LS_RJT received ELS cmd */
6660 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006661 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006662 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006663 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006664 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6665 NULL);
dea31012005-04-17 16:05:31 -05006666 }
6667
James Smartd7c255b2008-08-24 21:50:00 -04006668 lpfc_nlp_put(elsiocb->context1);
6669 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006670 return;
6671
6672dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006673 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006674 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6675 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006676 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006677 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006678 phba->fc_stat.elsRcvDrop++;
6679}
6680
James Smarte59058c2008-08-24 21:49:00 -04006681/**
James Smart3621a712009-04-06 18:47:14 -04006682 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006683 * @phba: pointer to lpfc hba data structure.
6684 * @pring: pointer to a SLI ring.
6685 * @elsiocb: pointer to lpfc els iocb data structure.
6686 *
6687 * This routine is used to process an unsolicited event received from a SLI
6688 * (Service Level Interface) ring. The actual processing of the data buffer
6689 * associated with the unsolicited event is done by invoking the routine
6690 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6691 * SLI ring on which the unsolicited event was received.
6692 **/
James Smarted957682007-06-17 19:56:37 -05006693void
6694lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6695 struct lpfc_iocbq *elsiocb)
6696{
6697 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006698 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006699 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006700 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6701 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006702
James Smartd7c255b2008-08-24 21:50:00 -04006703 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006704 elsiocb->context2 = NULL;
6705 elsiocb->context3 = NULL;
6706
6707 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6708 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6709 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6710 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006711 phba->fc_stat.NoRcvBuf++;
6712 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006713 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006714 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006715 return;
6716 }
6717
James Smart92d7f7b2007-06-17 19:56:38 -05006718 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6719 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6720 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6721 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6722 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006723 else
6724 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04006725 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05006726 }
James Smart6d368e52011-05-24 11:44:12 -04006727
James Smart7f5f3d02008-02-08 18:50:14 -05006728 /* If there are no BDEs associated
6729 * with this IOCB, there is nothing to do.
6730 */
James Smarted957682007-06-17 19:56:37 -05006731 if (icmd->ulpBdeCount == 0)
6732 return;
6733
James Smart7f5f3d02008-02-08 18:50:14 -05006734 /* type of ELS cmd is first 32bit word
6735 * in packet
6736 */
James Smarted957682007-06-17 19:56:37 -05006737 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006738 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006739 } else {
6740 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6741 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006742 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6743 paddr);
James Smarted957682007-06-17 19:56:37 -05006744 }
6745
James Smart92d7f7b2007-06-17 19:56:38 -05006746 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6747 /*
6748 * The different unsolicited event handlers would tell us
6749 * if they are done with "mp" by setting context2 to NULL.
6750 */
dea31012005-04-17 16:05:31 -05006751 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006752 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6753 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006754 }
James Smarted957682007-06-17 19:56:37 -05006755
6756 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006757 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006758 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006759 elsiocb->context2 = bdeBuf2;
6760 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006761 /* free mp if we are done with it */
6762 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006763 lpfc_in_buf_free(phba, elsiocb->context2);
6764 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006765 }
dea31012005-04-17 16:05:31 -05006766 }
dea31012005-04-17 16:05:31 -05006767}
James Smart92d7f7b2007-06-17 19:56:38 -05006768
James Smarte59058c2008-08-24 21:49:00 -04006769/**
James Smart3621a712009-04-06 18:47:14 -04006770 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006771 * @phba: pointer to lpfc hba data structure.
6772 * @vport: pointer to a virtual N_Port data structure.
6773 *
6774 * This routine issues a Port Login (PLOGI) to the Name Server with
6775 * State Change Request (SCR) for a @vport. This routine will create an
6776 * ndlp for the Name Server associated to the @vport if such node does
6777 * not already exist. The PLOGI to Name Server is issued by invoking the
6778 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6779 * (FDMI) is configured to the @vport, a FDMI node will be created and
6780 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6781 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006782void
6783lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6784{
6785 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05006786 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6787
6788 /*
6789 * If lpfc_delay_discovery parameter is set and the clean address
6790 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6791 * discovery.
6792 */
6793 spin_lock_irq(shost->host_lock);
6794 if (vport->fc_flag & FC_DISC_DELAYED) {
6795 spin_unlock_irq(shost->host_lock);
6796 mod_timer(&vport->delayed_disc_tmo,
6797 jiffies + HZ * phba->fc_ratov);
6798 return;
6799 }
6800 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006801
6802 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6803 if (!ndlp) {
6804 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6805 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006806 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05006807 lpfc_disc_start(vport);
6808 return;
6809 }
6810 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006811 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6812 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006813 return;
6814 }
6815 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006816 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6817 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6818 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006819 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05006820 lpfc_disc_start(vport);
6821 return;
6822 }
6823 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6824 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6825 "0348 NameServer login: node freed\n");
6826 return;
6827 }
James Smart92d7f7b2007-06-17 19:56:38 -05006828 }
James Smart58da1ff2008-04-07 10:15:56 -04006829 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006830
6831 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6832
6833 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6834 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006835 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6836 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006837 return;
6838 }
6839
James Smart3de2a652007-08-02 11:09:59 -04006840 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05006841 /* If this is the first time, allocate an ndlp and initialize
6842 * it. Otherwise, make sure the node is enabled and then do the
6843 * login.
6844 */
6845 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
6846 if (!ndlp_fdmi) {
6847 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6848 GFP_KERNEL);
6849 if (ndlp_fdmi) {
6850 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6851 ndlp_fdmi->nlp_type |= NLP_FABRIC;
6852 } else
6853 return;
6854 }
6855 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
6856 ndlp_fdmi = lpfc_enable_node(vport,
6857 ndlp_fdmi,
6858 NLP_STE_NPR_NODE);
6859
James Smart92d7f7b2007-06-17 19:56:38 -05006860 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04006861 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05006862 NLP_STE_PLOGI_ISSUE);
6863 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006864 }
6865 }
James Smart92d7f7b2007-06-17 19:56:38 -05006866}
6867
James Smarte59058c2008-08-24 21:49:00 -04006868/**
James Smart3621a712009-04-06 18:47:14 -04006869 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006870 * @phba: pointer to lpfc hba data structure.
6871 * @pmb: pointer to the driver internal queue element for mailbox command.
6872 *
6873 * This routine is the completion callback function to register new vport
6874 * mailbox command. If the new vport mailbox command completes successfully,
6875 * the fabric registration login shall be performed on physical port (the
6876 * new vport created is actually a physical port, with VPI 0) or the port
6877 * login to Name Server for State Change Request (SCR) will be performed
6878 * on virtual port (real virtual port, with VPI greater than 0).
6879 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006880static void
6881lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6882{
6883 struct lpfc_vport *vport = pmb->vport;
6884 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6885 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006886 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006887 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006888
James Smart09372822008-01-11 01:52:54 -05006889 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006890 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006891 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006892
6893 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006894 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006895 "0915 Register VPI failed : Status: x%x"
6896 " upd bit: x%x \n", mb->mbxStatus,
6897 mb->un.varRegVpi.upd);
6898 if (phba->sli_rev == LPFC_SLI_REV4 &&
6899 mb->un.varRegVpi.upd)
6900 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006901
6902 switch (mb->mbxStatus) {
6903 case 0x11: /* unsupported feature */
6904 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006905 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006906 /* giving up on vport registration */
6907 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6908 spin_lock_irq(shost->host_lock);
6909 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6910 spin_unlock_irq(shost->host_lock);
6911 lpfc_can_disctmo(vport);
6912 break;
James Smart695a8142010-01-26 23:08:03 -05006913 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6914 case 0x20:
6915 spin_lock_irq(shost->host_lock);
6916 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6917 spin_unlock_irq(shost->host_lock);
6918 lpfc_init_vpi(phba, pmb, vport->vpi);
6919 pmb->vport = vport;
6920 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6921 rc = lpfc_sli_issue_mbox(phba, pmb,
6922 MBX_NOWAIT);
6923 if (rc == MBX_NOT_FINISHED) {
6924 lpfc_printf_vlog(vport,
6925 KERN_ERR, LOG_MBOX,
6926 "2732 Failed to issue INIT_VPI"
6927 " mailbox command\n");
6928 } else {
6929 lpfc_nlp_put(ndlp);
6930 return;
6931 }
6932
James Smart92d7f7b2007-06-17 19:56:38 -05006933 default:
6934 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04006935 if (phba->sli_rev == LPFC_SLI_REV4)
6936 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006937 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006938 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006939 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006940 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006941 if (vport->port_type == LPFC_PHYSICAL_PORT
6942 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05006943 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05006944 else
6945 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006946 break;
6947 }
James Smart92d7f7b2007-06-17 19:56:38 -05006948 } else {
James Smart695a8142010-01-26 23:08:03 -05006949 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006950 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006951 spin_unlock_irq(shost->host_lock);
6952 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006953 if (phba->sli_rev < LPFC_SLI_REV4)
6954 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006955 else {
James Smartfc2b9892010-02-26 14:15:29 -05006956 /*
6957 * If the physical port is instantiated using
6958 * FDISC, do not start vport discovery.
6959 */
6960 if (vport->port_state != LPFC_FDISC)
6961 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006962 lpfc_do_scr_ns_plogi(phba, vport);
6963 }
6964 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006965 lpfc_do_scr_ns_plogi(phba, vport);
6966 }
James Smart38b92ef2010-08-04 16:11:39 -04006967mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05006968 /* Now, we decrement the ndlp reference count held for this
6969 * callback function
6970 */
6971 lpfc_nlp_put(ndlp);
6972
James Smart92d7f7b2007-06-17 19:56:38 -05006973 mempool_free(pmb, phba->mbox_mem_pool);
6974 return;
6975}
6976
James Smarte59058c2008-08-24 21:49:00 -04006977/**
James Smart3621a712009-04-06 18:47:14 -04006978 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006979 * @phba: pointer to lpfc hba data structure.
6980 * @vport: pointer to a host virtual N_Port data structure.
6981 * @ndlp: pointer to a node-list data structure.
6982 *
6983 * This routine registers the @vport as a new virtual port with a HBA.
6984 * It is done through a registering vpi mailbox command.
6985 **/
James Smart695a8142010-01-26 23:08:03 -05006986void
James Smart92d7f7b2007-06-17 19:56:38 -05006987lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6988 struct lpfc_nodelist *ndlp)
6989{
James Smart09372822008-01-11 01:52:54 -05006990 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006991 LPFC_MBOXQ_t *mbox;
6992
6993 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6994 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006995 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006996 mbox->vport = vport;
6997 mbox->context2 = lpfc_nlp_get(ndlp);
6998 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006999 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05007000 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05007001 /* mailbox command not success, decrement ndlp
7002 * reference count for this command
7003 */
7004 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007005 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05007006
James Smarte8b62012007-08-02 11:10:09 -04007007 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7008 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05007009 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007010 }
7011 } else {
James Smarte8b62012007-08-02 11:10:09 -04007012 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7013 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05007014 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007015 }
James Smartfa4066b2008-01-11 01:53:27 -05007016 return;
7017
7018mbox_err_exit:
7019 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7020 spin_lock_irq(shost->host_lock);
7021 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
7022 spin_unlock_irq(shost->host_lock);
7023 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007024}
7025
James Smarte59058c2008-08-24 21:49:00 -04007026/**
James Smart0c9ab6f2010-02-26 14:15:57 -05007027 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05007028 * @phba: pointer to lpfc hba data structure.
7029 *
James Smart0c9ab6f2010-02-26 14:15:57 -05007030 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05007031 **/
7032void
James Smart0c9ab6f2010-02-26 14:15:57 -05007033lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05007034{
7035 struct lpfc_vport **vports;
7036 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05007037 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05007038 int i;
James Smart695a8142010-01-26 23:08:03 -05007039
7040 /* Treat this failure as linkdown for all vports */
7041 link_state = phba->link_state;
7042 lpfc_linkdown(phba);
7043 phba->link_state = link_state;
7044
7045 vports = lpfc_create_vport_work_array(phba);
7046
7047 if (vports) {
7048 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
7049 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
7050 if (ndlp)
7051 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
7052 lpfc_els_flush_cmd(vports[i]);
7053 }
7054 lpfc_destroy_vport_work_array(phba, vports);
7055 }
James Smart0c9ab6f2010-02-26 14:15:57 -05007056}
7057
7058/**
7059 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7060 * @phba: pointer to lpfc hba data structure.
7061 *
7062 * This routine abort all pending discovery commands and
7063 * start a timer to retry FLOGI for the physical port
7064 * discovery.
7065 **/
7066void
7067lpfc_retry_pport_discovery(struct lpfc_hba *phba)
7068{
7069 struct lpfc_nodelist *ndlp;
7070 struct Scsi_Host *shost;
7071
7072 /* Cancel the all vports retry delay retry timers */
7073 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05007074
7075 /* If fabric require FLOGI, then re-instantiate physical login */
7076 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
7077 if (!ndlp)
7078 return;
7079
James Smart695a8142010-01-26 23:08:03 -05007080 shost = lpfc_shost_from_vport(phba->pport);
7081 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
7082 spin_lock_irq(shost->host_lock);
7083 ndlp->nlp_flag |= NLP_DELAY_TMO;
7084 spin_unlock_irq(shost->host_lock);
7085 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7086 phba->pport->port_state = LPFC_FLOGI;
7087 return;
7088}
7089
7090/**
7091 * lpfc_fabric_login_reqd - Check if FLOGI required.
7092 * @phba: pointer to lpfc hba data structure.
7093 * @cmdiocb: pointer to FDISC command iocb.
7094 * @rspiocb: pointer to FDISC response iocb.
7095 *
7096 * This routine checks if a FLOGI is reguired for FDISC
7097 * to succeed.
7098 **/
7099static int
7100lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7101 struct lpfc_iocbq *cmdiocb,
7102 struct lpfc_iocbq *rspiocb)
7103{
7104
7105 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7106 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7107 return 0;
7108 else
7109 return 1;
7110}
7111
7112/**
James Smart3621a712009-04-06 18:47:14 -04007113 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007114 * @phba: pointer to lpfc hba data structure.
7115 * @cmdiocb: pointer to lpfc command iocb data structure.
7116 * @rspiocb: pointer to lpfc response iocb data structure.
7117 *
7118 * This routine is the completion callback function to a Fabric Discover
7119 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7120 * single threaded, each FDISC completion callback function will reset
7121 * the discovery timer for all vports such that the timers will not get
7122 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7123 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7124 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7125 * assigned to the vport has been changed with the completion of the FDISC
7126 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7127 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7128 * routine is invoked to register new vport with the HBA. Otherwise, the
7129 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7130 * Server for State Change Request (SCR).
7131 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007132static void
7133lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7134 struct lpfc_iocbq *rspiocb)
7135{
7136 struct lpfc_vport *vport = cmdiocb->vport;
7137 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7138 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7139 struct lpfc_nodelist *np;
7140 struct lpfc_nodelist *next_np;
7141 IOCB_t *irsp = &rspiocb->iocb;
7142 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05007143 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7144 struct serv_parm *sp;
7145 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05007146
James Smarte8b62012007-08-02 11:10:09 -04007147 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7148 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7149 irsp->ulpStatus, irsp->un.ulpWord[4],
7150 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05007151 /* Since all FDISCs are being single threaded, we
7152 * must reset the discovery timer for ALL vports
7153 * waiting to send FDISC when one completes.
7154 */
7155 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7156 lpfc_set_disctmo(piocb->vport);
7157 }
7158
James Smart858c9f62007-06-17 19:56:39 -05007159 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7160 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7161 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7162
James Smart92d7f7b2007-06-17 19:56:38 -05007163 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05007164
7165 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7166 lpfc_retry_pport_discovery(phba);
7167 goto out;
7168 }
7169
James Smart92d7f7b2007-06-17 19:56:38 -05007170 /* Check for retry */
7171 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7172 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007173 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04007174 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart6b5151f2012-01-18 16:24:06 -05007175 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04007176 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04007177 goto fdisc_failed;
7178 }
James Smartd7c255b2008-08-24 21:50:00 -04007179 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05007180 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04007181 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04007182 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05007183 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04007184 vport->fc_flag |= FC_PUBLIC_LOOP;
7185 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007186
James Smartd7c255b2008-08-24 21:50:00 -04007187 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7188 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05007189 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7190 sp = prsp->virt + sizeof(uint32_t);
7191 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7192 memcpy(&vport->fabric_portname, &sp->portName,
7193 sizeof(struct lpfc_name));
7194 memcpy(&vport->fabric_nodename, &sp->nodeName,
7195 sizeof(struct lpfc_name));
7196 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04007197 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7198 /* If our NportID changed, we need to ensure all
7199 * remaining NPORTs get unreg_login'ed so we can
7200 * issue unreg_vpi.
7201 */
7202 list_for_each_entry_safe(np, next_np,
7203 &vport->fc_nodes, nlp_listp) {
7204 if (!NLP_CHK_NODE_ACT(ndlp) ||
7205 (np->nlp_state != NLP_STE_NPR_NODE) ||
7206 !(np->nlp_flag & NLP_NPR_ADISC))
7207 continue;
James Smart09372822008-01-11 01:52:54 -05007208 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007209 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007210 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007211 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007212 }
James Smart78730cf2010-04-06 15:06:30 -04007213 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007214
7215 if (phba->sli_rev == LPFC_SLI_REV4)
7216 lpfc_sli4_unreg_all_rpis(vport);
7217
James Smartd7c255b2008-08-24 21:50:00 -04007218 lpfc_mbx_unreg_vpi(vport);
7219 spin_lock_irq(shost->host_lock);
7220 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007221 if (phba->sli_rev == LPFC_SLI_REV4)
7222 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007223 else
7224 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007225 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007226 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7227 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7228 /*
7229 * Driver needs to re-reg VPI in order for f/w
7230 * to update the MAC address.
7231 */
7232 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007233 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007234 }
7235
James Smartecfd03c2010-02-12 14:41:27 -05007236 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7237 lpfc_issue_init_vpi(vport);
7238 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007239 lpfc_register_new_vport(phba, vport, ndlp);
7240 else
7241 lpfc_do_scr_ns_plogi(phba, vport);
7242 goto out;
7243fdisc_failed:
7244 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7245 /* Cancel discovery timer */
7246 lpfc_can_disctmo(vport);
7247 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007248out:
7249 lpfc_els_free_iocb(phba, cmdiocb);
7250}
7251
James Smarte59058c2008-08-24 21:49:00 -04007252/**
James Smart3621a712009-04-06 18:47:14 -04007253 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007254 * @vport: pointer to a virtual N_Port data structure.
7255 * @ndlp: pointer to a node-list data structure.
7256 * @retry: number of retries to the command IOCB.
7257 *
7258 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7259 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7260 * routine to issue the IOCB, which makes sure only one outstanding fabric
7261 * IOCB will be sent off HBA at any given time.
7262 *
7263 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7264 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7265 * will be stored into the context1 field of the IOCB for the completion
7266 * callback function to the FDISC ELS command.
7267 *
7268 * Return code
7269 * 0 - Successfully issued fdisc iocb command
7270 * 1 - Failed to issue fdisc iocb command
7271 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007272static int
James Smart92d7f7b2007-06-17 19:56:38 -05007273lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7274 uint8_t retry)
7275{
7276 struct lpfc_hba *phba = vport->phba;
7277 IOCB_t *icmd;
7278 struct lpfc_iocbq *elsiocb;
7279 struct serv_parm *sp;
7280 uint8_t *pcmd;
7281 uint16_t cmdsize;
7282 int did = ndlp->nlp_DID;
7283 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007284
James Smart5ffc2662009-11-18 15:39:44 -05007285 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05007286 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007287 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7288 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7289 ELS_CMD_FDISC);
7290 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007291 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007292 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7293 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007294 return 1;
7295 }
7296
7297 icmd = &elsiocb->iocb;
7298 icmd->un.elsreq64.myID = 0;
7299 icmd->un.elsreq64.fl = 1;
7300
James Smart73d91e52011-10-10 21:32:10 -04007301 /*
7302 * SLI3 ports require a different context type value than SLI4.
7303 * Catch SLI3 ports here and override the prep.
7304 */
7305 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04007306 icmd->ulpCt_h = 1;
7307 icmd->ulpCt_l = 0;
7308 }
James Smart92d7f7b2007-06-17 19:56:38 -05007309
7310 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7311 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7312 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7313 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7314 sp = (struct serv_parm *) pcmd;
7315 /* Setup CSPs accordingly for Fabric */
7316 sp->cmn.e_d_tov = 0;
7317 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05007318 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007319 sp->cls1.classValid = 0;
7320 sp->cls2.seqDelivery = 1;
7321 sp->cls3.seqDelivery = 1;
7322
7323 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7324 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7325 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7326 pcmd += sizeof(uint32_t); /* Port Name */
7327 memcpy(pcmd, &vport->fc_portname, 8);
7328 pcmd += sizeof(uint32_t); /* Node Name */
7329 pcmd += sizeof(uint32_t); /* Node Name */
7330 memcpy(pcmd, &vport->fc_nodename, 8);
7331
7332 lpfc_set_disctmo(vport);
7333
7334 phba->fc_stat.elsXmitFDISC++;
7335 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7336
James Smart858c9f62007-06-17 19:56:39 -05007337 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7338 "Issue FDISC: did:x%x",
7339 did, 0, 0);
7340
James Smart92d7f7b2007-06-17 19:56:38 -05007341 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7342 if (rc == IOCB_ERROR) {
7343 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007344 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007345 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7346 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007347 return 1;
7348 }
7349 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007350 return 0;
7351}
7352
James Smarte59058c2008-08-24 21:49:00 -04007353/**
James Smart3621a712009-04-06 18:47:14 -04007354 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007355 * @phba: pointer to lpfc hba data structure.
7356 * @cmdiocb: pointer to lpfc command iocb data structure.
7357 * @rspiocb: pointer to lpfc response iocb data structure.
7358 *
7359 * This routine is the completion callback function to the issuing of a LOGO
7360 * ELS command off a vport. It frees the command IOCB and then decrement the
7361 * reference count held on ndlp for this completion function, indicating that
7362 * the reference to the ndlp is no long needed. Note that the
7363 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7364 * callback function and an additional explicit ndlp reference decrementation
7365 * will trigger the actual release of the ndlp.
7366 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007367static void
7368lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7369 struct lpfc_iocbq *rspiocb)
7370{
7371 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007372 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007373 struct lpfc_nodelist *ndlp;
James Smart9589b0622011-04-16 11:03:17 -04007374 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05007375
James Smart9589b0622011-04-16 11:03:17 -04007376 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007377 irsp = &rspiocb->iocb;
7378 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7379 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7380 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007381
7382 lpfc_els_free_iocb(phba, cmdiocb);
7383 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007384
7385 /* Trigger the release of the ndlp after logo */
7386 lpfc_nlp_put(ndlp);
James Smart9589b0622011-04-16 11:03:17 -04007387
7388 /* NPIV LOGO completes to NPort <nlp_DID> */
7389 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7390 "2928 NPIV LOGO completes to NPort x%x "
7391 "Data: x%x x%x x%x x%x\n",
7392 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
7393 irsp->ulpTimeout, vport->num_disc_nodes);
7394
7395 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
7396 spin_lock_irq(shost->host_lock);
7397 vport->fc_flag &= ~FC_FABRIC;
7398 spin_unlock_irq(shost->host_lock);
7399 }
James Smart92d7f7b2007-06-17 19:56:38 -05007400}
7401
James Smarte59058c2008-08-24 21:49:00 -04007402/**
James Smart3621a712009-04-06 18:47:14 -04007403 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007404 * @vport: pointer to a virtual N_Port data structure.
7405 * @ndlp: pointer to a node-list data structure.
7406 *
7407 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7408 *
7409 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7410 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7411 * will be stored into the context1 field of the IOCB for the completion
7412 * callback function to the LOGO ELS command.
7413 *
7414 * Return codes
7415 * 0 - Successfully issued logo off the @vport
7416 * 1 - Failed to issue logo off the @vport
7417 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007418int
7419lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7420{
7421 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7422 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007423 IOCB_t *icmd;
7424 struct lpfc_iocbq *elsiocb;
7425 uint8_t *pcmd;
7426 uint16_t cmdsize;
7427
7428 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7429 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7430 ELS_CMD_LOGO);
7431 if (!elsiocb)
7432 return 1;
7433
7434 icmd = &elsiocb->iocb;
7435 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7436 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7437 pcmd += sizeof(uint32_t);
7438
7439 /* Fill in LOGO payload */
7440 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7441 pcmd += sizeof(uint32_t);
7442 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7443
James Smart858c9f62007-06-17 19:56:39 -05007444 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7445 "Issue LOGO npiv did:x%x flg:x%x",
7446 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7447
James Smart92d7f7b2007-06-17 19:56:38 -05007448 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7449 spin_lock_irq(shost->host_lock);
7450 ndlp->nlp_flag |= NLP_LOGO_SND;
7451 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007452 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7453 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007454 spin_lock_irq(shost->host_lock);
7455 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7456 spin_unlock_irq(shost->host_lock);
7457 lpfc_els_free_iocb(phba, elsiocb);
7458 return 1;
7459 }
7460 return 0;
7461}
7462
James Smarte59058c2008-08-24 21:49:00 -04007463/**
James Smart3621a712009-04-06 18:47:14 -04007464 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007465 * @ptr: holder for the timer function associated data.
7466 *
7467 * This routine is invoked by the fabric iocb block timer after
7468 * timeout. It posts the fabric iocb block timeout event by setting the
7469 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7470 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7471 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7472 * posted event WORKER_FABRIC_BLOCK_TMO.
7473 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007474void
7475lpfc_fabric_block_timeout(unsigned long ptr)
7476{
7477 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7478 unsigned long iflags;
7479 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007480
James Smart92d7f7b2007-06-17 19:56:38 -05007481 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7482 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7483 if (!tmo_posted)
7484 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7485 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7486
James Smart5e9d9b82008-06-14 22:52:53 -04007487 if (!tmo_posted)
7488 lpfc_worker_wake_up(phba);
7489 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007490}
7491
James Smarte59058c2008-08-24 21:49:00 -04007492/**
James Smart3621a712009-04-06 18:47:14 -04007493 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007494 * @phba: pointer to lpfc hba data structure.
7495 *
7496 * This routine issues one fabric iocb from the driver internal list to
7497 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7498 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7499 * remove one pending fabric iocb from the driver internal list and invokes
7500 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7501 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007502static void
7503lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7504{
7505 struct lpfc_iocbq *iocb;
7506 unsigned long iflags;
7507 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007508 IOCB_t *cmd;
7509
7510repeat:
7511 iocb = NULL;
7512 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007513 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007514 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7515 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7516 list);
7517 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007518 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007519 atomic_inc(&phba->fabric_iocb_count);
7520 }
7521 spin_unlock_irqrestore(&phba->hbalock, iflags);
7522 if (iocb) {
7523 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7524 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7525 iocb->iocb_flag |= LPFC_IO_FABRIC;
7526
James Smart858c9f62007-06-17 19:56:39 -05007527 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7528 "Fabric sched1: ste:x%x",
7529 iocb->vport->port_state, 0, 0);
7530
James Smart3772a992009-05-22 14:50:54 -04007531 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007532
7533 if (ret == IOCB_ERROR) {
7534 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7535 iocb->fabric_iocb_cmpl = NULL;
7536 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7537 cmd = &iocb->iocb;
7538 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7539 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7540 iocb->iocb_cmpl(phba, iocb, iocb);
7541
7542 atomic_dec(&phba->fabric_iocb_count);
7543 goto repeat;
7544 }
7545 }
7546
7547 return;
7548}
7549
James Smarte59058c2008-08-24 21:49:00 -04007550/**
James Smart3621a712009-04-06 18:47:14 -04007551 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007552 * @phba: pointer to lpfc hba data structure.
7553 *
7554 * This routine unblocks the issuing fabric iocb command. The function
7555 * will clear the fabric iocb block bit and then invoke the routine
7556 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7557 * from the driver internal fabric iocb list.
7558 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007559void
7560lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7561{
7562 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7563
7564 lpfc_resume_fabric_iocbs(phba);
7565 return;
7566}
7567
James Smarte59058c2008-08-24 21:49:00 -04007568/**
James Smart3621a712009-04-06 18:47:14 -04007569 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007570 * @phba: pointer to lpfc hba data structure.
7571 *
7572 * This routine blocks the issuing fabric iocb for a specified amount of
7573 * time (currently 100 ms). This is done by set the fabric iocb block bit
7574 * and set up a timeout timer for 100ms. When the block bit is set, no more
7575 * fabric iocb will be issued out of the HBA.
7576 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007577static void
7578lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7579{
7580 int blocked;
7581
7582 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007583 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007584 if (!blocked)
7585 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7586
7587 return;
7588}
7589
James Smarte59058c2008-08-24 21:49:00 -04007590/**
James Smart3621a712009-04-06 18:47:14 -04007591 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007592 * @phba: pointer to lpfc hba data structure.
7593 * @cmdiocb: pointer to lpfc command iocb data structure.
7594 * @rspiocb: pointer to lpfc response iocb data structure.
7595 *
7596 * This routine is the callback function that is put to the fabric iocb's
7597 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7598 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7599 * function first restores and invokes the original iocb's callback function
7600 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7601 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7602 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007603static void
7604lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7605 struct lpfc_iocbq *rspiocb)
7606{
7607 struct ls_rjt stat;
7608
7609 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7610 BUG();
7611
7612 switch (rspiocb->iocb.ulpStatus) {
7613 case IOSTAT_NPORT_RJT:
7614 case IOSTAT_FABRIC_RJT:
7615 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7616 lpfc_block_fabric_iocbs(phba);
7617 }
7618 break;
7619
7620 case IOSTAT_NPORT_BSY:
7621 case IOSTAT_FABRIC_BSY:
7622 lpfc_block_fabric_iocbs(phba);
7623 break;
7624
7625 case IOSTAT_LS_RJT:
7626 stat.un.lsRjtError =
7627 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7628 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7629 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7630 lpfc_block_fabric_iocbs(phba);
7631 break;
7632 }
7633
7634 if (atomic_read(&phba->fabric_iocb_count) == 0)
7635 BUG();
7636
7637 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7638 cmdiocb->fabric_iocb_cmpl = NULL;
7639 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7640 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7641
7642 atomic_dec(&phba->fabric_iocb_count);
7643 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007644 /* Post any pending iocbs to HBA */
7645 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007646 }
7647}
7648
James Smarte59058c2008-08-24 21:49:00 -04007649/**
James Smart3621a712009-04-06 18:47:14 -04007650 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007651 * @phba: pointer to lpfc hba data structure.
7652 * @iocb: pointer to lpfc command iocb data structure.
7653 *
7654 * This routine is used as the top-level API for issuing a fabric iocb command
7655 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7656 * function makes sure that only one fabric bound iocb will be outstanding at
7657 * any given time. As such, this function will first check to see whether there
7658 * is already an outstanding fabric iocb on the wire. If so, it will put the
7659 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7660 * issued later. Otherwise, it will issue the iocb on the wire and update the
7661 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7662 *
7663 * Note, this implementation has a potential sending out fabric IOCBs out of
7664 * order. The problem is caused by the construction of the "ready" boolen does
7665 * not include the condition that the internal fabric IOCB list is empty. As
7666 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7667 * ahead of the fabric IOCBs in the internal list.
7668 *
7669 * Return code
7670 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7671 * IOCB_ERROR - failed to issue fabric iocb
7672 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007673static int
James Smart92d7f7b2007-06-17 19:56:38 -05007674lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7675{
7676 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007677 int ready;
7678 int ret;
7679
7680 if (atomic_read(&phba->fabric_iocb_count) > 1)
7681 BUG();
7682
7683 spin_lock_irqsave(&phba->hbalock, iflags);
7684 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7685 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7686
James Smart7f5f3d02008-02-08 18:50:14 -05007687 if (ready)
7688 /* Increment fabric iocb count to hold the position */
7689 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007690 spin_unlock_irqrestore(&phba->hbalock, iflags);
7691 if (ready) {
7692 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7693 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7694 iocb->iocb_flag |= LPFC_IO_FABRIC;
7695
James Smart858c9f62007-06-17 19:56:39 -05007696 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7697 "Fabric sched2: ste:x%x",
7698 iocb->vport->port_state, 0, 0);
7699
James Smart3772a992009-05-22 14:50:54 -04007700 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007701
7702 if (ret == IOCB_ERROR) {
7703 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7704 iocb->fabric_iocb_cmpl = NULL;
7705 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7706 atomic_dec(&phba->fabric_iocb_count);
7707 }
7708 } else {
7709 spin_lock_irqsave(&phba->hbalock, iflags);
7710 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7711 spin_unlock_irqrestore(&phba->hbalock, iflags);
7712 ret = IOCB_SUCCESS;
7713 }
7714 return ret;
7715}
7716
James Smarte59058c2008-08-24 21:49:00 -04007717/**
James Smart3621a712009-04-06 18:47:14 -04007718 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007719 * @vport: pointer to a virtual N_Port data structure.
7720 *
7721 * This routine aborts all the IOCBs associated with a @vport from the
7722 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7723 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7724 * list, removes each IOCB associated with the @vport off the list, set the
7725 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7726 * associated with the IOCB.
7727 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007728static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007729{
7730 LIST_HEAD(completions);
7731 struct lpfc_hba *phba = vport->phba;
7732 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007733
7734 spin_lock_irq(&phba->hbalock);
7735 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7736 list) {
7737
7738 if (piocb->vport != vport)
7739 continue;
7740
7741 list_move_tail(&piocb->list, &completions);
7742 }
7743 spin_unlock_irq(&phba->hbalock);
7744
James Smarta257bf92009-04-06 18:48:10 -04007745 /* Cancel all the IOCBs from the completions list */
7746 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7747 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007748}
7749
James Smarte59058c2008-08-24 21:49:00 -04007750/**
James Smart3621a712009-04-06 18:47:14 -04007751 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007752 * @ndlp: pointer to a node-list data structure.
7753 *
7754 * This routine aborts all the IOCBs associated with an @ndlp from the
7755 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7756 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7757 * list, removes each IOCB associated with the @ndlp off the list, set the
7758 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7759 * associated with the IOCB.
7760 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007761void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7762{
7763 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007764 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007765 struct lpfc_iocbq *tmp_iocb, *piocb;
7766 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007767
7768 spin_lock_irq(&phba->hbalock);
7769 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7770 list) {
7771 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7772
7773 list_move_tail(&piocb->list, &completions);
7774 }
7775 }
7776 spin_unlock_irq(&phba->hbalock);
7777
James Smarta257bf92009-04-06 18:48:10 -04007778 /* Cancel all the IOCBs from the completions list */
7779 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7780 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007781}
7782
James Smarte59058c2008-08-24 21:49:00 -04007783/**
James Smart3621a712009-04-06 18:47:14 -04007784 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007785 * @phba: pointer to lpfc hba data structure.
7786 *
7787 * This routine aborts all the IOCBs currently on the driver internal
7788 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7789 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7790 * list, removes IOCBs off the list, set the status feild to
7791 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7792 * the IOCB.
7793 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007794void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7795{
7796 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007797
7798 spin_lock_irq(&phba->hbalock);
7799 list_splice_init(&phba->fabric_iocb_list, &completions);
7800 spin_unlock_irq(&phba->hbalock);
7801
James Smarta257bf92009-04-06 18:48:10 -04007802 /* Cancel all the IOCBs from the completions list */
7803 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7804 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007805}
James Smart6fb120a2009-05-22 14:52:59 -04007806
7807/**
James Smart1151e3e2011-02-16 12:39:35 -05007808 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7809 * @vport: pointer to lpfc vport data structure.
7810 *
7811 * This routine is invoked by the vport cleanup for deletions and the cleanup
7812 * for an ndlp on removal.
7813 **/
7814void
7815lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
7816{
7817 struct lpfc_hba *phba = vport->phba;
7818 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7819 unsigned long iflag = 0;
7820
7821 spin_lock_irqsave(&phba->hbalock, iflag);
7822 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7823 list_for_each_entry_safe(sglq_entry, sglq_next,
7824 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7825 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
7826 sglq_entry->ndlp = NULL;
7827 }
7828 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7829 spin_unlock_irqrestore(&phba->hbalock, iflag);
7830 return;
7831}
7832
7833/**
James Smart6fb120a2009-05-22 14:52:59 -04007834 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7835 * @phba: pointer to lpfc hba data structure.
7836 * @axri: pointer to the els xri abort wcqe structure.
7837 *
7838 * This routine is invoked by the worker thread to process a SLI4 slow-path
7839 * ELS aborted xri.
7840 **/
7841void
7842lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7843 struct sli4_wcqe_xri_aborted *axri)
7844{
7845 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05007846 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04007847 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05007848
James Smart6fb120a2009-05-22 14:52:59 -04007849 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7850 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05007851 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04007852 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007853
James Smart0f65ff62010-02-26 14:14:23 -05007854 spin_lock_irqsave(&phba->hbalock, iflag);
7855 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007856 list_for_each_entry_safe(sglq_entry, sglq_next,
7857 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7858 if (sglq_entry->sli4_xritag == xri) {
7859 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05007860 ndlp = sglq_entry->ndlp;
7861 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04007862 list_add_tail(&sglq_entry->list,
7863 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007864 sglq_entry->state = SGL_FREED;
7865 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007866 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart19ca7602010-11-20 23:11:55 -05007867 lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04007868
7869 /* Check if TXQ queue needs to be serviced */
7870 if (pring->txq_cnt)
7871 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007872 return;
7873 }
7874 }
James Smart0f65ff62010-02-26 14:14:23 -05007875 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04007876 lxri = lpfc_sli4_xri_inrange(phba, xri);
7877 if (lxri == NO_XRI) {
7878 spin_unlock_irqrestore(&phba->hbalock, iflag);
7879 return;
7880 }
7881 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05007882 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7883 spin_unlock_irqrestore(&phba->hbalock, iflag);
7884 return;
7885 }
7886 sglq_entry->state = SGL_XRI_ABORTED;
7887 spin_unlock_irqrestore(&phba->hbalock, iflag);
7888 return;
James Smart6fb120a2009-05-22 14:52:59 -04007889}