blob: d34b69f9cdb17d5efd288b55da1fa1543ac965f6 [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 Smartda0436e2009-05-22 14:51:39 -0400253 icmd->ulpContext = vport->vpi + phba->vpi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500254 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500255 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
256 if (elscmd == ELS_CMD_ECHO)
257 icmd->ulpCt_l = 0; /* context = invalid RPI */
258 else
259 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500260 }
261
dea31012005-04-17 16:05:31 -0500262 bpl = (struct ulp_bde64 *) pbuflist->virt;
263 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
264 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
265 bpl->tus.f.bdeSize = cmdSize;
266 bpl->tus.f.bdeFlags = 0;
267 bpl->tus.w = le32_to_cpu(bpl->tus.w);
268
269 if (expectRsp) {
270 bpl++;
271 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
272 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
273 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400274 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500275 bpl->tus.w = le32_to_cpu(bpl->tus.w);
276 }
277
James Smartfa4066b2008-01-11 01:53:27 -0500278 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400279 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500280 if (!elsiocb->context1)
281 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400282 elsiocb->context2 = pcmd;
283 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500284 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500285 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500286 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
287
288 if (prsp) {
289 list_add(&prsp->list, &pcmd->list);
290 }
dea31012005-04-17 16:05:31 -0500291 if (expectRsp) {
292 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400293 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
294 "0116 Xmit ELS command x%x to remote "
295 "NPORT x%x I/O tag: x%x, port state: x%x\n",
296 elscmd, did, elsiocb->iotag,
297 vport->port_state);
dea31012005-04-17 16:05:31 -0500298 } else {
299 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400300 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
301 "0117 Xmit ELS response x%x to remote "
302 "NPORT x%x I/O tag: x%x, size: x%x\n",
303 elscmd, ndlp->nlp_DID, elsiocb->iotag,
304 cmdSize);
dea31012005-04-17 16:05:31 -0500305 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500306 return elsiocb;
dea31012005-04-17 16:05:31 -0500307
James Smartfa4066b2008-01-11 01:53:27 -0500308els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500309 if (expectRsp)
310 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500311 kfree(pbuflist);
312
313els_iocb_free_prsp_exit:
314 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
315 kfree(prsp);
316
317els_iocb_free_pcmb_exit:
318 kfree(pcmd);
319 lpfc_sli_release_iocbq(phba, elsiocb);
320 return NULL;
321}
dea31012005-04-17 16:05:31 -0500322
James Smarte59058c2008-08-24 21:49:00 -0400323/**
James Smart3621a712009-04-06 18:47:14 -0400324 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400325 * @vport: pointer to a host virtual N_Port data structure.
326 *
327 * This routine issues a fabric registration login for a @vport. An
328 * active ndlp node with Fabric_DID must already exist for this @vport.
329 * The routine invokes two mailbox commands to carry out fabric registration
330 * login through the HBA firmware: the first mailbox command requests the
331 * HBA to perform link configuration for the @vport; and the second mailbox
332 * command requests the HBA to perform the actual fabric registration login
333 * with the @vport.
334 *
335 * Return code
336 * 0 - successfully issued fabric registration login for @vport
337 * -ENXIO -- failed to issue fabric registration login for @vport
338 **/
James Smart3772a992009-05-22 14:50:54 -0400339int
James Smart92d7f7b2007-06-17 19:56:38 -0500340lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
341{
342 struct lpfc_hba *phba = vport->phba;
343 LPFC_MBOXQ_t *mbox;
344 struct lpfc_dmabuf *mp;
345 struct lpfc_nodelist *ndlp;
346 struct serv_parm *sp;
347 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400348 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500349
350 sp = &phba->fc_fabparam;
351 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500352 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400353 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500354 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400355 }
James Smart92d7f7b2007-06-17 19:56:38 -0500356
357 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400358 if (!mbox) {
359 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500360 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400361 }
James Smart92d7f7b2007-06-17 19:56:38 -0500362
363 vport->port_state = LPFC_FABRIC_CFG_LINK;
364 lpfc_config_link(phba, mbox);
365 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
366 mbox->vport = vport;
367
James Smart0b727fe2007-10-27 13:37:25 -0400368 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400369 if (rc == MBX_NOT_FINISHED) {
370 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500371 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400372 }
James Smart92d7f7b2007-06-17 19:56:38 -0500373
374 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400375 if (!mbox) {
376 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500377 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400378 }
James Smart40426292010-12-15 17:58:10 -0500379 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
380 ndlp->nlp_rpi);
James Smart98c9ea52007-10-27 13:37:33 -0400381 if (rc) {
382 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500383 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400384 }
James Smart92d7f7b2007-06-17 19:56:38 -0500385
386 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
387 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500388 /* increment the reference count on ndlp to hold reference
389 * for the callback routine.
390 */
James Smart92d7f7b2007-06-17 19:56:38 -0500391 mbox->context2 = lpfc_nlp_get(ndlp);
392
James Smart0b727fe2007-10-27 13:37:25 -0400393 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400394 if (rc == MBX_NOT_FINISHED) {
395 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500396 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400397 }
James Smart92d7f7b2007-06-17 19:56:38 -0500398
399 return 0;
400
401fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500402 /* decrement the reference count on ndlp just incremented
403 * for the failed mbox command.
404 */
James Smart92d7f7b2007-06-17 19:56:38 -0500405 lpfc_nlp_put(ndlp);
406 mp = (struct lpfc_dmabuf *) mbox->context1;
407 lpfc_mbuf_free(phba, mp->virt, mp->phys);
408 kfree(mp);
409fail_free_mbox:
410 mempool_free(mbox, phba->mbox_mem_pool);
411
412fail:
413 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400414 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400415 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500416 return -ENXIO;
417}
418
James Smarte59058c2008-08-24 21:49:00 -0400419/**
James Smart6fb120a2009-05-22 14:52:59 -0400420 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
421 * @vport: pointer to a host virtual N_Port data structure.
422 *
423 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
424 * the @vport. This mailbox command is necessary for FCoE only.
425 *
426 * Return code
427 * 0 - successfully issued REG_VFI for @vport
428 * A failure code otherwise.
429 **/
430static int
431lpfc_issue_reg_vfi(struct lpfc_vport *vport)
432{
433 struct lpfc_hba *phba = vport->phba;
434 LPFC_MBOXQ_t *mboxq;
435 struct lpfc_nodelist *ndlp;
436 struct serv_parm *sp;
437 struct lpfc_dmabuf *dmabuf;
438 int rc = 0;
439
440 sp = &phba->fc_fabparam;
441 ndlp = lpfc_findnode_did(vport, Fabric_DID);
442 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
443 rc = -ENODEV;
444 goto fail;
445 }
446
447 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
448 if (!dmabuf) {
449 rc = -ENOMEM;
450 goto fail;
451 }
452 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
453 if (!dmabuf->virt) {
454 rc = -ENOMEM;
455 goto fail_free_dmabuf;
456 }
457 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
458 if (!mboxq) {
459 rc = -ENOMEM;
460 goto fail_free_coherent;
461 }
462 vport->port_state = LPFC_FABRIC_CFG_LINK;
463 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
464 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
465 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
466 mboxq->vport = vport;
467 mboxq->context1 = dmabuf;
468 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
469 if (rc == MBX_NOT_FINISHED) {
470 rc = -ENXIO;
471 goto fail_free_mbox;
472 }
473 return 0;
474
475fail_free_mbox:
476 mempool_free(mboxq, phba->mbox_mem_pool);
477fail_free_coherent:
478 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
479fail_free_dmabuf:
480 kfree(dmabuf);
481fail:
482 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
483 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
484 "0289 Issue Register VFI failed: Err %d\n", rc);
485 return rc;
486}
487
488/**
James Smart92494142011-02-16 12:39:44 -0500489 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
490 * @vport: pointer to a host virtual N_Port data structure.
491 * @sp: pointer to service parameter data structure.
492 *
493 * This routine is called from FLOGI/FDISC completion handler functions.
494 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
495 * node nodename is changed in the completion service parameter else return
496 * 0. This function also set flag in the vport data structure to delay
497 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
498 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
499 * node nodename is changed in the completion service parameter.
500 *
501 * Return code
502 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
503 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
504 *
505 **/
506static uint8_t
507lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
508 struct serv_parm *sp)
509{
510 uint8_t fabric_param_changed = 0;
511 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
512
513 if ((vport->fc_prevDID != vport->fc_myDID) ||
514 memcmp(&vport->fabric_portname, &sp->portName,
515 sizeof(struct lpfc_name)) ||
516 memcmp(&vport->fabric_nodename, &sp->nodeName,
517 sizeof(struct lpfc_name)))
518 fabric_param_changed = 1;
519
520 /*
521 * Word 1 Bit 31 in common service parameter is overloaded.
522 * Word 1 Bit 31 in FLOGI request is multiple NPort request
523 * Word 1 Bit 31 in FLOGI response is clean address bit
524 *
525 * If fabric parameter is changed and clean address bit is
526 * cleared delay nport discovery if
527 * - vport->fc_prevDID != 0 (not initial discovery) OR
528 * - lpfc_delay_discovery module parameter is set.
529 */
530 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
531 (vport->fc_prevDID || lpfc_delay_discovery)) {
532 spin_lock_irq(shost->host_lock);
533 vport->fc_flag |= FC_DISC_DELAYED;
534 spin_unlock_irq(shost->host_lock);
535 }
536
537 return fabric_param_changed;
538}
539
540
541/**
James Smart3621a712009-04-06 18:47:14 -0400542 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400543 * @vport: pointer to a host virtual N_Port data structure.
544 * @ndlp: pointer to a node-list data structure.
545 * @sp: pointer to service parameter data structure.
546 * @irsp: pointer to the IOCB within the lpfc response IOCB.
547 *
548 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
549 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
550 * port in a fabric topology. It properly sets up the parameters to the @ndlp
551 * from the IOCB response. It also check the newly assigned N_Port ID to the
552 * @vport against the previously assigned N_Port ID. If it is different from
553 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
554 * is invoked on all the remaining nodes with the @vport to unregister the
555 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
556 * is invoked to register login to the fabric.
557 *
558 * Return code
559 * 0 - Success (currently, always return 0)
560 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500561static int
James Smart2e0fef82007-06-17 19:56:36 -0500562lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
563 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500564{
James Smart2e0fef82007-06-17 19:56:36 -0500565 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
566 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500567 struct lpfc_nodelist *np;
568 struct lpfc_nodelist *next_np;
James Smart92494142011-02-16 12:39:44 -0500569 uint8_t fabric_param_changed;
dea31012005-04-17 16:05:31 -0500570
James Smart2e0fef82007-06-17 19:56:36 -0500571 spin_lock_irq(shost->host_lock);
572 vport->fc_flag |= FC_FABRIC;
573 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500574
575 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
576 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
577 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
578
James Smart12265f62010-10-22 11:05:53 -0400579 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500580 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
581
James Smart76a95d72010-11-20 23:11:48 -0500582 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500583 spin_lock_irq(shost->host_lock);
584 vport->fc_flag |= FC_PUBLIC_LOOP;
585 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500586 }
587
James Smart2e0fef82007-06-17 19:56:36 -0500588 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500589 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500590 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500591 ndlp->nlp_class_sup = 0;
592 if (sp->cls1.classValid)
593 ndlp->nlp_class_sup |= FC_COS_CLASS1;
594 if (sp->cls2.classValid)
595 ndlp->nlp_class_sup |= FC_COS_CLASS2;
596 if (sp->cls3.classValid)
597 ndlp->nlp_class_sup |= FC_COS_CLASS3;
598 if (sp->cls4.classValid)
599 ndlp->nlp_class_sup |= FC_COS_CLASS4;
600 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
601 sp->cmn.bbRcvSizeLsb;
James Smart92494142011-02-16 12:39:44 -0500602
603 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
604 memcpy(&vport->fabric_portname, &sp->portName,
605 sizeof(struct lpfc_name));
606 memcpy(&vport->fabric_nodename, &sp->nodeName,
607 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500608 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
609
James Smart92d7f7b2007-06-17 19:56:38 -0500610 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
611 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400612 lpfc_printf_vlog(vport, KERN_WARNING,
613 LOG_ELS | LOG_VPORT,
614 "1816 FLOGI NPIV supported, "
615 "response data 0x%x\n",
616 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500617 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500618 } else {
619 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400620 to call reg_vnpid atleast for the physcial host */
621 lpfc_printf_vlog(vport, KERN_WARNING,
622 LOG_ELS | LOG_VPORT,
623 "1817 Fabric does not support NPIV "
624 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500625 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
626 }
627 }
628
James Smart92494142011-02-16 12:39:44 -0500629 if (fabric_param_changed &&
James Smart92d7f7b2007-06-17 19:56:38 -0500630 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
631
632 /* If our NportID changed, we need to ensure all
633 * remaining NPORTs get unreg_login'ed.
634 */
635 list_for_each_entry_safe(np, next_np,
636 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400637 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500638 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500639 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
640 !(np->nlp_flag & NLP_NPR_ADISC))
641 continue;
642 spin_lock_irq(shost->host_lock);
643 np->nlp_flag &= ~NLP_NPR_ADISC;
644 spin_unlock_irq(shost->host_lock);
645 lpfc_unreg_rpi(vport, np);
646 }
James Smart78730cf2010-04-06 15:06:30 -0400647 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400648
649 if (phba->sli_rev == LPFC_SLI_REV4)
650 lpfc_sli4_unreg_all_rpis(vport);
651
James Smart92d7f7b2007-06-17 19:56:38 -0500652 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
653 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500654 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500655 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500656 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500657 }
James Smartecfd03c2010-02-12 14:41:27 -0500658 /*
659 * If VPI is unreged, driver need to do INIT_VPI
660 * before re-registering
661 */
662 if (phba->sli_rev == LPFC_SLI_REV4) {
663 spin_lock_irq(shost->host_lock);
664 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
665 spin_unlock_irq(shost->host_lock);
666 }
James Smart38b92ef2010-08-04 16:11:39 -0400667 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
668 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
669 /*
670 * Driver needs to re-reg VPI in order for f/w
671 * to update the MAC address.
672 */
673 lpfc_register_new_vport(phba, vport, ndlp);
674 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500675 }
676
James Smart6fb120a2009-05-22 14:52:59 -0400677 if (phba->sli_rev < LPFC_SLI_REV4) {
678 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
679 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
680 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
681 lpfc_register_new_vport(phba, vport, ndlp);
682 else
683 lpfc_issue_fabric_reglogin(vport);
684 } else {
685 ndlp->nlp_type |= NLP_FABRIC;
686 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500687 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
688 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400689 lpfc_start_fdiscs(phba);
690 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500691 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500692 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500693 else
James Smart6fb120a2009-05-22 14:52:59 -0400694 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500695 }
dea31012005-04-17 16:05:31 -0500696 return 0;
dea31012005-04-17 16:05:31 -0500697}
James Smarte59058c2008-08-24 21:49:00 -0400698/**
James Smart3621a712009-04-06 18:47:14 -0400699 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400700 * @vport: pointer to a host virtual N_Port data structure.
701 * @ndlp: pointer to a node-list data structure.
702 * @sp: pointer to service parameter data structure.
703 *
704 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
705 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
706 * in a point-to-point topology. First, the @vport's N_Port Name is compared
707 * with the received N_Port Name: if the @vport's N_Port Name is greater than
708 * the received N_Port Name lexicographically, this node shall assign local
709 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
710 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
711 * this node shall just wait for the remote node to issue PLOGI and assign
712 * N_Port IDs.
713 *
714 * Return code
715 * 0 - Success
716 * -ENXIO - Fail
717 **/
dea31012005-04-17 16:05:31 -0500718static int
James Smart2e0fef82007-06-17 19:56:36 -0500719lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
720 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500721{
James Smart2e0fef82007-06-17 19:56:36 -0500722 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
723 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500724 LPFC_MBOXQ_t *mbox;
725 int rc;
726
James Smart2e0fef82007-06-17 19:56:36 -0500727 spin_lock_irq(shost->host_lock);
728 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
729 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500730
731 phba->fc_edtov = FF_DEF_EDTOV;
732 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500733 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500734 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500735 if (rc >= 0) {
736 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500737 spin_lock_irq(shost->host_lock);
738 vport->fc_flag |= FC_PT2PT_PLOGI;
739 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500740
741 /*
742 * N_Port ID cannot be 0, set our to LocalID the other
743 * side will be RemoteID.
744 */
745
746 /* not equal */
747 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500748 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500749
750 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
751 if (!mbox)
752 goto fail;
753
754 lpfc_config_link(phba, mbox);
755
756 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500757 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400758 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500759 if (rc == MBX_NOT_FINISHED) {
760 mempool_free(mbox, phba->mbox_mem_pool);
761 goto fail;
762 }
James Smarte47c9092008-02-08 18:49:26 -0500763 /* Decrement ndlp reference count indicating that ndlp can be
764 * safely released when other references to it are done.
765 */
James Smart329f9bc2007-04-25 09:53:01 -0400766 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500767
James Smart2e0fef82007-06-17 19:56:36 -0500768 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500769 if (!ndlp) {
770 /*
771 * Cannot find existing Fabric ndlp, so allocate a
772 * new one
773 */
774 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
775 if (!ndlp)
776 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500777 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500778 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
779 ndlp = lpfc_enable_node(vport, ndlp,
780 NLP_STE_UNUSED_NODE);
781 if(!ndlp)
782 goto fail;
dea31012005-04-17 16:05:31 -0500783 }
784
785 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500786 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500787 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500788 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500789 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500790 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
791 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500792 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500793 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500794 } else
795 /* This side will wait for the PLOGI, decrement ndlp reference
796 * count indicating that ndlp can be released when other
797 * references to it are done.
798 */
James Smart329f9bc2007-04-25 09:53:01 -0400799 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500800
James Smart09372822008-01-11 01:52:54 -0500801 /* If we are pt2pt with another NPort, force NPIV off! */
802 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
803
James Smart2e0fef82007-06-17 19:56:36 -0500804 spin_lock_irq(shost->host_lock);
805 vport->fc_flag |= FC_PT2PT;
806 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500807
808 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500809 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500810 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500811fail:
dea31012005-04-17 16:05:31 -0500812 return -ENXIO;
813}
814
James Smarte59058c2008-08-24 21:49:00 -0400815/**
James Smart3621a712009-04-06 18:47:14 -0400816 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400817 * @phba: pointer to lpfc hba data structure.
818 * @cmdiocb: pointer to lpfc command iocb data structure.
819 * @rspiocb: pointer to lpfc response iocb data structure.
820 *
821 * This routine is the top-level completion callback function for issuing
822 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
823 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
824 * retry has been made (either immediately or delayed with lpfc_els_retry()
825 * returning 1), the command IOCB will be released and function returned.
826 * If the retry attempt has been given up (possibly reach the maximum
827 * number of retries), one additional decrement of ndlp reference shall be
828 * invoked before going out after releasing the command IOCB. This will
829 * actually release the remote node (Note, lpfc_els_free_iocb() will also
830 * invoke one decrement of ndlp reference count). If no error reported in
831 * the IOCB status, the command Port ID field is used to determine whether
832 * this is a point-to-point topology or a fabric topology: if the Port ID
833 * field is assigned, it is a fabric topology; otherwise, it is a
834 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
835 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
836 * specific topology completion conditions.
837 **/
dea31012005-04-17 16:05:31 -0500838static void
James Smart329f9bc2007-04-25 09:53:01 -0400839lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
840 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500841{
James Smart2e0fef82007-06-17 19:56:36 -0500842 struct lpfc_vport *vport = cmdiocb->vport;
843 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500844 IOCB_t *irsp = &rspiocb->iocb;
845 struct lpfc_nodelist *ndlp = cmdiocb->context1;
846 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
847 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500848 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500849 int rc;
850
851 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500852 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500853 /* One additional decrement on node reference count to
854 * trigger the release of the node
855 */
James Smart329f9bc2007-04-25 09:53:01 -0400856 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500857 goto out;
858 }
859
James Smart858c9f62007-06-17 19:56:39 -0500860 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
861 "FLOGI cmpl: status:x%x/x%x state:x%x",
862 irsp->ulpStatus, irsp->un.ulpWord[4],
863 vport->port_state);
864
dea31012005-04-17 16:05:31 -0500865 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500866 /*
James Smarta93ff372010-10-22 11:06:08 -0400867 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500868 * due to new FCF discovery
869 */
870 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smartdbb6b3a2010-06-08 18:31:37 -0400871 (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
872 (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) &&
873 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500874 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400875 "2611 FLOGI failed on FCF (x%x), "
876 "status:x%x/x%x, tmo:x%x, perform "
877 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -0400878 phba->fcf.current_rec.fcf_indx,
879 irsp->ulpStatus, irsp->un.ulpWord[4],
880 irsp->ulpTimeout);
James Smart0c9ab6f2010-02-26 14:15:57 -0500881 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -0400882 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
883 if (rc)
884 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500885 }
886
James Smart38b92ef2010-08-04 16:11:39 -0400887 /* FLOGI failure */
888 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
889 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
890 irsp->ulpStatus, irsp->un.ulpWord[4],
891 irsp->ulpTimeout);
892
dea31012005-04-17 16:05:31 -0500893 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500894 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500895 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500896
James Smart76a95d72010-11-20 23:11:48 -0500897 /* FLOGI failure */
898 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
899 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
900 irsp->ulpStatus, irsp->un.ulpWord[4],
901 irsp->ulpTimeout);
902
dea31012005-04-17 16:05:31 -0500903 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500904 spin_lock_irq(shost->host_lock);
905 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
906 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500907
James Smart329f9bc2007-04-25 09:53:01 -0400908 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500909 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
910 * alpa map would take too long otherwise.
911 */
912 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400913 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smart76a95d72010-11-20 23:11:48 -0500914 if ((phba->sli_rev == LPFC_SLI_REV4) &&
915 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
916 (vport->fc_prevDID != vport->fc_myDID))) {
917 if (vport->fc_flag & FC_VFI_REGISTERED)
918 lpfc_sli4_unreg_all_rpis(vport);
919 lpfc_issue_reg_vfi(vport);
920 lpfc_nlp_put(ndlp);
921 goto out;
922 }
dea31012005-04-17 16:05:31 -0500923 }
dea31012005-04-17 16:05:31 -0500924 goto flogifail;
925 }
James Smart695a8142010-01-26 23:08:03 -0500926 spin_lock_irq(shost->host_lock);
927 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400928 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500929 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500930
931 /*
932 * The FLogI succeeded. Sync the data for the CPU before
933 * accessing it.
934 */
935 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
936
937 sp = prsp->virt + sizeof(uint32_t);
938
939 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400940 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200941 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400942 "Data: x%x x%x x%x x%x\n",
943 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
944 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500945
James Smart2e0fef82007-06-17 19:56:36 -0500946 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500947 /*
948 * If Common Service Parameters indicate Nport
949 * we are point to point, if Fport we are Fabric.
950 */
951 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500952 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -0500953 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -0500954 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400955 else {
956 lpfc_printf_vlog(vport, KERN_ERR,
957 LOG_FIP | LOG_ELS,
958 "2831 FLOGI response with cleared Fabric "
959 "bit fcf_index 0x%x "
960 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
961 "Fabric Name "
962 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
963 phba->fcf.current_rec.fcf_indx,
964 phba->fcf.current_rec.switch_name[0],
965 phba->fcf.current_rec.switch_name[1],
966 phba->fcf.current_rec.switch_name[2],
967 phba->fcf.current_rec.switch_name[3],
968 phba->fcf.current_rec.switch_name[4],
969 phba->fcf.current_rec.switch_name[5],
970 phba->fcf.current_rec.switch_name[6],
971 phba->fcf.current_rec.switch_name[7],
972 phba->fcf.current_rec.fabric_name[0],
973 phba->fcf.current_rec.fabric_name[1],
974 phba->fcf.current_rec.fabric_name[2],
975 phba->fcf.current_rec.fabric_name[3],
976 phba->fcf.current_rec.fabric_name[4],
977 phba->fcf.current_rec.fabric_name[5],
978 phba->fcf.current_rec.fabric_name[6],
979 phba->fcf.current_rec.fabric_name[7]);
980 lpfc_nlp_put(ndlp);
981 spin_lock_irq(&phba->hbalock);
982 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400983 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -0400984 spin_unlock_irq(&phba->hbalock);
985 goto out;
986 }
James Smart0c9ab6f2010-02-26 14:15:57 -0500987 if (!rc) {
988 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400989 if (phba->hba_flag & HBA_FIP_SUPPORT)
990 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
991 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400992 "2769 FLOGI to FCF (x%x) "
993 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -0400994 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500995 spin_lock_irq(&phba->hbalock);
996 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400997 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -0500998 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500999 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001000 }
dea31012005-04-17 16:05:31 -05001001 }
1002
1003flogifail:
James Smart329f9bc2007-04-25 09:53:01 -04001004 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001005
James Smart858c9f62007-06-17 19:56:39 -05001006 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001007 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001008 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001009
1010 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001011 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001012 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1013 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
1014 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
1015 (phba->link_state != LPFC_CLEAR_LA)) {
1016 /* If FLOGI failed enable link interrupt. */
1017 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001018 }
dea31012005-04-17 16:05:31 -05001019out:
1020 lpfc_els_free_iocb(phba, cmdiocb);
1021}
1022
James Smarte59058c2008-08-24 21:49:00 -04001023/**
James Smart3621a712009-04-06 18:47:14 -04001024 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001025 * @vport: pointer to a host virtual N_Port data structure.
1026 * @ndlp: pointer to a node-list data structure.
1027 * @retry: number of retries to the command IOCB.
1028 *
1029 * This routine issues a Fabric Login (FLOGI) Request ELS command
1030 * for a @vport. The initiator service parameters are put into the payload
1031 * of the FLOGI Request IOCB and the top-level callback function pointer
1032 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1033 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1034 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1035 *
1036 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1037 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1038 * will be stored into the context1 field of the IOCB for the completion
1039 * callback function to the FLOGI ELS command.
1040 *
1041 * Return code
1042 * 0 - successfully issued flogi iocb for @vport
1043 * 1 - failed to issue flogi iocb for @vport
1044 **/
dea31012005-04-17 16:05:31 -05001045static int
James Smart2e0fef82007-06-17 19:56:36 -05001046lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001047 uint8_t retry)
1048{
James Smart2e0fef82007-06-17 19:56:36 -05001049 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001050 struct serv_parm *sp;
1051 IOCB_t *icmd;
1052 struct lpfc_iocbq *elsiocb;
1053 struct lpfc_sli_ring *pring;
1054 uint8_t *pcmd;
1055 uint16_t cmdsize;
1056 uint32_t tmo;
1057 int rc;
1058
1059 pring = &phba->sli.ring[LPFC_ELS_RING];
1060
James Smart92d7f7b2007-06-17 19:56:38 -05001061 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001062 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1063 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001064
James Smart488d1462006-03-07 15:02:37 -05001065 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001066 return 1;
dea31012005-04-17 16:05:31 -05001067
1068 icmd = &elsiocb->iocb;
1069 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1070
1071 /* For FLOGI request, remainder of payload is service parameters */
1072 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001073 pcmd += sizeof(uint32_t);
1074 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001075 sp = (struct serv_parm *) pcmd;
1076
1077 /* Setup CSPs accordingly for Fabric */
1078 sp->cmn.e_d_tov = 0;
1079 sp->cmn.w2.r_a_tov = 0;
1080 sp->cls1.classValid = 0;
1081 sp->cls2.seqDelivery = 1;
1082 sp->cls3.seqDelivery = 1;
1083 if (sp->cmn.fcphLow < FC_PH3)
1084 sp->cmn.fcphLow = FC_PH3;
1085 if (sp->cmn.fcphHigh < FC_PH3)
1086 sp->cmn.fcphHigh = FC_PH3;
1087
James Smart40426292010-12-15 17:58:10 -05001088 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1089 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1090 LPFC_SLI_INTF_IF_TYPE_0)) {
James Smart6fb120a2009-05-22 14:52:59 -04001091 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1092 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1093 /* FLOGI needs to be 3 for WQE FCFI */
1094 /* Set the fcfi to the fcfi we registered with */
1095 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1096 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001097 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001098 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1099 icmd->ulpCt_h = 1;
1100 icmd->ulpCt_l = 0;
1101 }
1102
James Smart76a95d72010-11-20 23:11:48 -05001103 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001104 icmd->un.elsreq64.myID = 0;
1105 icmd->un.elsreq64.fl = 1;
1106 }
1107
dea31012005-04-17 16:05:31 -05001108 tmo = phba->fc_ratov;
1109 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001110 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001111 phba->fc_ratov = tmo;
1112
1113 phba->fc_stat.elsXmitFLOGI++;
1114 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001115
1116 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1117 "Issue FLOGI: opt:x%x",
1118 phba->sli3_options, 0, 0);
1119
James Smart92d7f7b2007-06-17 19:56:38 -05001120 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001121 if (rc == IOCB_ERROR) {
1122 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001123 return 1;
dea31012005-04-17 16:05:31 -05001124 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001125 return 0;
dea31012005-04-17 16:05:31 -05001126}
1127
James Smarte59058c2008-08-24 21:49:00 -04001128/**
James Smart3621a712009-04-06 18:47:14 -04001129 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001130 * @phba: pointer to lpfc hba data structure.
1131 *
1132 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1133 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1134 * list and issues an abort IOCB commond on each outstanding IOCB that
1135 * contains a active Fabric_DID ndlp. Note that this function is to issue
1136 * the abort IOCB command on all the outstanding IOCBs, thus when this
1137 * function returns, it does not guarantee all the IOCBs are actually aborted.
1138 *
1139 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001140 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001141 **/
dea31012005-04-17 16:05:31 -05001142int
James Smart2e0fef82007-06-17 19:56:36 -05001143lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001144{
1145 struct lpfc_sli_ring *pring;
1146 struct lpfc_iocbq *iocb, *next_iocb;
1147 struct lpfc_nodelist *ndlp;
1148 IOCB_t *icmd;
1149
1150 /* Abort outstanding I/O on NPort <nlp_DID> */
1151 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001152 "0201 Abort outstanding I/O on NPort x%x\n",
1153 Fabric_DID);
dea31012005-04-17 16:05:31 -05001154
1155 pring = &phba->sli.ring[LPFC_ELS_RING];
1156
1157 /*
1158 * Check the txcmplq for an iocb that matches the nport the driver is
1159 * searching for.
1160 */
James Smart2e0fef82007-06-17 19:56:36 -05001161 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001162 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1163 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001164 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1165 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001166 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001167 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1168 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001169 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001170 }
1171 }
James Smart2e0fef82007-06-17 19:56:36 -05001172 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001173
1174 return 0;
1175}
1176
James Smarte59058c2008-08-24 21:49:00 -04001177/**
James Smart3621a712009-04-06 18:47:14 -04001178 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001179 * @vport: pointer to a host virtual N_Port data structure.
1180 *
1181 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1182 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1183 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1184 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1185 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1186 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1187 * @vport.
1188 *
1189 * Return code
1190 * 0 - failed to issue initial flogi for @vport
1191 * 1 - successfully issued initial flogi for @vport
1192 **/
dea31012005-04-17 16:05:31 -05001193int
James Smart2e0fef82007-06-17 19:56:36 -05001194lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001195{
James Smart2e0fef82007-06-17 19:56:36 -05001196 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001197 struct lpfc_nodelist *ndlp;
1198
James Smart98c9ea52007-10-27 13:37:33 -04001199 vport->port_state = LPFC_FLOGI;
1200 lpfc_set_disctmo(vport);
1201
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001202 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001203 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001204 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001205 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001206 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1207 if (!ndlp)
1208 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001209 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001210 /* Set the node type */
1211 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001212 /* Put ndlp onto node list */
1213 lpfc_enqueue_node(vport, ndlp);
1214 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1215 /* re-setup ndlp without removing from node list */
1216 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1217 if (!ndlp)
1218 return 0;
dea31012005-04-17 16:05:31 -05001219 }
James Smart87af33f2007-10-27 13:37:43 -04001220
James Smart5ac6b302010-10-22 11:05:36 -04001221 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001222 /* This decrement of reference count to node shall kick off
1223 * the release of the node.
1224 */
James Smart329f9bc2007-04-25 09:53:01 -04001225 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001226 return 0;
1227 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001228 return 1;
dea31012005-04-17 16:05:31 -05001229}
1230
James Smarte59058c2008-08-24 21:49:00 -04001231/**
James Smart3621a712009-04-06 18:47:14 -04001232 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001233 * @vport: pointer to a host virtual N_Port data structure.
1234 *
1235 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1236 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1237 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1238 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1239 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1240 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1241 * @vport.
1242 *
1243 * Return code
1244 * 0 - failed to issue initial fdisc for @vport
1245 * 1 - successfully issued initial fdisc for @vport
1246 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001247int
1248lpfc_initial_fdisc(struct lpfc_vport *vport)
1249{
1250 struct lpfc_hba *phba = vport->phba;
1251 struct lpfc_nodelist *ndlp;
1252
1253 /* First look for the Fabric ndlp */
1254 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1255 if (!ndlp) {
1256 /* Cannot find existing Fabric ndlp, so allocate a new one */
1257 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1258 if (!ndlp)
1259 return 0;
1260 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001261 /* Put ndlp onto node list */
1262 lpfc_enqueue_node(vport, ndlp);
1263 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1264 /* re-setup ndlp without removing from node list */
1265 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1266 if (!ndlp)
1267 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001268 }
James Smarte47c9092008-02-08 18:49:26 -05001269
James Smart92d7f7b2007-06-17 19:56:38 -05001270 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001271 /* decrement node reference count to trigger the release of
1272 * the node.
1273 */
James Smart92d7f7b2007-06-17 19:56:38 -05001274 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001275 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001276 }
1277 return 1;
1278}
James Smart87af33f2007-10-27 13:37:43 -04001279
James Smarte59058c2008-08-24 21:49:00 -04001280/**
James Smart3621a712009-04-06 18:47:14 -04001281 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001282 * @vport: pointer to a host virtual N_Port data structure.
1283 *
1284 * This routine checks whether there are more remaining Port Logins
1285 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1286 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1287 * to issue ELS PLOGIs up to the configured discover threads with the
1288 * @vport (@vport->cfg_discovery_threads). The function also decrement
1289 * the @vport's num_disc_node by 1 if it is not already 0.
1290 **/
James Smart87af33f2007-10-27 13:37:43 -04001291void
James Smart2e0fef82007-06-17 19:56:36 -05001292lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001293{
1294 int sentplogi;
1295
James Smart2e0fef82007-06-17 19:56:36 -05001296 if (vport->num_disc_nodes)
1297 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001298
1299 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001300 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1301 "0232 Continue discovery with %d PLOGIs to go "
1302 "Data: x%x x%x x%x\n",
1303 vport->num_disc_nodes, vport->fc_plogi_cnt,
1304 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001305 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001306 if (vport->fc_flag & FC_NLP_MORE)
1307 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1308 sentplogi = lpfc_els_disc_plogi(vport);
1309
dea31012005-04-17 16:05:31 -05001310 return;
1311}
1312
James Smarte59058c2008-08-24 21:49:00 -04001313/**
James Smart3621a712009-04-06 18:47:14 -04001314 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001315 * @phba: pointer to lpfc hba data structure.
1316 * @prsp: pointer to response IOCB payload.
1317 * @ndlp: pointer to a node-list data structure.
1318 *
1319 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1320 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1321 * The following cases are considered N_Port confirmed:
1322 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1323 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1324 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1325 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1326 * 1) if there is a node on vport list other than the @ndlp with the same
1327 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1328 * on that node to release the RPI associated with the node; 2) if there is
1329 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1330 * into, a new node shall be allocated (or activated). In either case, the
1331 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1332 * be released and the new_ndlp shall be put on to the vport node list and
1333 * its pointer returned as the confirmed node.
1334 *
1335 * Note that before the @ndlp got "released", the keepDID from not-matching
1336 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1337 * of the @ndlp. This is because the release of @ndlp is actually to put it
1338 * into an inactive state on the vport node list and the vport node list
1339 * management algorithm does not allow two node with a same DID.
1340 *
1341 * Return code
1342 * pointer to the PLOGI N_Port @ndlp
1343 **/
James Smart488d1462006-03-07 15:02:37 -05001344static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001345lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001346 struct lpfc_nodelist *ndlp)
1347{
James Smart2e0fef82007-06-17 19:56:36 -05001348 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001349 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001350 struct lpfc_rport_data *rdata;
1351 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001352 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001353 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001354 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001355 int put_node;
1356 int put_rport;
James Smart19ca7602010-11-20 23:11:55 -05001357 struct lpfc_node_rrqs rrq;
James Smart488d1462006-03-07 15:02:37 -05001358
James Smart2fb9bd82006-12-02 13:33:57 -05001359 /* Fabric nodes can have the same WWPN so we don't bother searching
1360 * by WWPN. Just return the ndlp that was given to us.
1361 */
1362 if (ndlp->nlp_type & NLP_FABRIC)
1363 return ndlp;
1364
James Smart92d7f7b2007-06-17 19:56:38 -05001365 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001366 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001367
James Smart685f0bf2007-04-25 09:53:08 -04001368 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001369 * we have for that ndlp. If not, we have some work to do.
1370 */
James Smart2e0fef82007-06-17 19:56:36 -05001371 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001372
James Smarte47c9092008-02-08 18:49:26 -05001373 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001374 return ndlp;
James Smart19ca7602010-11-20 23:11:55 -05001375 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
James Smart488d1462006-03-07 15:02:37 -05001376
1377 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001378 rc = memcmp(&ndlp->nlp_portname, name,
1379 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001380 if (!rc)
1381 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001382 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1383 if (!new_ndlp)
1384 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001385 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001386 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001387 rc = memcmp(&ndlp->nlp_portname, name,
1388 sizeof(struct lpfc_name));
1389 if (!rc)
1390 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001391 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1392 NLP_STE_UNUSED_NODE);
1393 if (!new_ndlp)
1394 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001395 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001396 if (phba->sli_rev == LPFC_SLI_REV4)
1397 memcpy(&rrq.xri_bitmap,
1398 &new_ndlp->active_rrqs.xri_bitmap,
1399 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1400 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001401 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001402 if (phba->sli_rev == LPFC_SLI_REV4)
1403 memcpy(&rrq.xri_bitmap,
1404 &new_ndlp->active_rrqs.xri_bitmap,
1405 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1406 }
James Smart488d1462006-03-07 15:02:37 -05001407
James Smart2e0fef82007-06-17 19:56:36 -05001408 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001409 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001410 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001411 if (phba->sli_rev == LPFC_SLI_REV4)
1412 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1413 &ndlp->active_rrqs.xri_bitmap,
1414 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart0ff10d42008-01-11 01:52:36 -05001415
1416 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1417 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1418 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1419
James Smarte47c9092008-02-08 18:49:26 -05001420 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001421 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001422
James Smart2e0fef82007-06-17 19:56:36 -05001423 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001424 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1425 /* The new_ndlp is replacing ndlp totally, so we need
1426 * to put ndlp on UNUSED list and try to free it.
1427 */
James Smart0ff10d42008-01-11 01:52:36 -05001428
1429 /* Fix up the rport accordingly */
1430 rport = ndlp->rport;
1431 if (rport) {
1432 rdata = rport->dd_data;
1433 if (rdata->pnode == ndlp) {
1434 lpfc_nlp_put(ndlp);
1435 ndlp->rport = NULL;
1436 rdata->pnode = lpfc_nlp_get(new_ndlp);
1437 new_ndlp->rport = rport;
1438 }
1439 new_ndlp->nlp_type = ndlp->nlp_type;
1440 }
James Smart58da1ff2008-04-07 10:15:56 -04001441 /* We shall actually free the ndlp with both nlp_DID and
1442 * nlp_portname fields equals 0 to avoid any ndlp on the
1443 * nodelist never to be used.
1444 */
1445 if (ndlp->nlp_DID == 0) {
1446 spin_lock_irq(&phba->ndlp_lock);
1447 NLP_SET_FREE_REQ(ndlp);
1448 spin_unlock_irq(&phba->ndlp_lock);
1449 }
James Smart0ff10d42008-01-11 01:52:36 -05001450
James Smart58da1ff2008-04-07 10:15:56 -04001451 /* Two ndlps cannot have the same did on the nodelist */
1452 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001453 if (phba->sli_rev == LPFC_SLI_REV4)
1454 memcpy(&ndlp->active_rrqs.xri_bitmap,
1455 &rrq.xri_bitmap,
1456 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001457 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001458 }
James Smart92795652006-07-06 15:50:02 -04001459 else {
James Smart2e0fef82007-06-17 19:56:36 -05001460 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001461 /* Two ndlps cannot have the same did */
1462 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001463 if (phba->sli_rev == LPFC_SLI_REV4)
1464 memcpy(&ndlp->active_rrqs.xri_bitmap,
1465 &rrq.xri_bitmap,
1466 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001467 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart38b92ef2010-08-04 16:11:39 -04001468 /* Since we are swapping the ndlp passed in with the new one
1469 * and the did has already been swapped, copy over the
1470 * state and names.
1471 */
1472 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1473 sizeof(struct lpfc_name));
1474 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1475 sizeof(struct lpfc_name));
1476 new_ndlp->nlp_state = ndlp->nlp_state;
1477 /* Fix up the rport accordingly */
1478 rport = ndlp->rport;
1479 if (rport) {
1480 rdata = rport->dd_data;
1481 put_node = rdata->pnode != NULL;
1482 put_rport = ndlp->rport != NULL;
1483 rdata->pnode = NULL;
1484 ndlp->rport = NULL;
1485 if (put_node)
1486 lpfc_nlp_put(ndlp);
1487 if (put_rport)
1488 put_device(&rport->dev);
1489 }
James Smart92795652006-07-06 15:50:02 -04001490 }
James Smart488d1462006-03-07 15:02:37 -05001491 return new_ndlp;
1492}
1493
James Smarte59058c2008-08-24 21:49:00 -04001494/**
James Smart3621a712009-04-06 18:47:14 -04001495 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001496 * @vport: pointer to a host virtual N_Port data structure.
1497 *
1498 * This routine checks whether more Registration State Change
1499 * Notifications (RSCNs) came in while the discovery state machine was in
1500 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1501 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1502 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1503 * handling the RSCNs.
1504 **/
James Smart87af33f2007-10-27 13:37:43 -04001505void
1506lpfc_end_rscn(struct lpfc_vport *vport)
1507{
1508 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1509
1510 if (vport->fc_flag & FC_RSCN_MODE) {
1511 /*
1512 * Check to see if more RSCNs came in while we were
1513 * processing this one.
1514 */
1515 if (vport->fc_rscn_id_cnt ||
1516 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1517 lpfc_els_handle_rscn(vport);
1518 else {
1519 spin_lock_irq(shost->host_lock);
1520 vport->fc_flag &= ~FC_RSCN_MODE;
1521 spin_unlock_irq(shost->host_lock);
1522 }
1523 }
1524}
1525
James Smarte59058c2008-08-24 21:49:00 -04001526/**
James Smart19ca7602010-11-20 23:11:55 -05001527 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1528 * @phba: pointer to lpfc hba data structure.
1529 * @cmdiocb: pointer to lpfc command iocb data structure.
1530 * @rspiocb: pointer to lpfc response iocb data structure.
1531 *
1532 * This routine will call the clear rrq function to free the rrq and
1533 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1534 * exist then the clear_rrq is still called because the rrq needs to
1535 * be freed.
1536 **/
1537
1538static void
1539lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1540 struct lpfc_iocbq *rspiocb)
1541{
1542 struct lpfc_vport *vport = cmdiocb->vport;
1543 IOCB_t *irsp;
1544 struct lpfc_nodelist *ndlp;
1545 struct lpfc_node_rrq *rrq;
1546
1547 /* we pass cmdiocb to state machine which needs rspiocb as well */
1548 rrq = cmdiocb->context_un.rrq;
1549 cmdiocb->context_un.rsp_iocb = rspiocb;
1550
1551 irsp = &rspiocb->iocb;
1552 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1553 "RRQ cmpl: status:x%x/x%x did:x%x",
1554 irsp->ulpStatus, irsp->un.ulpWord[4],
1555 irsp->un.elsreq64.remoteID);
1556
1557 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1558 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1559 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1560 "2882 RRQ completes to NPort x%x "
1561 "with no ndlp. Data: x%x x%x x%x\n",
1562 irsp->un.elsreq64.remoteID,
1563 irsp->ulpStatus, irsp->un.ulpWord[4],
1564 irsp->ulpIoTag);
1565 goto out;
1566 }
1567
1568 /* rrq completes to NPort <nlp_DID> */
1569 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1570 "2880 RRQ completes to NPort x%x "
1571 "Data: x%x x%x x%x x%x x%x\n",
1572 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1573 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1574
1575 if (irsp->ulpStatus) {
1576 /* Check for retry */
1577 /* RRQ failed Don't print the vport to vport rjts */
1578 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1579 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1580 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1581 (phba)->pport->cfg_log_verbose & LOG_ELS)
1582 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1583 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1584 ndlp->nlp_DID, irsp->ulpStatus,
1585 irsp->un.ulpWord[4]);
1586 }
1587out:
1588 if (rrq)
1589 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1590 lpfc_els_free_iocb(phba, cmdiocb);
1591 return;
1592}
1593/**
James Smart3621a712009-04-06 18:47:14 -04001594 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001595 * @phba: pointer to lpfc hba data structure.
1596 * @cmdiocb: pointer to lpfc command iocb data structure.
1597 * @rspiocb: pointer to lpfc response iocb data structure.
1598 *
1599 * This routine is the completion callback function for issuing the Port
1600 * Login (PLOGI) command. For PLOGI completion, there must be an active
1601 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001602 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001603 * ignored and command IOCB released. The PLOGI response IOCB status is
1604 * checked for error conditons. If there is error status reported, PLOGI
1605 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1606 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1607 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1608 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1609 * there are additional N_Port nodes with the vport that need to perform
1610 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1611 * PLOGIs.
1612 **/
dea31012005-04-17 16:05:31 -05001613static void
James Smart2e0fef82007-06-17 19:56:36 -05001614lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1615 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001616{
James Smart2e0fef82007-06-17 19:56:36 -05001617 struct lpfc_vport *vport = cmdiocb->vport;
1618 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001619 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001620 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001621 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001622 int disc, rc, did, type;
1623
dea31012005-04-17 16:05:31 -05001624 /* we pass cmdiocb to state machine which needs rspiocb as well */
1625 cmdiocb->context_un.rsp_iocb = rspiocb;
1626
1627 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001628 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1629 "PLOGI cmpl: status:x%x/x%x did:x%x",
1630 irsp->ulpStatus, irsp->un.ulpWord[4],
1631 irsp->un.elsreq64.remoteID);
1632
James Smart2e0fef82007-06-17 19:56:36 -05001633 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001634 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001635 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1636 "0136 PLOGI completes to NPort x%x "
1637 "with no ndlp. Data: x%x x%x x%x\n",
1638 irsp->un.elsreq64.remoteID,
1639 irsp->ulpStatus, irsp->un.ulpWord[4],
1640 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001641 goto out;
James Smarted957682007-06-17 19:56:37 -05001642 }
dea31012005-04-17 16:05:31 -05001643
1644 /* Since ndlp can be freed in the disc state machine, note if this node
1645 * is being used during discovery.
1646 */
James Smart2e0fef82007-06-17 19:56:36 -05001647 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001648 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001649 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001650 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001651 rc = 0;
1652
1653 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001654 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1655 "0102 PLOGI completes to NPort x%x "
1656 "Data: x%x x%x x%x x%x x%x\n",
1657 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1658 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001659 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001660 if (lpfc_els_chk_latt(vport)) {
1661 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001662 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001663 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001664 goto out;
1665 }
1666
1667 /* ndlp could be freed in DSM, save these values now */
1668 type = ndlp->nlp_type;
1669 did = ndlp->nlp_DID;
1670
1671 if (irsp->ulpStatus) {
1672 /* Check for retry */
1673 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1674 /* ELS command is being retried */
1675 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001676 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001677 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001678 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001679 }
1680 goto out;
1681 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001682 /* PLOGI failed Don't print the vport to vport rjts */
1683 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1684 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1685 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1686 (phba)->pport->cfg_log_verbose & LOG_ELS)
1687 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001688 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1689 ndlp->nlp_DID, irsp->ulpStatus,
1690 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001691 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001692 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001693 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001694 else
James Smart2e0fef82007-06-17 19:56:36 -05001695 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001696 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001697 } else {
1698 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001699 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001700 cmdiocb->context2)->list.next,
1701 struct lpfc_dmabuf, list);
1702 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001703 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001704 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001705 }
1706
James Smart2e0fef82007-06-17 19:56:36 -05001707 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001708 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001709 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001710
James Smart2e0fef82007-06-17 19:56:36 -05001711 if (vport->num_disc_nodes == 0) {
1712 spin_lock_irq(shost->host_lock);
1713 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1714 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001715
James Smart2e0fef82007-06-17 19:56:36 -05001716 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001717 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001718 }
1719 }
1720
1721out:
1722 lpfc_els_free_iocb(phba, cmdiocb);
1723 return;
1724}
1725
James Smarte59058c2008-08-24 21:49:00 -04001726/**
James Smart3621a712009-04-06 18:47:14 -04001727 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001728 * @vport: pointer to a host virtual N_Port data structure.
1729 * @did: destination port identifier.
1730 * @retry: number of retries to the command IOCB.
1731 *
1732 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1733 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1734 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1735 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1736 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1737 *
1738 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1739 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1740 * will be stored into the context1 field of the IOCB for the completion
1741 * callback function to the PLOGI ELS command.
1742 *
1743 * Return code
1744 * 0 - Successfully issued a plogi for @vport
1745 * 1 - failed to issue a plogi for @vport
1746 **/
dea31012005-04-17 16:05:31 -05001747int
James Smart2e0fef82007-06-17 19:56:36 -05001748lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001749{
James Smart2e0fef82007-06-17 19:56:36 -05001750 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001751 struct serv_parm *sp;
1752 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001753 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001754 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001755 struct lpfc_sli *psli;
1756 uint8_t *pcmd;
1757 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001758 int ret;
dea31012005-04-17 16:05:31 -05001759
1760 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001761
James Smart98c9ea52007-10-27 13:37:33 -04001762 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001763 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1764 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001765
James Smarte47c9092008-02-08 18:49:26 -05001766 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001767 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001768 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001769 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001770 if (!elsiocb)
1771 return 1;
dea31012005-04-17 16:05:31 -05001772
1773 icmd = &elsiocb->iocb;
1774 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1775
1776 /* For PLOGI request, remainder of payload is service parameters */
1777 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001778 pcmd += sizeof(uint32_t);
1779 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001780 sp = (struct serv_parm *) pcmd;
1781
James Smart5ac6b302010-10-22 11:05:36 -04001782 /*
1783 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1784 * to device on remote loops work.
1785 */
1786 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1787 sp->cmn.altBbCredit = 1;
1788
dea31012005-04-17 16:05:31 -05001789 if (sp->cmn.fcphLow < FC_PH_4_3)
1790 sp->cmn.fcphLow = FC_PH_4_3;
1791
1792 if (sp->cmn.fcphHigh < FC_PH3)
1793 sp->cmn.fcphHigh = FC_PH3;
1794
James Smart858c9f62007-06-17 19:56:39 -05001795 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1796 "Issue PLOGI: did:x%x",
1797 did, 0, 0);
1798
dea31012005-04-17 16:05:31 -05001799 phba->fc_stat.elsXmitPLOGI++;
1800 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001801 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001802
1803 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001804 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001805 return 1;
dea31012005-04-17 16:05:31 -05001806 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001807 return 0;
dea31012005-04-17 16:05:31 -05001808}
1809
James Smarte59058c2008-08-24 21:49:00 -04001810/**
James Smart3621a712009-04-06 18:47:14 -04001811 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001812 * @phba: pointer to lpfc hba data structure.
1813 * @cmdiocb: pointer to lpfc command iocb data structure.
1814 * @rspiocb: pointer to lpfc response iocb data structure.
1815 *
1816 * This routine is the completion callback function for a Process Login
1817 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1818 * status. If there is error status reported, PRLI retry shall be attempted
1819 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1820 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1821 * ndlp to mark the PRLI completion.
1822 **/
dea31012005-04-17 16:05:31 -05001823static void
James Smart2e0fef82007-06-17 19:56:36 -05001824lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1825 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001826{
James Smart2e0fef82007-06-17 19:56:36 -05001827 struct lpfc_vport *vport = cmdiocb->vport;
1828 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001829 IOCB_t *irsp;
1830 struct lpfc_sli *psli;
1831 struct lpfc_nodelist *ndlp;
1832
1833 psli = &phba->sli;
1834 /* we pass cmdiocb to state machine which needs rspiocb as well */
1835 cmdiocb->context_un.rsp_iocb = rspiocb;
1836
1837 irsp = &(rspiocb->iocb);
1838 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001839 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001840 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001841 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001842
James Smart858c9f62007-06-17 19:56:39 -05001843 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1844 "PRLI cmpl: status:x%x/x%x did:x%x",
1845 irsp->ulpStatus, irsp->un.ulpWord[4],
1846 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001847 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001848 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1849 "0103 PRLI completes to NPort x%x "
1850 "Data: x%x x%x x%x x%x\n",
1851 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1852 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001853
James Smart2e0fef82007-06-17 19:56:36 -05001854 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001855 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001856 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001857 goto out;
1858
1859 if (irsp->ulpStatus) {
1860 /* Check for retry */
1861 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1862 /* ELS command is being retried */
1863 goto out;
1864 }
1865 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001866 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1867 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1868 ndlp->nlp_DID, irsp->ulpStatus,
1869 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001870 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001871 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001872 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001873 else
James Smart2e0fef82007-06-17 19:56:36 -05001874 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001875 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001876 } else
dea31012005-04-17 16:05:31 -05001877 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001878 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001879 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001880out:
1881 lpfc_els_free_iocb(phba, cmdiocb);
1882 return;
1883}
1884
James Smarte59058c2008-08-24 21:49:00 -04001885/**
James Smart3621a712009-04-06 18:47:14 -04001886 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001887 * @vport: pointer to a host virtual N_Port data structure.
1888 * @ndlp: pointer to a node-list data structure.
1889 * @retry: number of retries to the command IOCB.
1890 *
1891 * This routine issues a Process Login (PRLI) ELS command for the
1892 * @vport. The PRLI service parameters are set up in the payload of the
1893 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1894 * is put to the IOCB completion callback func field before invoking the
1895 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1896 *
1897 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1898 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1899 * will be stored into the context1 field of the IOCB for the completion
1900 * callback function to the PRLI ELS command.
1901 *
1902 * Return code
1903 * 0 - successfully issued prli iocb command for @vport
1904 * 1 - failed to issue prli iocb command for @vport
1905 **/
dea31012005-04-17 16:05:31 -05001906int
James Smart2e0fef82007-06-17 19:56:36 -05001907lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001908 uint8_t retry)
1909{
James Smart2e0fef82007-06-17 19:56:36 -05001910 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1911 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001912 PRLI *npr;
1913 IOCB_t *icmd;
1914 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001915 uint8_t *pcmd;
1916 uint16_t cmdsize;
1917
James Smart92d7f7b2007-06-17 19:56:38 -05001918 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001919 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1920 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001921 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001922 return 1;
dea31012005-04-17 16:05:31 -05001923
1924 icmd = &elsiocb->iocb;
1925 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1926
1927 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001928 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001929 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001930 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001931
1932 /* For PRLI, remainder of payload is PRLI parameter page */
1933 npr = (PRLI *) pcmd;
1934 /*
1935 * If our firmware version is 3.20 or later,
1936 * set the following bits for FC-TAPE support.
1937 */
1938 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1939 npr->ConfmComplAllowed = 1;
1940 npr->Retry = 1;
1941 npr->TaskRetryIdReq = 1;
1942 }
1943 npr->estabImagePair = 1;
1944 npr->readXferRdyDis = 1;
1945
1946 /* For FCP support */
1947 npr->prliType = PRLI_FCP_TYPE;
1948 npr->initiatorFunc = 1;
1949
James Smart858c9f62007-06-17 19:56:39 -05001950 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1951 "Issue PRLI: did:x%x",
1952 ndlp->nlp_DID, 0, 0);
1953
dea31012005-04-17 16:05:31 -05001954 phba->fc_stat.elsXmitPRLI++;
1955 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001956 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001957 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001958 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001959 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1960 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001961 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001962 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001963 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001964 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001965 return 1;
dea31012005-04-17 16:05:31 -05001966 }
James Smart2e0fef82007-06-17 19:56:36 -05001967 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001968 return 0;
dea31012005-04-17 16:05:31 -05001969}
1970
James Smarte59058c2008-08-24 21:49:00 -04001971/**
James Smart3621a712009-04-06 18:47:14 -04001972 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001973 * @vport: pointer to a host virtual N_Port data structure.
1974 *
1975 * This routine performs Registration State Change Notification (RSCN)
1976 * discovery for a @vport. If the @vport's node port recovery count is not
1977 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1978 * the nodes that need recovery. If none of the PLOGI were needed through
1979 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1980 * invoked to check and handle possible more RSCN came in during the period
1981 * of processing the current ones.
1982 **/
1983static void
1984lpfc_rscn_disc(struct lpfc_vport *vport)
1985{
1986 lpfc_can_disctmo(vport);
1987
1988 /* RSCN discovery */
1989 /* go thru NPR nodes and issue ELS PLOGIs */
1990 if (vport->fc_npr_cnt)
1991 if (lpfc_els_disc_plogi(vport))
1992 return;
1993
1994 lpfc_end_rscn(vport);
1995}
1996
1997/**
James Smart3621a712009-04-06 18:47:14 -04001998 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001999 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2000 *
2001 * This function is called when the final ADISC is completed during discovery.
2002 * This function handles clearing link attention or issuing reg_vpi depending
2003 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2004 * discovery.
2005 * This function is called with no locks held.
2006 **/
2007static void
2008lpfc_adisc_done(struct lpfc_vport *vport)
2009{
2010 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2011 struct lpfc_hba *phba = vport->phba;
2012
2013 /*
2014 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2015 * and continue discovery.
2016 */
2017 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002018 !(vport->fc_flag & FC_RSCN_MODE) &&
2019 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04002020 lpfc_issue_reg_vpi(phba, vport);
2021 return;
2022 }
2023 /*
2024 * For SLI2, we need to set port_state to READY
2025 * and continue discovery.
2026 */
2027 if (vport->port_state < LPFC_VPORT_READY) {
2028 /* If we get here, there is nothing to ADISC */
2029 if (vport->port_type == LPFC_PHYSICAL_PORT)
2030 lpfc_issue_clear_la(phba, vport);
2031 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2032 vport->num_disc_nodes = 0;
2033 /* go thru NPR list, issue ELS PLOGIs */
2034 if (vport->fc_npr_cnt)
2035 lpfc_els_disc_plogi(vport);
2036 if (!vport->num_disc_nodes) {
2037 spin_lock_irq(shost->host_lock);
2038 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2039 spin_unlock_irq(shost->host_lock);
2040 lpfc_can_disctmo(vport);
2041 lpfc_end_rscn(vport);
2042 }
2043 }
2044 vport->port_state = LPFC_VPORT_READY;
2045 } else
2046 lpfc_rscn_disc(vport);
2047}
2048
2049/**
James Smart3621a712009-04-06 18:47:14 -04002050 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002051 * @vport: pointer to a host virtual N_Port data structure.
2052 *
2053 * This routine determines whether there are more ndlps on a @vport
2054 * node list need to have Address Discover (ADISC) issued. If so, it will
2055 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2056 * remaining nodes which need to have ADISC sent.
2057 **/
James Smart0ff10d42008-01-11 01:52:36 -05002058void
James Smart2e0fef82007-06-17 19:56:36 -05002059lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002060{
2061 int sentadisc;
2062
James Smart2e0fef82007-06-17 19:56:36 -05002063 if (vport->num_disc_nodes)
2064 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002065 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002066 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2067 "0210 Continue discovery with %d ADISCs to go "
2068 "Data: x%x x%x x%x\n",
2069 vport->num_disc_nodes, vport->fc_adisc_cnt,
2070 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002071 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002072 if (vport->fc_flag & FC_NLP_MORE) {
2073 lpfc_set_disctmo(vport);
2074 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2075 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002076 }
James Smart90160e02008-08-24 21:49:45 -04002077 if (!vport->num_disc_nodes)
2078 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002079 return;
2080}
2081
James Smarte59058c2008-08-24 21:49:00 -04002082/**
James Smart3621a712009-04-06 18:47:14 -04002083 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002084 * @phba: pointer to lpfc hba data structure.
2085 * @cmdiocb: pointer to lpfc command iocb data structure.
2086 * @rspiocb: pointer to lpfc response iocb data structure.
2087 *
2088 * This routine is the completion function for issuing the Address Discover
2089 * (ADISC) command. It first checks to see whether link went down during
2090 * the discovery process. If so, the node will be marked as node port
2091 * recovery for issuing discover IOCB by the link attention handler and
2092 * exit. Otherwise, the response status is checked. If error was reported
2093 * in the response status, the ADISC command shall be retried by invoking
2094 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2095 * the response status, the state machine is invoked to set transition
2096 * with respect to NLP_EVT_CMPL_ADISC event.
2097 **/
dea31012005-04-17 16:05:31 -05002098static void
James Smart2e0fef82007-06-17 19:56:36 -05002099lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2100 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002101{
James Smart2e0fef82007-06-17 19:56:36 -05002102 struct lpfc_vport *vport = cmdiocb->vport;
2103 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002104 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002105 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002106 int disc;
dea31012005-04-17 16:05:31 -05002107
2108 /* we pass cmdiocb to state machine which needs rspiocb as well */
2109 cmdiocb->context_un.rsp_iocb = rspiocb;
2110
2111 irsp = &(rspiocb->iocb);
2112 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002113
James Smart858c9f62007-06-17 19:56:39 -05002114 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2115 "ADISC cmpl: status:x%x/x%x did:x%x",
2116 irsp->ulpStatus, irsp->un.ulpWord[4],
2117 ndlp->nlp_DID);
2118
dea31012005-04-17 16:05:31 -05002119 /* Since ndlp can be freed in the disc state machine, note if this node
2120 * is being used during discovery.
2121 */
James Smart2e0fef82007-06-17 19:56:36 -05002122 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002123 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002124 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002125 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002126 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002127 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2128 "0104 ADISC completes to NPort x%x "
2129 "Data: x%x x%x x%x x%x x%x\n",
2130 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2131 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002132 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002133 if (lpfc_els_chk_latt(vport)) {
2134 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002135 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002136 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002137 goto out;
2138 }
2139
2140 if (irsp->ulpStatus) {
2141 /* Check for retry */
2142 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2143 /* ELS command is being retried */
2144 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002145 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002146 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002147 spin_unlock_irq(shost->host_lock);
2148 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002149 }
2150 goto out;
2151 }
2152 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002153 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2154 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2155 ndlp->nlp_DID, irsp->ulpStatus,
2156 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002157 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002158 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002159 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002160 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002161 } else
dea31012005-04-17 16:05:31 -05002162 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002163 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002164 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002165
James Smart90160e02008-08-24 21:49:45 -04002166 /* Check to see if there are more ADISCs to be sent */
2167 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002168 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002169out:
2170 lpfc_els_free_iocb(phba, cmdiocb);
2171 return;
2172}
2173
James Smarte59058c2008-08-24 21:49:00 -04002174/**
James Smart3621a712009-04-06 18:47:14 -04002175 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002176 * @vport: pointer to a virtual N_Port data structure.
2177 * @ndlp: pointer to a node-list data structure.
2178 * @retry: number of retries to the command IOCB.
2179 *
2180 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2181 * @vport. It prepares the payload of the ADISC ELS command, updates the
2182 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2183 * to issue the ADISC ELS command.
2184 *
2185 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2186 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2187 * will be stored into the context1 field of the IOCB for the completion
2188 * callback function to the ADISC ELS command.
2189 *
2190 * Return code
2191 * 0 - successfully issued adisc
2192 * 1 - failed to issue adisc
2193 **/
dea31012005-04-17 16:05:31 -05002194int
James Smart2e0fef82007-06-17 19:56:36 -05002195lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002196 uint8_t retry)
2197{
James Smart2e0fef82007-06-17 19:56:36 -05002198 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2199 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002200 ADISC *ap;
2201 IOCB_t *icmd;
2202 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002203 uint8_t *pcmd;
2204 uint16_t cmdsize;
2205
James Smart92d7f7b2007-06-17 19:56:38 -05002206 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002207 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2208 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002209 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002210 return 1;
dea31012005-04-17 16:05:31 -05002211
2212 icmd = &elsiocb->iocb;
2213 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2214
2215 /* For ADISC request, remainder of payload is service parameters */
2216 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002217 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002218
2219 /* Fill in ADISC payload */
2220 ap = (ADISC *) pcmd;
2221 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002222 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2223 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002224 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002225
James Smart858c9f62007-06-17 19:56:39 -05002226 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2227 "Issue ADISC: did:x%x",
2228 ndlp->nlp_DID, 0, 0);
2229
dea31012005-04-17 16:05:31 -05002230 phba->fc_stat.elsXmitADISC++;
2231 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002232 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002233 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002234 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002235 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2236 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002237 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002238 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002239 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002240 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002241 return 1;
dea31012005-04-17 16:05:31 -05002242 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002243 return 0;
dea31012005-04-17 16:05:31 -05002244}
2245
James Smarte59058c2008-08-24 21:49:00 -04002246/**
James Smart3621a712009-04-06 18:47:14 -04002247 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002248 * @phba: pointer to lpfc hba data structure.
2249 * @cmdiocb: pointer to lpfc command iocb data structure.
2250 * @rspiocb: pointer to lpfc response iocb data structure.
2251 *
2252 * This routine is the completion function for issuing the ELS Logout (LOGO)
2253 * command. If no error status was reported from the LOGO response, the
2254 * state machine of the associated ndlp shall be invoked for transition with
2255 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2256 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2257 **/
dea31012005-04-17 16:05:31 -05002258static void
James Smart2e0fef82007-06-17 19:56:36 -05002259lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2260 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002261{
James Smart2e0fef82007-06-17 19:56:36 -05002262 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2263 struct lpfc_vport *vport = ndlp->vport;
2264 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002265 IOCB_t *irsp;
2266 struct lpfc_sli *psli;
James Smart92494142011-02-16 12:39:44 -05002267 struct lpfcMboxq *mbox;
dea31012005-04-17 16:05:31 -05002268
2269 psli = &phba->sli;
2270 /* we pass cmdiocb to state machine which needs rspiocb as well */
2271 cmdiocb->context_un.rsp_iocb = rspiocb;
2272
2273 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002274 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002275 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002276 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002277
James Smart858c9f62007-06-17 19:56:39 -05002278 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2279 "LOGO cmpl: status:x%x/x%x did:x%x",
2280 irsp->ulpStatus, irsp->un.ulpWord[4],
2281 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002282 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002283 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2284 "0105 LOGO completes to NPort x%x "
2285 "Data: x%x x%x x%x x%x\n",
2286 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2287 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002288 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002289 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002290 goto out;
2291
James Smart92d7f7b2007-06-17 19:56:38 -05002292 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2293 /* NLP_EVT_DEVICE_RM should unregister the RPI
2294 * which should abort all outstanding IOs.
2295 */
2296 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2297 NLP_EVT_DEVICE_RM);
2298 goto out;
2299 }
2300
dea31012005-04-17 16:05:31 -05002301 if (irsp->ulpStatus) {
2302 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002303 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002304 /* ELS command is being retried */
2305 goto out;
dea31012005-04-17 16:05:31 -05002306 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002307 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2308 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2309 ndlp->nlp_DID, irsp->ulpStatus,
2310 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002311 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002312 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002313 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002314 else
James Smart2e0fef82007-06-17 19:56:36 -05002315 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002316 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002317 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002318 /* Good status, call state machine.
2319 * This will unregister the rpi if needed.
2320 */
James Smart2e0fef82007-06-17 19:56:36 -05002321 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002322 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002323out:
2324 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002325 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2326 if ((vport->fc_flag & FC_PT2PT) &&
2327 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2328 phba->pport->fc_myDID = 0;
2329 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2330 if (mbox) {
2331 lpfc_config_link(phba, mbox);
2332 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2333 mbox->vport = vport;
2334 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2335 MBX_NOT_FINISHED) {
2336 mempool_free(mbox, phba->mbox_mem_pool);
2337 }
2338 }
2339 }
dea31012005-04-17 16:05:31 -05002340 return;
2341}
2342
James Smarte59058c2008-08-24 21:49:00 -04002343/**
James Smart3621a712009-04-06 18:47:14 -04002344 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002345 * @vport: pointer to a virtual N_Port data structure.
2346 * @ndlp: pointer to a node-list data structure.
2347 * @retry: number of retries to the command IOCB.
2348 *
2349 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2350 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2351 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2352 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2353 *
2354 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2355 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2356 * will be stored into the context1 field of the IOCB for the completion
2357 * callback function to the LOGO ELS command.
2358 *
2359 * Return code
2360 * 0 - successfully issued logo
2361 * 1 - failed to issue logo
2362 **/
dea31012005-04-17 16:05:31 -05002363int
James Smart2e0fef82007-06-17 19:56:36 -05002364lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002365 uint8_t retry)
2366{
James Smart2e0fef82007-06-17 19:56:36 -05002367 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2368 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002369 IOCB_t *icmd;
2370 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002371 uint8_t *pcmd;
2372 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002373 int rc;
dea31012005-04-17 16:05:31 -05002374
James Smart98c9ea52007-10-27 13:37:33 -04002375 spin_lock_irq(shost->host_lock);
2376 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2377 spin_unlock_irq(shost->host_lock);
2378 return 0;
2379 }
2380 spin_unlock_irq(shost->host_lock);
2381
James Smart92d7f7b2007-06-17 19:56:38 -05002382 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002383 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2384 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002385 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002386 return 1;
dea31012005-04-17 16:05:31 -05002387
2388 icmd = &elsiocb->iocb;
2389 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2390 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002391 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002392
2393 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002394 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002395 pcmd += sizeof(uint32_t);
2396 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002397
James Smart858c9f62007-06-17 19:56:39 -05002398 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2399 "Issue LOGO: did:x%x",
2400 ndlp->nlp_DID, 0, 0);
2401
dea31012005-04-17 16:05:31 -05002402 phba->fc_stat.elsXmitLOGO++;
2403 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002404 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002405 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002406 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002407 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002408
2409 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002410 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002411 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002412 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002413 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002414 return 1;
dea31012005-04-17 16:05:31 -05002415 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002416 return 0;
dea31012005-04-17 16:05:31 -05002417}
2418
James Smarte59058c2008-08-24 21:49:00 -04002419/**
James Smart3621a712009-04-06 18:47:14 -04002420 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002421 * @phba: pointer to lpfc hba data structure.
2422 * @cmdiocb: pointer to lpfc command iocb data structure.
2423 * @rspiocb: pointer to lpfc response iocb data structure.
2424 *
2425 * This routine is a generic completion callback function for ELS commands.
2426 * Specifically, it is the callback function which does not need to perform
2427 * any command specific operations. It is currently used by the ELS command
2428 * issuing routines for the ELS State Change Request (SCR),
2429 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2430 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2431 * certain debug loggings, this callback function simply invokes the
2432 * lpfc_els_chk_latt() routine to check whether link went down during the
2433 * discovery process.
2434 **/
dea31012005-04-17 16:05:31 -05002435static void
James Smart2e0fef82007-06-17 19:56:36 -05002436lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2437 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002438{
James Smart2e0fef82007-06-17 19:56:36 -05002439 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002440 IOCB_t *irsp;
2441
2442 irsp = &rspiocb->iocb;
2443
James Smart858c9f62007-06-17 19:56:39 -05002444 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2445 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2446 irsp->ulpStatus, irsp->un.ulpWord[4],
2447 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002448 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002449 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2450 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2451 irsp->ulpIoTag, irsp->ulpStatus,
2452 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002453 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002454 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002455 lpfc_els_free_iocb(phba, cmdiocb);
2456 return;
2457}
2458
James Smarte59058c2008-08-24 21:49:00 -04002459/**
James Smart3621a712009-04-06 18:47:14 -04002460 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002461 * @vport: pointer to a host virtual N_Port data structure.
2462 * @nportid: N_Port identifier to the remote node.
2463 * @retry: number of retries to the command IOCB.
2464 *
2465 * This routine issues a State Change Request (SCR) to a fabric node
2466 * on a @vport. The remote node @nportid is passed into the function. It
2467 * first search the @vport node list to find the matching ndlp. If no such
2468 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2469 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2470 * routine is invoked to send the SCR IOCB.
2471 *
2472 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2473 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2474 * will be stored into the context1 field of the IOCB for the completion
2475 * callback function to the SCR ELS command.
2476 *
2477 * Return code
2478 * 0 - Successfully issued scr command
2479 * 1 - Failed to issue scr command
2480 **/
dea31012005-04-17 16:05:31 -05002481int
James Smart2e0fef82007-06-17 19:56:36 -05002482lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002483{
James Smart2e0fef82007-06-17 19:56:36 -05002484 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002485 IOCB_t *icmd;
2486 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002487 struct lpfc_sli *psli;
2488 uint8_t *pcmd;
2489 uint16_t cmdsize;
2490 struct lpfc_nodelist *ndlp;
2491
2492 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002493 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002494
James Smarte47c9092008-02-08 18:49:26 -05002495 ndlp = lpfc_findnode_did(vport, nportid);
2496 if (!ndlp) {
2497 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2498 if (!ndlp)
2499 return 1;
2500 lpfc_nlp_init(vport, ndlp, nportid);
2501 lpfc_enqueue_node(vport, ndlp);
2502 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2503 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2504 if (!ndlp)
2505 return 1;
2506 }
dea31012005-04-17 16:05:31 -05002507
James Smart2e0fef82007-06-17 19:56:36 -05002508 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2509 ndlp->nlp_DID, ELS_CMD_SCR);
2510
James Smart488d1462006-03-07 15:02:37 -05002511 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002512 /* This will trigger the release of the node just
2513 * allocated
2514 */
James Smart329f9bc2007-04-25 09:53:01 -04002515 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002516 return 1;
dea31012005-04-17 16:05:31 -05002517 }
2518
2519 icmd = &elsiocb->iocb;
2520 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2521
2522 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002523 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002524
2525 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002526 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002527 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2528
James Smart858c9f62007-06-17 19:56:39 -05002529 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2530 "Issue SCR: did:x%x",
2531 ndlp->nlp_DID, 0, 0);
2532
dea31012005-04-17 16:05:31 -05002533 phba->fc_stat.elsXmitSCR++;
2534 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002535 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2536 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002537 /* The additional lpfc_nlp_put will cause the following
2538 * lpfc_els_free_iocb routine to trigger the rlease of
2539 * the node.
2540 */
James Smart329f9bc2007-04-25 09:53:01 -04002541 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002542 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002543 return 1;
dea31012005-04-17 16:05:31 -05002544 }
James Smartfa4066b2008-01-11 01:53:27 -05002545 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2546 * trigger the release of node.
2547 */
James Smart329f9bc2007-04-25 09:53:01 -04002548 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002549 return 0;
dea31012005-04-17 16:05:31 -05002550}
2551
James Smarte59058c2008-08-24 21:49:00 -04002552/**
James Smart3621a712009-04-06 18:47:14 -04002553 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002554 * @vport: pointer to a host virtual N_Port data structure.
2555 * @nportid: N_Port identifier to the remote node.
2556 * @retry: number of retries to the command IOCB.
2557 *
2558 * This routine issues a Fibre Channel Address Resolution Response
2559 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2560 * is passed into the function. It first search the @vport node list to find
2561 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2562 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2563 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2564 *
2565 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2566 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2567 * will be stored into the context1 field of the IOCB for the completion
2568 * callback function to the PARPR ELS command.
2569 *
2570 * Return code
2571 * 0 - Successfully issued farpr command
2572 * 1 - Failed to issue farpr command
2573 **/
dea31012005-04-17 16:05:31 -05002574static int
James Smart2e0fef82007-06-17 19:56:36 -05002575lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002576{
James Smart2e0fef82007-06-17 19:56:36 -05002577 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002578 IOCB_t *icmd;
2579 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002580 struct lpfc_sli *psli;
2581 FARP *fp;
2582 uint8_t *pcmd;
2583 uint32_t *lp;
2584 uint16_t cmdsize;
2585 struct lpfc_nodelist *ondlp;
2586 struct lpfc_nodelist *ndlp;
2587
2588 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002589 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002590
James Smarte47c9092008-02-08 18:49:26 -05002591 ndlp = lpfc_findnode_did(vport, nportid);
2592 if (!ndlp) {
2593 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2594 if (!ndlp)
2595 return 1;
2596 lpfc_nlp_init(vport, ndlp, nportid);
2597 lpfc_enqueue_node(vport, ndlp);
2598 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2599 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2600 if (!ndlp)
2601 return 1;
2602 }
James Smart2e0fef82007-06-17 19:56:36 -05002603
2604 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2605 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002606 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002607 /* This will trigger the release of the node just
2608 * allocated
2609 */
James Smart329f9bc2007-04-25 09:53:01 -04002610 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002611 return 1;
dea31012005-04-17 16:05:31 -05002612 }
2613
2614 icmd = &elsiocb->iocb;
2615 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2616
2617 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002618 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002619
2620 /* Fill in FARPR payload */
2621 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002622 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002623 lp = (uint32_t *) pcmd;
2624 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002625 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002626 fp->Rflags = 0;
2627 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2628
James Smart92d7f7b2007-06-17 19:56:38 -05002629 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2630 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002631 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002632 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002633 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002634 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002635 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002636 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002637 }
2638
James Smart858c9f62007-06-17 19:56:39 -05002639 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2640 "Issue FARPR: did:x%x",
2641 ndlp->nlp_DID, 0, 0);
2642
dea31012005-04-17 16:05:31 -05002643 phba->fc_stat.elsXmitFARPR++;
2644 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002645 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2646 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002647 /* The additional lpfc_nlp_put will cause the following
2648 * lpfc_els_free_iocb routine to trigger the release of
2649 * the node.
2650 */
James Smart329f9bc2007-04-25 09:53:01 -04002651 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002652 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002653 return 1;
dea31012005-04-17 16:05:31 -05002654 }
James Smartfa4066b2008-01-11 01:53:27 -05002655 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2656 * trigger the release of the node.
2657 */
James Smart329f9bc2007-04-25 09:53:01 -04002658 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002659 return 0;
dea31012005-04-17 16:05:31 -05002660}
2661
James Smarte59058c2008-08-24 21:49:00 -04002662/**
James Smart3621a712009-04-06 18:47:14 -04002663 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002664 * @vport: pointer to a host virtual N_Port data structure.
2665 * @nlp: pointer to a node-list data structure.
2666 *
2667 * This routine cancels the timer with a delayed IOCB-command retry for
2668 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2669 * removes the ELS retry event if it presents. In addition, if the
2670 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2671 * commands are sent for the @vport's nodes that require issuing discovery
2672 * ADISC.
2673 **/
dea31012005-04-17 16:05:31 -05002674void
James Smart2e0fef82007-06-17 19:56:36 -05002675lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002676{
James Smart2e0fef82007-06-17 19:56:36 -05002677 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002678 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002679
James Smart0d2b6b82008-06-14 22:52:47 -04002680 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2681 return;
James Smart2e0fef82007-06-17 19:56:36 -05002682 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002683 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002684 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002685 del_timer_sync(&nlp->nlp_delayfunc);
2686 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002687 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002688 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002689 /* Decrement nlp reference count held for the delayed retry */
2690 evtp = &nlp->els_retry_evt;
2691 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2692 }
James Smartfdcebe22006-03-07 15:04:01 -05002693 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002694 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002695 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002696 spin_unlock_irq(shost->host_lock);
2697 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002698 if (vport->port_state < LPFC_VPORT_READY) {
2699 /* Check if there are more ADISCs to be sent */
2700 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002701 } else {
2702 /* Check if there are more PLOGIs to be sent */
2703 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002704 if (vport->num_disc_nodes == 0) {
2705 spin_lock_irq(shost->host_lock);
2706 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2707 spin_unlock_irq(shost->host_lock);
2708 lpfc_can_disctmo(vport);
2709 lpfc_end_rscn(vport);
2710 }
James Smartfdcebe22006-03-07 15:04:01 -05002711 }
2712 }
2713 }
2714 return;
2715}
2716
James Smarte59058c2008-08-24 21:49:00 -04002717/**
James Smart3621a712009-04-06 18:47:14 -04002718 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002719 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2720 *
2721 * This routine is invoked by the ndlp delayed-function timer to check
2722 * whether there is any pending ELS retry event(s) with the node. If not, it
2723 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2724 * adds the delayed events to the HBA work list and invokes the
2725 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2726 * event. Note that lpfc_nlp_get() is called before posting the event to
2727 * the work list to hold reference count of ndlp so that it guarantees the
2728 * reference to ndlp will still be available when the worker thread gets
2729 * to the event associated with the ndlp.
2730 **/
James Smartfdcebe22006-03-07 15:04:01 -05002731void
dea31012005-04-17 16:05:31 -05002732lpfc_els_retry_delay(unsigned long ptr)
2733{
James Smart2e0fef82007-06-17 19:56:36 -05002734 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2735 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002736 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002737 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002738 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002739
James Smart92d7f7b2007-06-17 19:56:38 -05002740 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002741 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002742 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002743 return;
2744 }
2745
James Smartfa4066b2008-01-11 01:53:27 -05002746 /* We need to hold the node by incrementing the reference
2747 * count until the queued work is done
2748 */
2749 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002750 if (evtp->evt_arg1) {
2751 evtp->evt = LPFC_EVT_ELS_RETRY;
2752 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002753 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002754 }
James Smart92d7f7b2007-06-17 19:56:38 -05002755 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002756 return;
2757}
2758
James Smarte59058c2008-08-24 21:49:00 -04002759/**
James Smart3621a712009-04-06 18:47:14 -04002760 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002761 * @ndlp: pointer to a node-list data structure.
2762 *
2763 * This routine is the worker-thread handler for processing the @ndlp delayed
2764 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2765 * the last ELS command from the associated ndlp and invokes the proper ELS
2766 * function according to the delayed ELS command to retry the command.
2767 **/
dea31012005-04-17 16:05:31 -05002768void
2769lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2770{
James Smart2e0fef82007-06-17 19:56:36 -05002771 struct lpfc_vport *vport = ndlp->vport;
2772 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2773 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002774
James Smart2e0fef82007-06-17 19:56:36 -05002775 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002776 did = ndlp->nlp_DID;
2777 cmd = ndlp->nlp_last_elscmd;
2778 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002779
2780 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002781 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002782 return;
2783 }
2784
2785 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002786 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002787 /*
2788 * If a discovery event readded nlp_delayfunc after timer
2789 * firing and before processing the timer, cancel the
2790 * nlp_delayfunc.
2791 */
2792 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002793 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002794 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002795
2796 switch (cmd) {
2797 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002798 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002799 break;
2800 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002801 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002802 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002803 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002804 }
dea31012005-04-17 16:05:31 -05002805 break;
2806 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002807 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002808 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002809 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002810 }
dea31012005-04-17 16:05:31 -05002811 break;
2812 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002813 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002814 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002815 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002816 }
dea31012005-04-17 16:05:31 -05002817 break;
2818 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002819 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002820 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002821 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002822 }
dea31012005-04-17 16:05:31 -05002823 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002824 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05002825 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
2826 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05002827 break;
dea31012005-04-17 16:05:31 -05002828 }
2829 return;
2830}
2831
James Smarte59058c2008-08-24 21:49:00 -04002832/**
James Smart3621a712009-04-06 18:47:14 -04002833 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002834 * @phba: pointer to lpfc hba data structure.
2835 * @cmdiocb: pointer to lpfc command iocb data structure.
2836 * @rspiocb: pointer to lpfc response iocb data structure.
2837 *
2838 * This routine makes a retry decision on an ELS command IOCB, which has
2839 * failed. The following ELS IOCBs use this function for retrying the command
2840 * when previously issued command responsed with error status: FLOGI, PLOGI,
2841 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2842 * returned error status, it makes the decision whether a retry shall be
2843 * issued for the command, and whether a retry shall be made immediately or
2844 * delayed. In the former case, the corresponding ELS command issuing-function
2845 * is called to retry the command. In the later case, the ELS command shall
2846 * be posted to the ndlp delayed event and delayed function timer set to the
2847 * ndlp for the delayed command issusing.
2848 *
2849 * Return code
2850 * 0 - No retry of els command is made
2851 * 1 - Immediate or delayed retry of els command is made
2852 **/
dea31012005-04-17 16:05:31 -05002853static int
James Smart2e0fef82007-06-17 19:56:36 -05002854lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2855 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002856{
James Smart2e0fef82007-06-17 19:56:36 -05002857 struct lpfc_vport *vport = cmdiocb->vport;
2858 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2859 IOCB_t *irsp = &rspiocb->iocb;
2860 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2861 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002862 uint32_t *elscmd;
2863 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002864 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002865 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002866 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002867 uint32_t did;
dea31012005-04-17 16:05:31 -05002868
James Smart488d1462006-03-07 15:02:37 -05002869
dea31012005-04-17 16:05:31 -05002870 /* Note: context2 may be 0 for internal driver abort
2871 * of delays ELS command.
2872 */
2873
2874 if (pcmd && pcmd->virt) {
2875 elscmd = (uint32_t *) (pcmd->virt);
2876 cmd = *elscmd++;
2877 }
2878
James Smarte47c9092008-02-08 18:49:26 -05002879 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002880 did = ndlp->nlp_DID;
2881 else {
2882 /* We should only hit this case for retrying PLOGI */
2883 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002884 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002885 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2886 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002887 return 1;
2888 }
2889
James Smart858c9f62007-06-17 19:56:39 -05002890 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2891 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2892 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2893
dea31012005-04-17 16:05:31 -05002894 switch (irsp->ulpStatus) {
2895 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05002896 break;
James Smart1151e3e2011-02-16 12:39:35 -05002897 case IOSTAT_REMOTE_STOP:
2898 if (phba->sli_rev == LPFC_SLI_REV4) {
2899 /* This IO was aborted by the target, we don't
2900 * know the rxid and because we did not send the
2901 * ABTS we cannot generate and RRQ.
2902 */
2903 lpfc_set_rrq_active(phba, ndlp,
2904 cmdiocb->sli4_xritag, 0, 0);
2905 }
2906 break;
dea31012005-04-17 16:05:31 -05002907 case IOSTAT_LOCAL_REJECT:
2908 switch ((irsp->un.ulpWord[4] & 0xff)) {
2909 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002910 if (cmd == ELS_CMD_FLOGI) {
2911 if (PCI_DEVICE_ID_HORNET ==
2912 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05002913 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05002914 phba->pport->fc_myDID = 0;
2915 phba->alpa_map[0] = 0;
2916 phba->alpa_map[1] = 0;
2917 }
2918 }
James Smart2e0fef82007-06-17 19:56:36 -05002919 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002920 delay = 1000;
dea31012005-04-17 16:05:31 -05002921 retry = 1;
2922 break;
2923
James Smart92d7f7b2007-06-17 19:56:38 -05002924 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002925 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2926 "0124 Retry illegal cmd x%x "
2927 "retry:x%x delay:x%x\n",
2928 cmd, cmdiocb->retry, delay);
2929 retry = 1;
2930 /* All command's retry policy */
2931 maxretry = 8;
2932 if (cmdiocb->retry > 2)
2933 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002934 break;
2935
dea31012005-04-17 16:05:31 -05002936 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002937 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002938 retry = 1;
2939 if (cmdiocb->retry > 100)
2940 delay = 100;
2941 maxretry = 250;
2942 break;
2943
2944 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002945 delay = 100;
dea31012005-04-17 16:05:31 -05002946 retry = 1;
2947 break;
2948
James Smart858c9f62007-06-17 19:56:39 -05002949 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002950 case IOERR_INVALID_RPI:
2951 retry = 1;
2952 break;
2953 }
2954 break;
2955
2956 case IOSTAT_NPORT_RJT:
2957 case IOSTAT_FABRIC_RJT:
2958 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2959 retry = 1;
2960 break;
2961 }
2962 break;
2963
2964 case IOSTAT_NPORT_BSY:
2965 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002966 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002967 retry = 1;
2968 break;
2969
2970 case IOSTAT_LS_RJT:
2971 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2972 /* Added for Vendor specifc support
2973 * Just keep retrying for these Rsn / Exp codes
2974 */
2975 switch (stat.un.b.lsRjtRsnCode) {
2976 case LSRJT_UNABLE_TPC:
2977 if (stat.un.b.lsRjtRsnCodeExp ==
2978 LSEXP_CMD_IN_PROGRESS) {
2979 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002980 delay = 1000;
dea31012005-04-17 16:05:31 -05002981 maxretry = 48;
2982 }
2983 retry = 1;
2984 break;
2985 }
James Smartffc95492010-06-07 15:23:17 -04002986 if (stat.un.b.lsRjtRsnCodeExp ==
2987 LSEXP_CANT_GIVE_DATA) {
2988 if (cmd == ELS_CMD_PLOGI) {
2989 delay = 1000;
2990 maxretry = 48;
2991 }
2992 retry = 1;
2993 break;
2994 }
dea31012005-04-17 16:05:31 -05002995 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002996 delay = 1000;
dea31012005-04-17 16:05:31 -05002997 maxretry = lpfc_max_els_tries + 1;
2998 retry = 1;
2999 break;
3000 }
James Smart92d7f7b2007-06-17 19:56:38 -05003001 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3002 (cmd == ELS_CMD_FDISC) &&
3003 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003004 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3005 "0125 FDISC Failed (x%x). "
3006 "Fabric out of resources\n",
3007 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003008 lpfc_vport_set_state(vport,
3009 FC_VPORT_NO_FABRIC_RSCS);
3010 }
dea31012005-04-17 16:05:31 -05003011 break;
3012
3013 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003014 if ((cmd == ELS_CMD_PLOGI) ||
3015 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003016 delay = 1000;
dea31012005-04-17 16:05:31 -05003017 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003018 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003019 /* FDISC retry policy */
3020 maxretry = 48;
3021 if (cmdiocb->retry >= 32)
3022 delay = 1000;
dea31012005-04-17 16:05:31 -05003023 }
3024 retry = 1;
3025 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003026
3027 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003028 /* There are some cases where switches return this
3029 * error when they are not ready and should be returning
3030 * Logical Busy. We should delay every time.
3031 */
3032 if (cmd == ELS_CMD_FDISC &&
3033 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3034 maxretry = 3;
3035 delay = 1000;
3036 retry = 1;
3037 break;
3038 }
James Smart92d7f7b2007-06-17 19:56:38 -05003039 case LSRJT_PROTOCOL_ERR:
3040 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3041 (cmd == ELS_CMD_FDISC) &&
3042 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3043 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3044 ) {
James Smarte8b62012007-08-02 11:10:09 -04003045 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003046 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003047 "Fabric Detected Bad WWN\n",
3048 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003049 lpfc_vport_set_state(vport,
3050 FC_VPORT_FABRIC_REJ_WWN);
3051 }
3052 break;
dea31012005-04-17 16:05:31 -05003053 }
3054 break;
3055
3056 case IOSTAT_INTERMED_RSP:
3057 case IOSTAT_BA_RJT:
3058 break;
3059
3060 default:
3061 break;
3062 }
3063
James Smart488d1462006-03-07 15:02:37 -05003064 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003065 retry = 1;
dea31012005-04-17 16:05:31 -05003066
James Smart695a8142010-01-26 23:08:03 -05003067 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart76a95d72010-11-20 23:11:48 -05003068 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003069 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003070 /* FLOGI retry policy */
3071 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04003072 /* retry forever */
3073 maxretry = 0;
3074 if (cmdiocb->retry >= 100)
3075 delay = 5000;
3076 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003077 delay = 1000;
3078 }
3079
James Smart6669f9b2009-10-02 15:16:45 -04003080 cmdiocb->retry++;
3081 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003082 phba->fc_stat.elsRetryExceeded++;
3083 retry = 0;
3084 }
3085
James Smarted957682007-06-17 19:56:37 -05003086 if ((vport->load_flag & FC_UNLOADING) != 0)
3087 retry = 0;
3088
dea31012005-04-17 16:05:31 -05003089 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003090 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3091 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3092 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3093 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3094 "2849 Stop retry ELS command "
3095 "x%x to remote NPORT x%x, "
3096 "Data: x%x x%x\n", cmd, did,
3097 cmdiocb->retry, delay);
3098 return 0;
3099 }
3100 }
dea31012005-04-17 16:05:31 -05003101
3102 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003103 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3104 "0107 Retry ELS command x%x to remote "
3105 "NPORT x%x Data: x%x x%x\n",
3106 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003107
James Smart858c9f62007-06-17 19:56:39 -05003108 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3109 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3110 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
3111 /* Don't reset timer for no resources */
3112
dea31012005-04-17 16:05:31 -05003113 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003114 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003115 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003116 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003117 }
3118
3119 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003120 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003121 phba->fc_stat.elsDelayRetry++;
3122 ndlp->nlp_retry = cmdiocb->retry;
3123
James Smart92d7f7b2007-06-17 19:56:38 -05003124 /* delay is specified in milliseconds */
3125 mod_timer(&ndlp->nlp_delayfunc,
3126 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003127 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003128 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003129 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003130
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003131 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003132 if (cmd == ELS_CMD_PRLI)
3133 lpfc_nlp_set_state(vport, ndlp,
3134 NLP_STE_REG_LOGIN_ISSUE);
3135 else
3136 lpfc_nlp_set_state(vport, ndlp,
3137 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003138 ndlp->nlp_last_elscmd = cmd;
3139
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003140 return 1;
dea31012005-04-17 16:05:31 -05003141 }
3142 switch (cmd) {
3143 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003144 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003145 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003146 case ELS_CMD_FDISC:
3147 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3148 return 1;
dea31012005-04-17 16:05:31 -05003149 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003150 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003151 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003152 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003153 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003154 }
James Smart2e0fef82007-06-17 19:56:36 -05003155 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003156 return 1;
dea31012005-04-17 16:05:31 -05003157 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003158 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003159 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3160 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003161 return 1;
dea31012005-04-17 16:05:31 -05003162 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003163 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003164 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3165 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003166 return 1;
dea31012005-04-17 16:05:31 -05003167 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003168 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003169 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3170 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003171 return 1;
dea31012005-04-17 16:05:31 -05003172 }
3173 }
dea31012005-04-17 16:05:31 -05003174 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003175 if (logerr) {
3176 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3177 "0137 No retry ELS command x%x to remote "
3178 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3179 cmd, did, irsp->ulpStatus,
3180 irsp->un.ulpWord[4]);
3181 }
3182 else {
3183 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003184 "0108 No retry ELS command x%x to remote "
3185 "NPORT x%x Retried:%d Error:x%x/%x\n",
3186 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3187 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003188 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003189 return 0;
dea31012005-04-17 16:05:31 -05003190}
3191
James Smarte59058c2008-08-24 21:49:00 -04003192/**
James Smart3621a712009-04-06 18:47:14 -04003193 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003194 * @phba: pointer to lpfc hba data structure.
3195 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3196 *
3197 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3198 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3199 * checks to see whether there is a lpfc DMA buffer associated with the
3200 * response of the command IOCB. If so, it will be released before releasing
3201 * the lpfc DMA buffer associated with the IOCB itself.
3202 *
3203 * Return code
3204 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3205 **/
James Smart09372822008-01-11 01:52:54 -05003206static int
James Smart87af33f2007-10-27 13:37:43 -04003207lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3208{
3209 struct lpfc_dmabuf *buf_ptr;
3210
James Smarte59058c2008-08-24 21:49:00 -04003211 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003212 if (!list_empty(&buf_ptr1->list)) {
3213 list_remove_head(&buf_ptr1->list, buf_ptr,
3214 struct lpfc_dmabuf,
3215 list);
3216 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3217 kfree(buf_ptr);
3218 }
3219 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3220 kfree(buf_ptr1);
3221 return 0;
3222}
3223
James Smarte59058c2008-08-24 21:49:00 -04003224/**
James Smart3621a712009-04-06 18:47:14 -04003225 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003226 * @phba: pointer to lpfc hba data structure.
3227 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3228 *
3229 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3230 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3231 * pool.
3232 *
3233 * Return code
3234 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3235 **/
James Smart09372822008-01-11 01:52:54 -05003236static int
James Smart87af33f2007-10-27 13:37:43 -04003237lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3238{
3239 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3240 kfree(buf_ptr);
3241 return 0;
3242}
3243
James Smarte59058c2008-08-24 21:49:00 -04003244/**
James Smart3621a712009-04-06 18:47:14 -04003245 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003246 * @phba: pointer to lpfc hba data structure.
3247 * @elsiocb: pointer to lpfc els command iocb data structure.
3248 *
3249 * This routine frees a command IOCB and its associated resources. The
3250 * command IOCB data structure contains the reference to various associated
3251 * resources, these fields must be set to NULL if the associated reference
3252 * not present:
3253 * context1 - reference to ndlp
3254 * context2 - reference to cmd
3255 * context2->next - reference to rsp
3256 * context3 - reference to bpl
3257 *
3258 * It first properly decrements the reference count held on ndlp for the
3259 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3260 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3261 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3262 * adds the DMA buffer the @phba data structure for the delayed release.
3263 * If reference to the Buffer Pointer List (BPL) is present, the
3264 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3265 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3266 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3267 *
3268 * Return code
3269 * 0 - Success (currently, always return 0)
3270 **/
James Smart87af33f2007-10-27 13:37:43 -04003271int
James Smart329f9bc2007-04-25 09:53:01 -04003272lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003273{
3274 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003275 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003276
James Smarta8adb832007-10-27 13:37:53 -04003277 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3278 if (ndlp) {
3279 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3280 lpfc_nlp_put(ndlp);
3281
3282 /* If the ndlp is not being used by another discovery
3283 * thread, free it.
3284 */
3285 if (!lpfc_nlp_not_used(ndlp)) {
3286 /* If ndlp is being used by another discovery
3287 * thread, just clear NLP_DEFER_RM
3288 */
3289 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3290 }
3291 }
3292 else
3293 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003294 elsiocb->context1 = NULL;
3295 }
dea31012005-04-17 16:05:31 -05003296 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3297 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003298 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3299 /* Firmware could still be in progress of DMAing
3300 * payload, so don't free data buffer till after
3301 * a hbeat.
3302 */
3303 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3304 buf_ptr = elsiocb->context2;
3305 elsiocb->context2 = NULL;
3306 if (buf_ptr) {
3307 buf_ptr1 = NULL;
3308 spin_lock_irq(&phba->hbalock);
3309 if (!list_empty(&buf_ptr->list)) {
3310 list_remove_head(&buf_ptr->list,
3311 buf_ptr1, struct lpfc_dmabuf,
3312 list);
3313 INIT_LIST_HEAD(&buf_ptr1->list);
3314 list_add_tail(&buf_ptr1->list,
3315 &phba->elsbuf);
3316 phba->elsbuf_cnt++;
3317 }
3318 INIT_LIST_HEAD(&buf_ptr->list);
3319 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3320 phba->elsbuf_cnt++;
3321 spin_unlock_irq(&phba->hbalock);
3322 }
3323 } else {
3324 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3325 lpfc_els_free_data(phba, buf_ptr1);
3326 }
dea31012005-04-17 16:05:31 -05003327 }
3328
3329 if (elsiocb->context3) {
3330 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003331 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003332 }
James Bottomley604a3e32005-10-29 10:28:33 -05003333 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003334 return 0;
3335}
3336
James Smarte59058c2008-08-24 21:49:00 -04003337/**
James Smart3621a712009-04-06 18:47:14 -04003338 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003339 * @phba: pointer to lpfc hba data structure.
3340 * @cmdiocb: pointer to lpfc command iocb data structure.
3341 * @rspiocb: pointer to lpfc response iocb data structure.
3342 *
3343 * This routine is the completion callback function to the Logout (LOGO)
3344 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3345 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3346 * release the ndlp if it has the last reference remaining (reference count
3347 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3348 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3349 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3350 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3351 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3352 * IOCB data structure.
3353 **/
dea31012005-04-17 16:05:31 -05003354static void
James Smart2e0fef82007-06-17 19:56:36 -05003355lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3356 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003357{
James Smart2e0fef82007-06-17 19:56:36 -05003358 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3359 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003360 IOCB_t *irsp;
3361
3362 irsp = &rspiocb->iocb;
3363 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3364 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3365 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003366 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003367 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3368 "0109 ACC to LOGO completes to NPort x%x "
3369 "Data: x%x x%x x%x\n",
3370 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3371 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003372
3373 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3374 /* NPort Recovery mode or node is just allocated */
3375 if (!lpfc_nlp_not_used(ndlp)) {
3376 /* If the ndlp is being used by another discovery
3377 * thread, just unregister the RPI.
3378 */
3379 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003380 } else {
3381 /* Indicate the node has already released, should
3382 * not reference to it from within lpfc_els_free_iocb.
3383 */
3384 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003385 }
dea31012005-04-17 16:05:31 -05003386 }
3387 lpfc_els_free_iocb(phba, cmdiocb);
3388 return;
3389}
3390
James Smarte59058c2008-08-24 21:49:00 -04003391/**
James Smart3621a712009-04-06 18:47:14 -04003392 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003393 * @phba: pointer to lpfc hba data structure.
3394 * @pmb: pointer to the driver internal queue element for mailbox command.
3395 *
3396 * This routine is the completion callback function for unregister default
3397 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3398 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3399 * decrements the ndlp reference count held for this completion callback
3400 * function. After that, it invokes the lpfc_nlp_not_used() to check
3401 * whether there is only one reference left on the ndlp. If so, it will
3402 * perform one more decrement and trigger the release of the ndlp.
3403 **/
James Smart858c9f62007-06-17 19:56:39 -05003404void
3405lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3406{
3407 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3408 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3409
3410 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003411 pmb->context2 = NULL;
3412
James Smart858c9f62007-06-17 19:56:39 -05003413 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3414 kfree(mp);
3415 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003416 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003417 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003418 /* This is the end of the default RPI cleanup logic for this
3419 * ndlp. If no other discovery threads are using this ndlp.
3420 * we should free all resources associated with it.
3421 */
3422 lpfc_nlp_not_used(ndlp);
3423 }
James Smart3772a992009-05-22 14:50:54 -04003424
James Smart858c9f62007-06-17 19:56:39 -05003425 return;
3426}
3427
James Smarte59058c2008-08-24 21:49:00 -04003428/**
James Smart3621a712009-04-06 18:47:14 -04003429 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003430 * @phba: pointer to lpfc hba data structure.
3431 * @cmdiocb: pointer to lpfc command iocb data structure.
3432 * @rspiocb: pointer to lpfc response iocb data structure.
3433 *
3434 * This routine is the completion callback function for ELS Response IOCB
3435 * command. In normal case, this callback function just properly sets the
3436 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3437 * field in the command IOCB is not NULL, the referred mailbox command will
3438 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3439 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3440 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3441 * routine shall be invoked trying to release the ndlp if no other threads
3442 * are currently referring it.
3443 **/
dea31012005-04-17 16:05:31 -05003444static void
James Smart858c9f62007-06-17 19:56:39 -05003445lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003446 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003447{
James Smart2e0fef82007-06-17 19:56:36 -05003448 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3449 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3450 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003451 IOCB_t *irsp;
3452 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003453 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003454 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003455 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003456
James Smart33ccf8d2006-08-17 11:57:58 -04003457 irsp = &rspiocb->iocb;
3458
dea31012005-04-17 16:05:31 -05003459 if (cmdiocb->context_un.mbox)
3460 mbox = cmdiocb->context_un.mbox;
3461
James Smartfa4066b2008-01-11 01:53:27 -05003462 /* First determine if this is a LS_RJT cmpl. Note, this callback
3463 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3464 */
James Smart87af33f2007-10-27 13:37:43 -04003465 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003466 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3467 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003468 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003469 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003470 */
3471 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3472 ls_rjt = 1;
3473 }
3474
dea31012005-04-17 16:05:31 -05003475 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003476 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003477 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003478 mp = (struct lpfc_dmabuf *) mbox->context1;
3479 if (mp) {
3480 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3481 kfree(mp);
3482 }
James Smart329f9bc2007-04-25 09:53:01 -04003483 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003484 }
James Smart58da1ff2008-04-07 10:15:56 -04003485 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3486 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003487 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003488 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003489 /* Indicate the node has already released,
3490 * should not reference to it from within
3491 * the routine lpfc_els_free_iocb.
3492 */
3493 cmdiocb->context1 = NULL;
3494 }
dea31012005-04-17 16:05:31 -05003495 goto out;
3496 }
3497
James Smart858c9f62007-06-17 19:56:39 -05003498 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003499 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003500 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003501 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003502 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003503 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3504 "0110 ELS response tag x%x completes "
3505 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3506 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3507 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3508 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3509 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003510 if (mbox) {
3511 if ((rspiocb->iocb.ulpStatus == 0)
3512 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003513 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003514 /* Increment reference count to ndlp to hold the
3515 * reference to ndlp for the callback function.
3516 */
James Smart329f9bc2007-04-25 09:53:01 -04003517 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003518 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003519 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3520 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3521 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3522 }
3523 else {
3524 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3525 ndlp->nlp_prev_state = ndlp->nlp_state;
3526 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003527 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003528 }
James Smart0b727fe2007-10-27 13:37:25 -04003529 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003530 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003531 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003532 else
3533 /* Decrement the ndlp reference count we
3534 * set for this failed mailbox command.
3535 */
3536 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003537
3538 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3539 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3540 "0138 ELS rsp: Cannot issue reg_login for x%x "
3541 "Data: x%x x%x x%x\n",
3542 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3543 ndlp->nlp_rpi);
3544
James Smartfa4066b2008-01-11 01:53:27 -05003545 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003546 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003547 /* Indicate node has already been released,
3548 * should not reference to it from within
3549 * the routine lpfc_els_free_iocb.
3550 */
3551 cmdiocb->context1 = NULL;
3552 }
dea31012005-04-17 16:05:31 -05003553 } else {
James Smart858c9f62007-06-17 19:56:39 -05003554 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3555 if (!lpfc_error_lost_link(irsp) &&
3556 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003557 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003558 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003559 /* Indicate node has already been
3560 * released, should not reference
3561 * to it from within the routine
3562 * lpfc_els_free_iocb.
3563 */
3564 cmdiocb->context1 = NULL;
3565 }
dea31012005-04-17 16:05:31 -05003566 }
3567 }
James Smart14691152006-12-02 13:34:28 -05003568 mp = (struct lpfc_dmabuf *) mbox->context1;
3569 if (mp) {
3570 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3571 kfree(mp);
3572 }
3573 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003574 }
3575out:
James Smart58da1ff2008-04-07 10:15:56 -04003576 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003577 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003578 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003579 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003580
3581 /* If the node is not being used by another discovery thread,
3582 * and we are sending a reject, we are done with it.
3583 * Release driver reference count here and free associated
3584 * resources.
3585 */
3586 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003587 if (lpfc_nlp_not_used(ndlp))
3588 /* Indicate node has already been released,
3589 * should not reference to it from within
3590 * the routine lpfc_els_free_iocb.
3591 */
3592 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003593 }
James Smart87af33f2007-10-27 13:37:43 -04003594
dea31012005-04-17 16:05:31 -05003595 lpfc_els_free_iocb(phba, cmdiocb);
3596 return;
3597}
3598
James Smarte59058c2008-08-24 21:49:00 -04003599/**
James Smart3621a712009-04-06 18:47:14 -04003600 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003601 * @vport: pointer to a host virtual N_Port data structure.
3602 * @flag: the els command code to be accepted.
3603 * @oldiocb: pointer to the original lpfc command iocb data structure.
3604 * @ndlp: pointer to a node-list data structure.
3605 * @mbox: pointer to the driver internal queue element for mailbox command.
3606 *
3607 * This routine prepares and issues an Accept (ACC) response IOCB
3608 * command. It uses the @flag to properly set up the IOCB field for the
3609 * specific ACC response command to be issued and invokes the
3610 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3611 * @mbox pointer is passed in, it will be put into the context_un.mbox
3612 * field of the IOCB for the completion callback function to issue the
3613 * mailbox command to the HBA later when callback is invoked.
3614 *
3615 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3616 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3617 * will be stored into the context1 field of the IOCB for the completion
3618 * callback function to the corresponding response ELS IOCB command.
3619 *
3620 * Return code
3621 * 0 - Successfully issued acc response
3622 * 1 - Failed to issue acc response
3623 **/
dea31012005-04-17 16:05:31 -05003624int
James Smart2e0fef82007-06-17 19:56:36 -05003625lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3626 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003627 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003628{
James Smart2e0fef82007-06-17 19:56:36 -05003629 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3630 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003631 IOCB_t *icmd;
3632 IOCB_t *oldcmd;
3633 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003634 struct lpfc_sli *psli;
3635 uint8_t *pcmd;
3636 uint16_t cmdsize;
3637 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003638 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003639
3640 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003641 oldcmd = &oldiocb->iocb;
3642
3643 switch (flag) {
3644 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003645 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003646 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3647 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003648 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003649 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003650 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003651 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003652 return 1;
dea31012005-04-17 16:05:31 -05003653 }
James Smart2e0fef82007-06-17 19:56:36 -05003654
dea31012005-04-17 16:05:31 -05003655 icmd = &elsiocb->iocb;
3656 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3657 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3658 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003659 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003660
3661 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3662 "Issue ACC: did:x%x flg:x%x",
3663 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003664 break;
3665 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003666 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003667 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3668 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003669 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003670 return 1;
James Smart488d1462006-03-07 15:02:37 -05003671
dea31012005-04-17 16:05:31 -05003672 icmd = &elsiocb->iocb;
3673 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3674 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3675
3676 if (mbox)
3677 elsiocb->context_un.mbox = mbox;
3678
3679 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003680 pcmd += sizeof(uint32_t);
3681 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003682
3683 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3684 "Issue ACC PLOGI: did:x%x flg:x%x",
3685 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003686 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003687 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003688 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003689 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003690 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3691 if (!elsiocb)
3692 return 1;
3693
3694 icmd = &elsiocb->iocb;
3695 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3696 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3697
3698 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003699 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003700 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3701 els_pkt_ptr = (ELS_PKT *) pcmd;
3702 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003703
3704 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3705 "Issue ACC PRLO: did:x%x flg:x%x",
3706 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003707 break;
dea31012005-04-17 16:05:31 -05003708 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003709 return 1;
dea31012005-04-17 16:05:31 -05003710 }
dea31012005-04-17 16:05:31 -05003711 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003712 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3713 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3714 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3715 elsiocb->iotag, elsiocb->iocb.ulpContext,
3716 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3717 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003718 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003719 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003720 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003721 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003722 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3723 } else {
James Smart858c9f62007-06-17 19:56:39 -05003724 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003725 }
3726
3727 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003728 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003729 if (rc == IOCB_ERROR) {
3730 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003731 return 1;
dea31012005-04-17 16:05:31 -05003732 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003733 return 0;
dea31012005-04-17 16:05:31 -05003734}
3735
James Smarte59058c2008-08-24 21:49:00 -04003736/**
James Smart3621a712009-04-06 18:47:14 -04003737 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003738 * @vport: pointer to a virtual N_Port data structure.
3739 * @rejectError:
3740 * @oldiocb: pointer to the original lpfc command iocb data structure.
3741 * @ndlp: pointer to a node-list data structure.
3742 * @mbox: pointer to the driver internal queue element for mailbox command.
3743 *
3744 * This routine prepares and issue an Reject (RJT) response IOCB
3745 * command. If a @mbox pointer is passed in, it will be put into the
3746 * context_un.mbox field of the IOCB for the completion callback function
3747 * to issue to the HBA later.
3748 *
3749 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3750 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3751 * will be stored into the context1 field of the IOCB for the completion
3752 * callback function to the reject response ELS IOCB command.
3753 *
3754 * Return code
3755 * 0 - Successfully issued reject response
3756 * 1 - Failed to issue reject response
3757 **/
dea31012005-04-17 16:05:31 -05003758int
James Smart2e0fef82007-06-17 19:56:36 -05003759lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003760 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3761 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003762{
James Smart2e0fef82007-06-17 19:56:36 -05003763 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003764 IOCB_t *icmd;
3765 IOCB_t *oldcmd;
3766 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003767 struct lpfc_sli *psli;
3768 uint8_t *pcmd;
3769 uint16_t cmdsize;
3770 int rc;
3771
3772 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003773 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003774 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3775 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003776 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003777 return 1;
dea31012005-04-17 16:05:31 -05003778
3779 icmd = &elsiocb->iocb;
3780 oldcmd = &oldiocb->iocb;
3781 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3782 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3783
3784 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003785 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003786 *((uint32_t *) (pcmd)) = rejectError;
3787
James Smart51ef4c22007-08-02 11:10:31 -04003788 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003789 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003790
dea31012005-04-17 16:05:31 -05003791 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003792 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3793 "0129 Xmit ELS RJT x%x response tag x%x "
3794 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3795 "rpi x%x\n",
3796 rejectError, elsiocb->iotag,
3797 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3798 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003799 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3800 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3801 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3802
dea31012005-04-17 16:05:31 -05003803 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003804 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003805 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003806
dea31012005-04-17 16:05:31 -05003807 if (rc == IOCB_ERROR) {
3808 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003809 return 1;
dea31012005-04-17 16:05:31 -05003810 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003811 return 0;
dea31012005-04-17 16:05:31 -05003812}
3813
James Smarte59058c2008-08-24 21:49:00 -04003814/**
James Smart3621a712009-04-06 18:47:14 -04003815 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003816 * @vport: pointer to a virtual N_Port data structure.
3817 * @oldiocb: pointer to the original lpfc command iocb data structure.
3818 * @ndlp: pointer to a node-list data structure.
3819 *
3820 * This routine prepares and issues an Accept (ACC) response to Address
3821 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3822 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3823 *
3824 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3825 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3826 * will be stored into the context1 field of the IOCB for the completion
3827 * callback function to the ADISC Accept response ELS IOCB command.
3828 *
3829 * Return code
3830 * 0 - Successfully issued acc adisc response
3831 * 1 - Failed to issue adisc acc response
3832 **/
dea31012005-04-17 16:05:31 -05003833int
James Smart2e0fef82007-06-17 19:56:36 -05003834lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3835 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003836{
James Smart2e0fef82007-06-17 19:56:36 -05003837 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003838 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003839 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003840 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003841 uint8_t *pcmd;
3842 uint16_t cmdsize;
3843 int rc;
3844
James Smart92d7f7b2007-06-17 19:56:38 -05003845 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003846 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3847 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003848 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003849 return 1;
dea31012005-04-17 16:05:31 -05003850
dea31012005-04-17 16:05:31 -05003851 icmd = &elsiocb->iocb;
3852 oldcmd = &oldiocb->iocb;
3853 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003854
3855 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003856 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3857 "0130 Xmit ADISC ACC response iotag x%x xri: "
3858 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3859 elsiocb->iotag, elsiocb->iocb.ulpContext,
3860 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3861 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003862 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3863
3864 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003865 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003866
3867 ap = (ADISC *) (pcmd);
3868 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003869 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3870 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003871 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003872
James Smart858c9f62007-06-17 19:56:39 -05003873 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3874 "Issue ACC ADISC: did:x%x flg:x%x",
3875 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3876
dea31012005-04-17 16:05:31 -05003877 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003878 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003879 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003880 if (rc == IOCB_ERROR) {
3881 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003882 return 1;
dea31012005-04-17 16:05:31 -05003883 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003884 return 0;
dea31012005-04-17 16:05:31 -05003885}
3886
James Smarte59058c2008-08-24 21:49:00 -04003887/**
James Smart3621a712009-04-06 18:47:14 -04003888 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003889 * @vport: pointer to a virtual N_Port data structure.
3890 * @oldiocb: pointer to the original lpfc command iocb data structure.
3891 * @ndlp: pointer to a node-list data structure.
3892 *
3893 * This routine prepares and issues an Accept (ACC) response to Process
3894 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3895 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3896 *
3897 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3898 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3899 * will be stored into the context1 field of the IOCB for the completion
3900 * callback function to the PRLI Accept response ELS IOCB command.
3901 *
3902 * Return code
3903 * 0 - Successfully issued acc prli response
3904 * 1 - Failed to issue acc prli response
3905 **/
dea31012005-04-17 16:05:31 -05003906int
James Smart2e0fef82007-06-17 19:56:36 -05003907lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003908 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003909{
James Smart2e0fef82007-06-17 19:56:36 -05003910 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003911 PRLI *npr;
3912 lpfc_vpd_t *vpd;
3913 IOCB_t *icmd;
3914 IOCB_t *oldcmd;
3915 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003916 struct lpfc_sli *psli;
3917 uint8_t *pcmd;
3918 uint16_t cmdsize;
3919 int rc;
3920
3921 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003922
James Smart92d7f7b2007-06-17 19:56:38 -05003923 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003924 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003925 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003926 if (!elsiocb)
3927 return 1;
dea31012005-04-17 16:05:31 -05003928
dea31012005-04-17 16:05:31 -05003929 icmd = &elsiocb->iocb;
3930 oldcmd = &oldiocb->iocb;
3931 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003932 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003933 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3934 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3935 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3936 elsiocb->iotag, elsiocb->iocb.ulpContext,
3937 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3938 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003939 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3940
3941 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003942 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003943
3944 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003945 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003946
3947 npr = (PRLI *) pcmd;
3948 vpd = &phba->vpd;
3949 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003950 * If the remote port is a target and our firmware version is 3.20 or
3951 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003952 */
James Smart0d2b6b82008-06-14 22:52:47 -04003953 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3954 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003955 npr->ConfmComplAllowed = 1;
3956 npr->Retry = 1;
3957 npr->TaskRetryIdReq = 1;
3958 }
3959
3960 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3961 npr->estabImagePair = 1;
3962 npr->readXferRdyDis = 1;
3963 npr->ConfmComplAllowed = 1;
3964
3965 npr->prliType = PRLI_FCP_TYPE;
3966 npr->initiatorFunc = 1;
3967
James Smart858c9f62007-06-17 19:56:39 -05003968 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3969 "Issue ACC PRLI: did:x%x flg:x%x",
3970 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3971
dea31012005-04-17 16:05:31 -05003972 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003973 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003974
James Smart3772a992009-05-22 14:50:54 -04003975 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003976 if (rc == IOCB_ERROR) {
3977 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003978 return 1;
dea31012005-04-17 16:05:31 -05003979 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003980 return 0;
dea31012005-04-17 16:05:31 -05003981}
3982
James Smarte59058c2008-08-24 21:49:00 -04003983/**
James Smart3621a712009-04-06 18:47:14 -04003984 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003985 * @vport: pointer to a virtual N_Port data structure.
3986 * @format: rnid command format.
3987 * @oldiocb: pointer to the original lpfc command iocb data structure.
3988 * @ndlp: pointer to a node-list data structure.
3989 *
3990 * This routine issues a Request Node Identification Data (RNID) Accept
3991 * (ACC) response. It constructs the RNID ACC response command according to
3992 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3993 * issue the response. Note that this command does not need to hold the ndlp
3994 * reference count for the callback. So, the ndlp reference count taken by
3995 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3996 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3997 * there is no ndlp reference available.
3998 *
3999 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4000 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4001 * will be stored into the context1 field of the IOCB for the completion
4002 * callback function. However, for the RNID Accept Response ELS command,
4003 * this is undone later by this routine after the IOCB is allocated.
4004 *
4005 * Return code
4006 * 0 - Successfully issued acc rnid response
4007 * 1 - Failed to issue acc rnid response
4008 **/
dea31012005-04-17 16:05:31 -05004009static int
James Smart2e0fef82007-06-17 19:56:36 -05004010lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004011 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004012{
James Smart2e0fef82007-06-17 19:56:36 -05004013 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004014 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004015 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004016 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004017 struct lpfc_sli *psli;
4018 uint8_t *pcmd;
4019 uint16_t cmdsize;
4020 int rc;
4021
4022 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004023 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4024 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004025 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004026 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004027
James Smart2e0fef82007-06-17 19:56:36 -05004028 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4029 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004030 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004031 return 1;
dea31012005-04-17 16:05:31 -05004032
dea31012005-04-17 16:05:31 -05004033 icmd = &elsiocb->iocb;
4034 oldcmd = &oldiocb->iocb;
4035 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04004036 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004037 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4038 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4039 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004040 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004041 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004042 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004043
James Smart92d7f7b2007-06-17 19:56:38 -05004044 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004045 rn = (RNID *) (pcmd);
4046 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004047 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4048 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4049 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004050 switch (format) {
4051 case 0:
4052 rn->SpecificLen = 0;
4053 break;
4054 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004055 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004056 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004057 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004058 rn->un.topologyDisc.unitType = RNID_HBA;
4059 rn->un.topologyDisc.physPort = 0;
4060 rn->un.topologyDisc.attachedNodes = 0;
4061 break;
4062 default:
4063 rn->CommonLen = 0;
4064 rn->SpecificLen = 0;
4065 break;
4066 }
4067
James Smart858c9f62007-06-17 19:56:39 -05004068 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4069 "Issue ACC RNID: did:x%x flg:x%x",
4070 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4071
dea31012005-04-17 16:05:31 -05004072 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004073 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04004074 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004075 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
4076 * it could be freed */
4077
James Smart3772a992009-05-22 14:50:54 -04004078 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004079 if (rc == IOCB_ERROR) {
4080 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004081 return 1;
dea31012005-04-17 16:05:31 -05004082 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004083 return 0;
dea31012005-04-17 16:05:31 -05004084}
4085
James Smarte59058c2008-08-24 21:49:00 -04004086/**
James Smart19ca7602010-11-20 23:11:55 -05004087 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4088 * @vport: pointer to a virtual N_Port data structure.
4089 * @iocb: pointer to the lpfc command iocb data structure.
4090 * @ndlp: pointer to a node-list data structure.
4091 *
4092 * Return
4093 **/
4094static void
4095lpfc_els_clear_rrq(struct lpfc_vport *vport,
4096 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4097{
4098 struct lpfc_hba *phba = vport->phba;
4099 uint8_t *pcmd;
4100 struct RRQ *rrq;
4101 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004102 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004103 struct lpfc_node_rrq *prrq;
4104
4105
4106 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4107 pcmd += sizeof(uint32_t);
4108 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004109 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
4110 rxid = be16_to_cpu(bf_get(rrq_rxid, rrq));
James Smart19ca7602010-11-20 23:11:55 -05004111
4112 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4113 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4114 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004115 be32_to_cpu(bf_get(rrq_did, rrq)),
4116 be16_to_cpu(bf_get(rrq_oxid, rrq)),
James Smart19ca7602010-11-20 23:11:55 -05004117 rxid,
4118 iocb->iotag, iocb->iocb.ulpContext);
4119
4120 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4121 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4122 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004123 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
4124 xri = be16_to_cpu(bf_get(rrq_oxid, rrq));
4125 else
4126 xri = rxid;
4127 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004128 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004129 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004130 return;
4131}
4132
4133/**
James Smart12265f62010-10-22 11:05:53 -04004134 * lpfc_els_rsp_echo_acc - Issue echo acc response
4135 * @vport: pointer to a virtual N_Port data structure.
4136 * @data: pointer to echo data to return in the accept.
4137 * @oldiocb: pointer to the original lpfc command iocb data structure.
4138 * @ndlp: pointer to a node-list data structure.
4139 *
4140 * Return code
4141 * 0 - Successfully issued acc echo response
4142 * 1 - Failed to issue acc echo response
4143 **/
4144static int
4145lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4146 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4147{
4148 struct lpfc_hba *phba = vport->phba;
4149 struct lpfc_iocbq *elsiocb;
4150 struct lpfc_sli *psli;
4151 uint8_t *pcmd;
4152 uint16_t cmdsize;
4153 int rc;
4154
4155 psli = &phba->sli;
4156 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4157
4158 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4159 ndlp->nlp_DID, ELS_CMD_ACC);
4160 if (!elsiocb)
4161 return 1;
4162
4163 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */
4164 /* Xmit ECHO ACC response tag <ulpIoTag> */
4165 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4166 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4167 elsiocb->iotag, elsiocb->iocb.ulpContext);
4168 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4169 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4170 pcmd += sizeof(uint32_t);
4171 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4172
4173 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4174 "Issue ACC ECHO: did:x%x flg:x%x",
4175 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4176
4177 phba->fc_stat.elsXmitACC++;
4178 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4179 lpfc_nlp_put(ndlp);
4180 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
4181 * it could be freed */
4182
4183 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4184 if (rc == IOCB_ERROR) {
4185 lpfc_els_free_iocb(phba, elsiocb);
4186 return 1;
4187 }
4188 return 0;
4189}
4190
4191/**
James Smart3621a712009-04-06 18:47:14 -04004192 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004193 * @vport: pointer to a host virtual N_Port data structure.
4194 *
4195 * This routine issues Address Discover (ADISC) ELS commands to those
4196 * N_Ports which are in node port recovery state and ADISC has not been issued
4197 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4198 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4199 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4200 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4201 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4202 * IOCBs quit for later pick up. On the other hand, after walking through
4203 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4204 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4205 * no more ADISC need to be sent.
4206 *
4207 * Return code
4208 * The number of N_Ports with adisc issued.
4209 **/
dea31012005-04-17 16:05:31 -05004210int
James Smart2e0fef82007-06-17 19:56:36 -05004211lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004212{
James Smart2e0fef82007-06-17 19:56:36 -05004213 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004214 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004215 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004216
James Smart685f0bf2007-04-25 09:53:08 -04004217 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004218 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004219 if (!NLP_CHK_NODE_ACT(ndlp))
4220 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004221 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4222 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4223 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004224 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004225 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004226 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004227 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004228 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4229 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004230 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004231 vport->num_disc_nodes++;
4232 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004233 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004234 spin_lock_irq(shost->host_lock);
4235 vport->fc_flag |= FC_NLP_MORE;
4236 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004237 break;
dea31012005-04-17 16:05:31 -05004238 }
4239 }
4240 }
4241 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004242 spin_lock_irq(shost->host_lock);
4243 vport->fc_flag &= ~FC_NLP_MORE;
4244 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004245 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004246 return sentadisc;
dea31012005-04-17 16:05:31 -05004247}
4248
James Smarte59058c2008-08-24 21:49:00 -04004249/**
James Smart3621a712009-04-06 18:47:14 -04004250 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004251 * @vport: pointer to a host virtual N_Port data structure.
4252 *
4253 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4254 * which are in node port recovery state, with a @vport. Each time an ELS
4255 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4256 * the per @vport number of discover count (num_disc_nodes) shall be
4257 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4258 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4259 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4260 * later pick up. On the other hand, after walking through all the ndlps with
4261 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4262 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4263 * PLOGI need to be sent.
4264 *
4265 * Return code
4266 * The number of N_Ports with plogi issued.
4267 **/
dea31012005-04-17 16:05:31 -05004268int
James Smart2e0fef82007-06-17 19:56:36 -05004269lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004270{
James Smart2e0fef82007-06-17 19:56:36 -05004271 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004272 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004273 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004274
James Smart2e0fef82007-06-17 19:56:36 -05004275 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4276 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004277 if (!NLP_CHK_NODE_ACT(ndlp))
4278 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004279 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4280 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4281 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4282 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4283 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004284 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4285 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004286 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004287 vport->num_disc_nodes++;
4288 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004289 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004290 spin_lock_irq(shost->host_lock);
4291 vport->fc_flag |= FC_NLP_MORE;
4292 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004293 break;
dea31012005-04-17 16:05:31 -05004294 }
4295 }
4296 }
James Smart87af33f2007-10-27 13:37:43 -04004297 if (sentplogi) {
4298 lpfc_set_disctmo(vport);
4299 }
4300 else {
James Smart2e0fef82007-06-17 19:56:36 -05004301 spin_lock_irq(shost->host_lock);
4302 vport->fc_flag &= ~FC_NLP_MORE;
4303 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004304 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004305 return sentplogi;
dea31012005-04-17 16:05:31 -05004306}
4307
James Smarte59058c2008-08-24 21:49:00 -04004308/**
James Smart3621a712009-04-06 18:47:14 -04004309 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004310 * @vport: pointer to a host virtual N_Port data structure.
4311 *
4312 * This routine cleans up any Registration State Change Notification
4313 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4314 * @vport together with the host_lock is used to prevent multiple thread
4315 * trying to access the RSCN array on a same @vport at the same time.
4316 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004317void
James Smart2e0fef82007-06-17 19:56:36 -05004318lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004319{
James Smart2e0fef82007-06-17 19:56:36 -05004320 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4321 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004322 int i;
4323
James Smart7f5f3d02008-02-08 18:50:14 -05004324 spin_lock_irq(shost->host_lock);
4325 if (vport->fc_rscn_flush) {
4326 /* Another thread is walking fc_rscn_id_list on this vport */
4327 spin_unlock_irq(shost->host_lock);
4328 return;
4329 }
4330 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4331 vport->fc_rscn_flush = 1;
4332 spin_unlock_irq(shost->host_lock);
4333
James Smart2e0fef82007-06-17 19:56:36 -05004334 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004335 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004336 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004337 }
James Smart2e0fef82007-06-17 19:56:36 -05004338 spin_lock_irq(shost->host_lock);
4339 vport->fc_rscn_id_cnt = 0;
4340 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4341 spin_unlock_irq(shost->host_lock);
4342 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004343 /* Indicate we are done walking this fc_rscn_id_list */
4344 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004345}
4346
James Smarte59058c2008-08-24 21:49:00 -04004347/**
James Smart3621a712009-04-06 18:47:14 -04004348 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004349 * @vport: pointer to a host virtual N_Port data structure.
4350 * @did: remote destination port identifier.
4351 *
4352 * This routine checks whether there is any pending Registration State
4353 * Configuration Notification (RSCN) to a @did on @vport.
4354 *
4355 * Return code
4356 * None zero - The @did matched with a pending rscn
4357 * 0 - not able to match @did with a pending rscn
4358 **/
dea31012005-04-17 16:05:31 -05004359int
James Smart2e0fef82007-06-17 19:56:36 -05004360lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004361{
4362 D_ID ns_did;
4363 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004364 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004365 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004366 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004367
4368 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004369
4370 /* Never match fabric nodes for RSCNs */
4371 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004372 return 0;
dea31012005-04-17 16:05:31 -05004373
4374 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004375 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004376 return did;
dea31012005-04-17 16:05:31 -05004377
James Smart7f5f3d02008-02-08 18:50:14 -05004378 spin_lock_irq(shost->host_lock);
4379 if (vport->fc_rscn_flush) {
4380 /* Another thread is walking fc_rscn_id_list on this vport */
4381 spin_unlock_irq(shost->host_lock);
4382 return 0;
4383 }
4384 /* Indicate we are walking fc_rscn_id_list on this vport */
4385 vport->fc_rscn_flush = 1;
4386 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004387 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004388 lp = vport->fc_rscn_id_list[i]->virt;
4389 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4390 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004391 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004392 rscn_did.un.word = be32_to_cpu(*lp++);
4393 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004394 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4395 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004396 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4397 && (ns_did.un.b.area == rscn_did.un.b.area)
4398 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004399 goto return_did_out;
dea31012005-04-17 16:05:31 -05004400 break;
James Smarteaf15d52008-12-04 22:39:29 -05004401 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004402 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4403 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004404 goto return_did_out;
dea31012005-04-17 16:05:31 -05004405 break;
James Smarteaf15d52008-12-04 22:39:29 -05004406 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004407 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004408 goto return_did_out;
dea31012005-04-17 16:05:31 -05004409 break;
James Smarteaf15d52008-12-04 22:39:29 -05004410 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004411 goto return_did_out;
dea31012005-04-17 16:05:31 -05004412 }
4413 }
James Smart92d7f7b2007-06-17 19:56:38 -05004414 }
James Smart7f5f3d02008-02-08 18:50:14 -05004415 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4416 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004417 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004418return_did_out:
4419 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4420 vport->fc_rscn_flush = 0;
4421 return did;
dea31012005-04-17 16:05:31 -05004422}
4423
James Smarte59058c2008-08-24 21:49:00 -04004424/**
James Smart3621a712009-04-06 18:47:14 -04004425 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004426 * @vport: pointer to a host virtual N_Port data structure.
4427 *
4428 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4429 * state machine for a @vport's nodes that are with pending RSCN (Registration
4430 * State Change Notification).
4431 *
4432 * Return code
4433 * 0 - Successful (currently alway return 0)
4434 **/
dea31012005-04-17 16:05:31 -05004435static int
James Smart2e0fef82007-06-17 19:56:36 -05004436lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004437{
James Smart685f0bf2007-04-25 09:53:08 -04004438 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004439
James Smart0d2b6b82008-06-14 22:52:47 -04004440 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004441 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004442 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004443 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4444 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004445 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004446 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004447 NLP_EVT_DEVICE_RECOVERY);
4448 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004449 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004450 return 0;
dea31012005-04-17 16:05:31 -05004451}
4452
James Smarte59058c2008-08-24 21:49:00 -04004453/**
James Smart3621a712009-04-06 18:47:14 -04004454 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004455 * @vport: pointer to a host virtual N_Port data structure.
4456 * @cmdiocb: pointer to lpfc command iocb data structure.
4457 *
4458 * lpfc_send_rscn_event sends an RSCN netlink event to management
4459 * applications.
4460 */
4461static void
4462lpfc_send_rscn_event(struct lpfc_vport *vport,
4463 struct lpfc_iocbq *cmdiocb)
4464{
4465 struct lpfc_dmabuf *pcmd;
4466 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4467 uint32_t *payload_ptr;
4468 uint32_t payload_len;
4469 struct lpfc_rscn_event_header *rscn_event_data;
4470
4471 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4472 payload_ptr = (uint32_t *) pcmd->virt;
4473 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4474
4475 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4476 payload_len, GFP_KERNEL);
4477 if (!rscn_event_data) {
4478 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4479 "0147 Failed to allocate memory for RSCN event\n");
4480 return;
4481 }
4482 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4483 rscn_event_data->payload_length = payload_len;
4484 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4485 payload_len);
4486
4487 fc_host_post_vendor_event(shost,
4488 fc_get_event_number(),
4489 sizeof(struct lpfc_els_event_header) + payload_len,
4490 (char *)rscn_event_data,
4491 LPFC_NL_VENDOR_ID);
4492
4493 kfree(rscn_event_data);
4494}
4495
4496/**
James Smart3621a712009-04-06 18:47:14 -04004497 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004498 * @vport: pointer to a host virtual N_Port data structure.
4499 * @cmdiocb: pointer to lpfc command iocb data structure.
4500 * @ndlp: pointer to a node-list data structure.
4501 *
4502 * This routine processes an unsolicited RSCN (Registration State Change
4503 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4504 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4505 * discover state machine is about to begin discovery, it just accepts the
4506 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4507 * contains N_Port IDs for other vports on this HBA, it just accepts the
4508 * RSCN and ignore processing it. If the state machine is in the recovery
4509 * state, the fc_rscn_id_list of this @vport is walked and the
4510 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4511 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4512 * routine is invoked to handle the RSCN event.
4513 *
4514 * Return code
4515 * 0 - Just sent the acc response
4516 * 1 - Sent the acc response and waited for name server completion
4517 **/
dea31012005-04-17 16:05:31 -05004518static int
James Smart2e0fef82007-06-17 19:56:36 -05004519lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004520 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004521{
James Smart2e0fef82007-06-17 19:56:36 -05004522 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4523 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004524 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004525 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004526 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004527 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004528 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004529 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004530 int i;
dea31012005-04-17 16:05:31 -05004531
4532 icmd = &cmdiocb->iocb;
4533 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4534 lp = (uint32_t *) pcmd->virt;
4535
James Smart92d7f7b2007-06-17 19:56:38 -05004536 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4537 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004538 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004539 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4540 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004541 vport->fc_flag, payload_len, *lp,
4542 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004543
4544 /* Send an RSCN event to the management application */
4545 lpfc_send_rscn_event(vport, cmdiocb);
4546
James Smartd2873e42006-08-18 17:46:43 -04004547 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004548 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004549 FCH_EVT_RSCN, lp[i]);
4550
dea31012005-04-17 16:05:31 -05004551 /* If we are about to begin discovery, just ACC the RSCN.
4552 * Discovery processing will satisfy it.
4553 */
James Smart2e0fef82007-06-17 19:56:36 -05004554 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004555 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4556 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4557 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4558
James Smart51ef4c22007-08-02 11:10:31 -04004559 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004560 return 0;
dea31012005-04-17 16:05:31 -05004561 }
4562
James Smart92d7f7b2007-06-17 19:56:38 -05004563 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4564 * just ACC and ignore it.
4565 */
4566 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004567 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004568 i = payload_len;
4569 datap = lp;
4570 while (i > 0) {
4571 nportid = *datap++;
4572 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4573 i -= sizeof(uint32_t);
4574 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004575 if (lpfc_find_vport_by_did(phba, nportid))
4576 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004577 }
4578 if (rscn_id == hba_id) {
4579 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004580 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004581 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004582 "Data: x%x x%x x%x x%x\n",
4583 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004584 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004585 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4586 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4587 ndlp->nlp_DID, vport->port_state,
4588 ndlp->nlp_flag);
4589
James Smart92d7f7b2007-06-17 19:56:38 -05004590 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004591 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004592 return 0;
4593 }
4594 }
4595
James Smart7f5f3d02008-02-08 18:50:14 -05004596 spin_lock_irq(shost->host_lock);
4597 if (vport->fc_rscn_flush) {
4598 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004599 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004600 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004601 /* Send back ACC */
4602 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004603 return 0;
4604 }
4605 /* Indicate we are walking fc_rscn_id_list on this vport */
4606 vport->fc_rscn_flush = 1;
4607 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004608 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004609 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004610 /* If we are already processing an RSCN, save the received
4611 * RSCN payload buffer, cmdiocb->context2 to process later.
4612 */
James Smart2e0fef82007-06-17 19:56:36 -05004613 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004614 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4615 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4616 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4617
James Smart09372822008-01-11 01:52:54 -05004618 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004619 vport->fc_flag |= FC_RSCN_DEFERRED;
4620 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004621 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004622 vport->fc_flag |= FC_RSCN_MODE;
4623 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004624 if (rscn_cnt) {
4625 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4626 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4627 }
4628 if ((rscn_cnt) &&
4629 (payload_len + length <= LPFC_BPL_SIZE)) {
4630 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004631 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004632 memcpy(((uint8_t *)cmd) + length, lp,
4633 payload_len);
4634 } else {
4635 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4636 vport->fc_rscn_id_cnt++;
4637 /* If we zero, cmdiocb->context2, the calling
4638 * routine will not try to free it.
4639 */
4640 cmdiocb->context2 = NULL;
4641 }
dea31012005-04-17 16:05:31 -05004642 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004643 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4644 "0235 Deferred RSCN "
4645 "Data: x%x x%x x%x\n",
4646 vport->fc_rscn_id_cnt, vport->fc_flag,
4647 vport->port_state);
dea31012005-04-17 16:05:31 -05004648 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004649 vport->fc_flag |= FC_RSCN_DISCOVERY;
4650 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004651 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004652 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4653 "0234 ReDiscovery RSCN "
4654 "Data: x%x x%x x%x\n",
4655 vport->fc_rscn_id_cnt, vport->fc_flag,
4656 vport->port_state);
dea31012005-04-17 16:05:31 -05004657 }
James Smart7f5f3d02008-02-08 18:50:14 -05004658 /* Indicate we are done walking fc_rscn_id_list on this vport */
4659 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004660 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004661 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004662 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004663 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004664 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004665 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004666 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004667 return 0;
dea31012005-04-17 16:05:31 -05004668 }
James Smart858c9f62007-06-17 19:56:39 -05004669 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4670 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4671 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4672
James Smart2e0fef82007-06-17 19:56:36 -05004673 spin_lock_irq(shost->host_lock);
4674 vport->fc_flag |= FC_RSCN_MODE;
4675 spin_unlock_irq(shost->host_lock);
4676 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004677 /* Indicate we are done walking fc_rscn_id_list on this vport */
4678 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004679 /*
4680 * If we zero, cmdiocb->context2, the calling routine will
4681 * not try to free it.
4682 */
4683 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004684 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004685 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004686 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004687 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004688 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004689 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004690}
4691
James Smarte59058c2008-08-24 21:49:00 -04004692/**
James Smart3621a712009-04-06 18:47:14 -04004693 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004694 * @vport: pointer to a host virtual N_Port data structure.
4695 *
4696 * This routine handles the Registration State Configuration Notification
4697 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4698 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4699 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4700 * NameServer shall be issued. If CT command to the NameServer fails to be
4701 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4702 * RSCN activities with the @vport.
4703 *
4704 * Return code
4705 * 0 - Cleaned up rscn on the @vport
4706 * 1 - Wait for plogi to name server before proceed
4707 **/
dea31012005-04-17 16:05:31 -05004708int
James Smart2e0fef82007-06-17 19:56:36 -05004709lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004710{
4711 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004712 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004713
James Smart92d7f7b2007-06-17 19:56:38 -05004714 /* Ignore RSCN if the port is being torn down. */
4715 if (vport->load_flag & FC_UNLOADING) {
4716 lpfc_els_flush_rscn(vport);
4717 return 0;
4718 }
4719
dea31012005-04-17 16:05:31 -05004720 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004721 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004722
4723 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004724 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4725 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4726 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4727 vport->port_state);
dea31012005-04-17 16:05:31 -05004728
4729 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004730 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004731 vport->num_disc_nodes = 0;
4732
James Smart2e0fef82007-06-17 19:56:36 -05004733 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004734 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4735 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004736 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004737 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004738 /* Wait for NameServer query cmpl before we can
4739 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004740 return 1;
dea31012005-04-17 16:05:31 -05004741 } else {
4742 /* If login to NameServer does not exist, issue one */
4743 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004744 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004745 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004746 /* Wait for NameServer login cmpl before we can
4747 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004748 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004749
James Smarte47c9092008-02-08 18:49:26 -05004750 if (ndlp) {
4751 ndlp = lpfc_enable_node(vport, ndlp,
4752 NLP_STE_PLOGI_ISSUE);
4753 if (!ndlp) {
4754 lpfc_els_flush_rscn(vport);
4755 return 0;
4756 }
4757 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004758 } else {
James Smarte47c9092008-02-08 18:49:26 -05004759 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4760 if (!ndlp) {
4761 lpfc_els_flush_rscn(vport);
4762 return 0;
4763 }
James Smart2e0fef82007-06-17 19:56:36 -05004764 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004765 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004766 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004767 }
James Smarte47c9092008-02-08 18:49:26 -05004768 ndlp->nlp_type |= NLP_FABRIC;
4769 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4770 /* Wait for NameServer login cmpl before we can
4771 * continue
4772 */
4773 return 1;
dea31012005-04-17 16:05:31 -05004774 }
4775
James Smart2e0fef82007-06-17 19:56:36 -05004776 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004777 return 0;
dea31012005-04-17 16:05:31 -05004778}
4779
James Smarte59058c2008-08-24 21:49:00 -04004780/**
James Smart3621a712009-04-06 18:47:14 -04004781 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004782 * @vport: pointer to a host virtual N_Port data structure.
4783 * @cmdiocb: pointer to lpfc command iocb data structure.
4784 * @ndlp: pointer to a node-list data structure.
4785 *
4786 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4787 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4788 * point topology. As an unsolicited FLOGI should not be received in a loop
4789 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4790 * lpfc_check_sparm() routine is invoked to check the parameters in the
4791 * unsolicited FLOGI. If parameters validation failed, the routine
4792 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4793 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4794 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4795 * will initiate PLOGI. The higher lexicographical value party shall has
4796 * higher priority (as the winning port) and will initiate PLOGI and
4797 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4798 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4799 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4800 *
4801 * Return code
4802 * 0 - Successfully processed the unsolicited flogi
4803 * 1 - Failed to process the unsolicited flogi
4804 **/
dea31012005-04-17 16:05:31 -05004805static int
James Smart2e0fef82007-06-17 19:56:36 -05004806lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004807 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004808{
James Smart2e0fef82007-06-17 19:56:36 -05004809 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4810 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004811 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4812 uint32_t *lp = (uint32_t *) pcmd->virt;
4813 IOCB_t *icmd = &cmdiocb->iocb;
4814 struct serv_parm *sp;
4815 LPFC_MBOXQ_t *mbox;
4816 struct ls_rjt stat;
4817 uint32_t cmd, did;
4818 int rc;
4819
4820 cmd = *lp++;
4821 sp = (struct serv_parm *) lp;
4822
4823 /* FLOGI received */
4824
James Smart2e0fef82007-06-17 19:56:36 -05004825 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004826
James Smart76a95d72010-11-20 23:11:48 -05004827 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004828 /* We should never receive a FLOGI in loop mode, ignore it */
4829 did = icmd->un.elsreq64.remoteID;
4830
4831 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4832 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004833 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4834 "0113 An FLOGI ELS command x%x was "
4835 "received from DID x%x in Loop Mode\n",
4836 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004837 return 1;
dea31012005-04-17 16:05:31 -05004838 }
4839
4840 did = Fabric_DID;
4841
James Smart341af102010-01-26 23:07:37 -05004842 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004843 /* For a FLOGI we accept, then if our portname is greater
4844 * then the remote portname we initiate Nport login.
4845 */
4846
James Smart2e0fef82007-06-17 19:56:36 -05004847 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004848 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004849
4850 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004851 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4852 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004853 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004854
dea31012005-04-17 16:05:31 -05004855 lpfc_linkdown(phba);
4856 lpfc_init_link(phba, mbox,
4857 phba->cfg_topology,
4858 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004859 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004860 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004861 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004862 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004863 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004864 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004865 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004866 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004867 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004868 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004869 spin_lock_irq(shost->host_lock);
4870 vport->fc_flag |= FC_PT2PT_PLOGI;
4871 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004872 }
James Smart2e0fef82007-06-17 19:56:36 -05004873 spin_lock_irq(shost->host_lock);
4874 vport->fc_flag |= FC_PT2PT;
4875 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4876 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004877 } else {
4878 /* Reject this request because invalid parameters */
4879 stat.un.b.lsRjtRsvd0 = 0;
4880 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4881 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4882 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004883 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4884 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004885 return 1;
dea31012005-04-17 16:05:31 -05004886 }
4887
4888 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004889 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004890
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004891 return 0;
dea31012005-04-17 16:05:31 -05004892}
4893
James Smarte59058c2008-08-24 21:49:00 -04004894/**
James Smart3621a712009-04-06 18:47:14 -04004895 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004896 * @vport: pointer to a host virtual N_Port data structure.
4897 * @cmdiocb: pointer to lpfc command iocb data structure.
4898 * @ndlp: pointer to a node-list data structure.
4899 *
4900 * This routine processes Request Node Identification Data (RNID) IOCB
4901 * received as an ELS unsolicited event. Only when the RNID specified format
4902 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4903 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4904 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4905 * rejected by invoking the lpfc_els_rsp_reject() routine.
4906 *
4907 * Return code
4908 * 0 - Successfully processed rnid iocb (currently always return 0)
4909 **/
dea31012005-04-17 16:05:31 -05004910static int
James Smart2e0fef82007-06-17 19:56:36 -05004911lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4912 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004913{
4914 struct lpfc_dmabuf *pcmd;
4915 uint32_t *lp;
4916 IOCB_t *icmd;
4917 RNID *rn;
4918 struct ls_rjt stat;
4919 uint32_t cmd, did;
4920
4921 icmd = &cmdiocb->iocb;
4922 did = icmd->un.elsreq64.remoteID;
4923 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4924 lp = (uint32_t *) pcmd->virt;
4925
4926 cmd = *lp++;
4927 rn = (RNID *) lp;
4928
4929 /* RNID received */
4930
4931 switch (rn->Format) {
4932 case 0:
4933 case RNID_TOPOLOGY_DISC:
4934 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004935 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004936 break;
4937 default:
4938 /* Reject this request because format not supported */
4939 stat.un.b.lsRjtRsvd0 = 0;
4940 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4941 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4942 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004943 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4944 NULL);
dea31012005-04-17 16:05:31 -05004945 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004946 return 0;
dea31012005-04-17 16:05:31 -05004947}
4948
James Smarte59058c2008-08-24 21:49:00 -04004949/**
James Smart12265f62010-10-22 11:05:53 -04004950 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4951 * @vport: pointer to a host virtual N_Port data structure.
4952 * @cmdiocb: pointer to lpfc command iocb data structure.
4953 * @ndlp: pointer to a node-list data structure.
4954 *
4955 * Return code
4956 * 0 - Successfully processed echo iocb (currently always return 0)
4957 **/
4958static int
4959lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4960 struct lpfc_nodelist *ndlp)
4961{
4962 uint8_t *pcmd;
4963
4964 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4965
4966 /* skip over first word of echo command to find echo data */
4967 pcmd += sizeof(uint32_t);
4968
4969 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
4970 return 0;
4971}
4972
4973/**
James Smart3621a712009-04-06 18:47:14 -04004974 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004975 * @vport: pointer to a host virtual N_Port data structure.
4976 * @cmdiocb: pointer to lpfc command iocb data structure.
4977 * @ndlp: pointer to a node-list data structure.
4978 *
4979 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4980 * received as an ELS unsolicited event. Currently, this function just invokes
4981 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4982 *
4983 * Return code
4984 * 0 - Successfully processed lirr iocb (currently always return 0)
4985 **/
dea31012005-04-17 16:05:31 -05004986static int
James Smart2e0fef82007-06-17 19:56:36 -05004987lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4988 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004989{
4990 struct ls_rjt stat;
4991
4992 /* For now, unconditionally reject this command */
4993 stat.un.b.lsRjtRsvd0 = 0;
4994 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4995 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4996 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004997 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004998 return 0;
4999}
5000
James Smarte59058c2008-08-24 21:49:00 -04005001/**
James Smart5ffc2662009-11-18 15:39:44 -05005002 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5003 * @vport: pointer to a host virtual N_Port data structure.
5004 * @cmdiocb: pointer to lpfc command iocb data structure.
5005 * @ndlp: pointer to a node-list data structure.
5006 *
5007 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5008 * received as an ELS unsolicited event. A request to RRQ shall only
5009 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5010 * Nx_Port N_Port_ID of the target Exchange is the same as the
5011 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5012 * not accepted, an LS_RJT with reason code "Unable to perform
5013 * command request" and reason code explanation "Invalid Originator
5014 * S_ID" shall be returned. For now, we just unconditionally accept
5015 * RRQ from the target.
5016 **/
5017static void
5018lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5019 struct lpfc_nodelist *ndlp)
5020{
5021 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05005022 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5023 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05005024}
5025
5026/**
James Smart12265f62010-10-22 11:05:53 -04005027 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5028 * @phba: pointer to lpfc hba data structure.
5029 * @pmb: pointer to the driver internal queue element for mailbox command.
5030 *
5031 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5032 * mailbox command. This callback function is to actually send the Accept
5033 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5034 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5035 * mailbox command, constructs the RPS response with the link statistics
5036 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5037 * response to the RPS.
5038 *
5039 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5040 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5041 * will be stored into the context1 field of the IOCB for the completion
5042 * callback function to the RPS Accept Response ELS IOCB command.
5043 *
5044 **/
5045static void
5046lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5047{
5048 MAILBOX_t *mb;
5049 IOCB_t *icmd;
5050 struct RLS_RSP *rls_rsp;
5051 uint8_t *pcmd;
5052 struct lpfc_iocbq *elsiocb;
5053 struct lpfc_nodelist *ndlp;
5054 uint16_t xri;
5055 uint32_t cmdsize;
5056
5057 mb = &pmb->u.mb;
5058
5059 ndlp = (struct lpfc_nodelist *) pmb->context2;
5060 xri = (uint16_t) ((unsigned long)(pmb->context1));
5061 pmb->context1 = NULL;
5062 pmb->context2 = NULL;
5063
5064 if (mb->mbxStatus) {
5065 mempool_free(pmb, phba->mbox_mem_pool);
5066 return;
5067 }
5068
5069 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
5070 mempool_free(pmb, phba->mbox_mem_pool);
5071 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5072 lpfc_max_els_tries, ndlp,
5073 ndlp->nlp_DID, ELS_CMD_ACC);
5074
5075 /* Decrement the ndlp reference count from previous mbox command */
5076 lpfc_nlp_put(ndlp);
5077
5078 if (!elsiocb)
5079 return;
5080
5081 icmd = &elsiocb->iocb;
5082 icmd->ulpContext = xri;
5083
5084 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5085 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5086 pcmd += sizeof(uint32_t); /* Skip past command */
5087 rls_rsp = (struct RLS_RSP *)pcmd;
5088
5089 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5090 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5091 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5092 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5093 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5094 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
5095
5096 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5097 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5098 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5099 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5100 elsiocb->iotag, elsiocb->iocb.ulpContext,
5101 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5102 ndlp->nlp_rpi);
5103 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5104 phba->fc_stat.elsXmitACC++;
5105 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5106 lpfc_els_free_iocb(phba, elsiocb);
5107}
5108
5109/**
James Smart3621a712009-04-06 18:47:14 -04005110 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005111 * @phba: pointer to lpfc hba data structure.
5112 * @pmb: pointer to the driver internal queue element for mailbox command.
5113 *
5114 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5115 * mailbox command. This callback function is to actually send the Accept
5116 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5117 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5118 * mailbox command, constructs the RPS response with the link statistics
5119 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5120 * response to the RPS.
5121 *
5122 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5123 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5124 * will be stored into the context1 field of the IOCB for the completion
5125 * callback function to the RPS Accept Response ELS IOCB command.
5126 *
5127 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005128static void
James Smart329f9bc2007-04-25 09:53:01 -04005129lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005130{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005131 MAILBOX_t *mb;
5132 IOCB_t *icmd;
5133 RPS_RSP *rps_rsp;
5134 uint8_t *pcmd;
5135 struct lpfc_iocbq *elsiocb;
5136 struct lpfc_nodelist *ndlp;
5137 uint16_t xri, status;
5138 uint32_t cmdsize;
5139
James Smart04c68492009-05-22 14:52:52 -04005140 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005141
5142 ndlp = (struct lpfc_nodelist *) pmb->context2;
5143 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07005144 pmb->context1 = NULL;
5145 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005146
5147 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005148 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005149 return;
5150 }
5151
5152 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005153 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005154 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5155 lpfc_max_els_tries, ndlp,
5156 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005157
5158 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005159 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005160
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005161 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005162 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005163
5164 icmd = &elsiocb->iocb;
5165 icmd->ulpContext = xri;
5166
5167 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5168 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005169 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005170 rps_rsp = (RPS_RSP *)pcmd;
5171
James Smart76a95d72010-11-20 23:11:48 -05005172 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005173 status = 0x10;
5174 else
5175 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005176 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005177 status |= 0x4;
5178
5179 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005180 rps_rsp->portStatus = cpu_to_be16(status);
5181 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5182 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5183 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5184 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5185 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5186 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005187 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005188 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5189 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5190 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5191 elsiocb->iotag, elsiocb->iocb.ulpContext,
5192 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5193 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005194 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005195 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005196 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005197 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005198 return;
5199}
5200
James Smarte59058c2008-08-24 21:49:00 -04005201/**
James Smart12265f62010-10-22 11:05:53 -04005202 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5203 * @vport: pointer to a host virtual N_Port data structure.
5204 * @cmdiocb: pointer to lpfc command iocb data structure.
5205 * @ndlp: pointer to a node-list data structure.
5206 *
5207 * This routine processes Read Port Status (RPL) IOCB received as an
5208 * ELS unsolicited event. It first checks the remote port state. If the
5209 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5210 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5211 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5212 * for reading the HBA link statistics. It is for the callback function,
5213 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5214 * to actually sending out RPL Accept (ACC) response.
5215 *
5216 * Return codes
5217 * 0 - Successfully processed rls iocb (currently always return 0)
5218 **/
5219static int
5220lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5221 struct lpfc_nodelist *ndlp)
5222{
5223 struct lpfc_hba *phba = vport->phba;
5224 LPFC_MBOXQ_t *mbox;
5225 struct lpfc_dmabuf *pcmd;
5226 struct ls_rjt stat;
5227
5228 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5229 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5230 /* reject the unsolicited RPS request and done with it */
5231 goto reject_out;
5232
5233 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5234
5235 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5236 if (mbox) {
5237 lpfc_read_lnk_stat(phba, mbox);
5238 mbox->context1 =
5239 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
5240 mbox->context2 = lpfc_nlp_get(ndlp);
5241 mbox->vport = vport;
5242 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5243 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5244 != MBX_NOT_FINISHED)
5245 /* Mbox completion will send ELS Response */
5246 return 0;
5247 /* Decrement reference count used for the failed mbox
5248 * command.
5249 */
5250 lpfc_nlp_put(ndlp);
5251 mempool_free(mbox, phba->mbox_mem_pool);
5252 }
5253reject_out:
5254 /* issue rejection response */
5255 stat.un.b.lsRjtRsvd0 = 0;
5256 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5257 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5258 stat.un.b.vendorUnique = 0;
5259 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5260 return 0;
5261}
5262
5263/**
5264 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5265 * @vport: pointer to a host virtual N_Port data structure.
5266 * @cmdiocb: pointer to lpfc command iocb data structure.
5267 * @ndlp: pointer to a node-list data structure.
5268 *
5269 * This routine processes Read Timout Value (RTV) IOCB received as an
5270 * ELS unsolicited event. It first checks the remote port state. If the
5271 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5272 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5273 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5274 * Value (RTV) unsolicited IOCB event.
5275 *
5276 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5277 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5278 * will be stored into the context1 field of the IOCB for the completion
5279 * callback function to the RPS Accept Response ELS IOCB command.
5280 *
5281 * Return codes
5282 * 0 - Successfully processed rtv iocb (currently always return 0)
5283 **/
5284static int
5285lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5286 struct lpfc_nodelist *ndlp)
5287{
5288 struct lpfc_hba *phba = vport->phba;
5289 struct ls_rjt stat;
5290 struct RTV_RSP *rtv_rsp;
5291 uint8_t *pcmd;
5292 struct lpfc_iocbq *elsiocb;
5293 uint32_t cmdsize;
5294
5295
5296 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5297 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5298 /* reject the unsolicited RPS request and done with it */
5299 goto reject_out;
5300
5301 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5302 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5303 lpfc_max_els_tries, ndlp,
5304 ndlp->nlp_DID, ELS_CMD_ACC);
5305
5306 if (!elsiocb)
5307 return 1;
5308
5309 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5310 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5311 pcmd += sizeof(uint32_t); /* Skip past command */
5312
5313 /* use the command's xri in the response */
5314 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext;
5315
5316 rtv_rsp = (struct RTV_RSP *)pcmd;
5317
5318 /* populate RTV payload */
5319 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5320 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5321 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5322 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5323 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5324
5325 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5326 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5327 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5328 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5329 "Data: x%x x%x x%x\n",
5330 elsiocb->iotag, elsiocb->iocb.ulpContext,
5331 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5332 ndlp->nlp_rpi,
5333 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5334 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5335 phba->fc_stat.elsXmitACC++;
5336 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5337 lpfc_els_free_iocb(phba, elsiocb);
5338 return 0;
5339
5340reject_out:
5341 /* issue rejection response */
5342 stat.un.b.lsRjtRsvd0 = 0;
5343 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5344 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5345 stat.un.b.vendorUnique = 0;
5346 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5347 return 0;
5348}
5349
5350/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005351 * @vport: pointer to a host virtual N_Port data structure.
5352 * @cmdiocb: pointer to lpfc command iocb data structure.
5353 * @ndlp: pointer to a node-list data structure.
5354 *
5355 * This routine processes Read Port Status (RPS) IOCB received as an
5356 * ELS unsolicited event. It first checks the remote port state. If the
5357 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5358 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5359 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5360 * for reading the HBA link statistics. It is for the callback function,
5361 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5362 * to actually sending out RPS Accept (ACC) response.
5363 *
5364 * Return codes
5365 * 0 - Successfully processed rps iocb (currently always return 0)
5366 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005367static int
James Smart2e0fef82007-06-17 19:56:36 -05005368lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5369 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005370{
James Smart2e0fef82007-06-17 19:56:36 -05005371 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005372 uint32_t *lp;
5373 uint8_t flag;
5374 LPFC_MBOXQ_t *mbox;
5375 struct lpfc_dmabuf *pcmd;
5376 RPS *rps;
5377 struct ls_rjt stat;
5378
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005379 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005380 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5381 /* reject the unsolicited RPS request and done with it */
5382 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005383
5384 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5385 lp = (uint32_t *) pcmd->virt;
5386 flag = (be32_to_cpu(*lp++) & 0xf);
5387 rps = (RPS *) lp;
5388
5389 if ((flag == 0) ||
5390 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005391 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005392 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005393
James Smart92d7f7b2007-06-17 19:56:38 -05005394 printk("Fix me....\n");
5395 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005396 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5397 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005398 lpfc_read_lnk_stat(phba, mbox);
5399 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05005400 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04005401 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005402 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005403 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005404 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005405 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005406 /* Mbox completion will send ELS Response */
5407 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005408 /* Decrement reference count used for the failed mbox
5409 * command.
5410 */
James Smart329f9bc2007-04-25 09:53:01 -04005411 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005412 mempool_free(mbox, phba->mbox_mem_pool);
5413 }
5414 }
James Smart90160e02008-08-24 21:49:45 -04005415
5416reject_out:
5417 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005418 stat.un.b.lsRjtRsvd0 = 0;
5419 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5420 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5421 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005422 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005423 return 0;
5424}
5425
James Smart19ca7602010-11-20 23:11:55 -05005426/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5427 * @vport: pointer to a host virtual N_Port data structure.
5428 * @ndlp: pointer to a node-list data structure.
5429 * @did: DID of the target.
5430 * @rrq: Pointer to the rrq struct.
5431 *
5432 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5433 * Successful the the completion handler will clear the RRQ.
5434 *
5435 * Return codes
5436 * 0 - Successfully sent rrq els iocb.
5437 * 1 - Failed to send rrq els iocb.
5438 **/
5439static int
5440lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5441 uint32_t did, struct lpfc_node_rrq *rrq)
5442{
5443 struct lpfc_hba *phba = vport->phba;
5444 struct RRQ *els_rrq;
5445 IOCB_t *icmd;
5446 struct lpfc_iocbq *elsiocb;
5447 uint8_t *pcmd;
5448 uint16_t cmdsize;
5449 int ret;
5450
5451
5452 if (ndlp != rrq->ndlp)
5453 ndlp = rrq->ndlp;
5454 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5455 return 1;
5456
5457 /* If ndlp is not NULL, we will bump the reference count on it */
5458 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5459 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5460 ELS_CMD_RRQ);
5461 if (!elsiocb)
5462 return 1;
5463
5464 icmd = &elsiocb->iocb;
5465 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5466
5467 /* For RRQ request, remainder of payload is Exchange IDs */
5468 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5469 pcmd += sizeof(uint32_t);
5470 els_rrq = (struct RRQ *) pcmd;
5471
5472 bf_set(rrq_oxid, els_rrq, rrq->xritag);
5473 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5474 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5475 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5476 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5477
5478
5479 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5480 "Issue RRQ: did:x%x",
5481 did, rrq->xritag, rrq->rxid);
5482 elsiocb->context_un.rrq = rrq;
5483 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5484 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5485
5486 if (ret == IOCB_ERROR) {
5487 lpfc_els_free_iocb(phba, elsiocb);
5488 return 1;
5489 }
5490 return 0;
5491}
5492
5493/**
5494 * lpfc_send_rrq - Sends ELS RRQ if needed.
5495 * @phba: pointer to lpfc hba data structure.
5496 * @rrq: pointer to the active rrq.
5497 *
5498 * This routine will call the lpfc_issue_els_rrq if the rrq is
5499 * still active for the xri. If this function returns a failure then
5500 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5501 *
5502 * Returns 0 Success.
5503 * 1 Failure.
5504 **/
5505int
5506lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5507{
5508 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5509 rrq->nlp_DID);
5510 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5511 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5512 rrq->nlp_DID, rrq);
5513 else
5514 return 1;
5515}
5516
James Smarte59058c2008-08-24 21:49:00 -04005517/**
James Smart3621a712009-04-06 18:47:14 -04005518 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005519 * @vport: pointer to a host virtual N_Port data structure.
5520 * @cmdsize: size of the ELS command.
5521 * @oldiocb: pointer to the original lpfc command iocb data structure.
5522 * @ndlp: pointer to a node-list data structure.
5523 *
5524 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5525 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5526 *
5527 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5528 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5529 * will be stored into the context1 field of the IOCB for the completion
5530 * callback function to the RPL Accept Response ELS command.
5531 *
5532 * Return code
5533 * 0 - Successfully issued ACC RPL ELS command
5534 * 1 - Failed to issue ACC RPL ELS command
5535 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005536static int
James Smart2e0fef82007-06-17 19:56:36 -05005537lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5538 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005539{
James Smart2e0fef82007-06-17 19:56:36 -05005540 struct lpfc_hba *phba = vport->phba;
5541 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005542 RPL_RSP rpl_rsp;
5543 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005544 uint8_t *pcmd;
5545
James Smart2e0fef82007-06-17 19:56:36 -05005546 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5547 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005548
James Smart488d1462006-03-07 15:02:37 -05005549 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005550 return 1;
James Smart488d1462006-03-07 15:02:37 -05005551
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005552 icmd = &elsiocb->iocb;
5553 oldcmd = &oldiocb->iocb;
5554 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
5555
5556 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5557 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005558 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005559 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5560 pcmd += sizeof(uint16_t);
5561
5562 /* Setup the RPL ACC payload */
5563 rpl_rsp.listLen = be32_to_cpu(1);
5564 rpl_rsp.index = 0;
5565 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005566 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5567 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005568 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005569 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005570 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005571 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5572 "0120 Xmit ELS RPL ACC response tag x%x "
5573 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5574 "rpi x%x\n",
5575 elsiocb->iotag, elsiocb->iocb.ulpContext,
5576 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5577 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005578 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005579 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005580 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5581 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005582 lpfc_els_free_iocb(phba, elsiocb);
5583 return 1;
5584 }
5585 return 0;
5586}
5587
James Smarte59058c2008-08-24 21:49:00 -04005588/**
James Smart3621a712009-04-06 18:47:14 -04005589 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005590 * @vport: pointer to a host virtual N_Port data structure.
5591 * @cmdiocb: pointer to lpfc command iocb data structure.
5592 * @ndlp: pointer to a node-list data structure.
5593 *
5594 * This routine processes Read Port List (RPL) IOCB received as an ELS
5595 * unsolicited event. It first checks the remote port state. If the remote
5596 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5597 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5598 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5599 * to accept the RPL.
5600 *
5601 * Return code
5602 * 0 - Successfully processed rpl iocb (currently always return 0)
5603 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005604static int
James Smart2e0fef82007-06-17 19:56:36 -05005605lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5606 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005607{
5608 struct lpfc_dmabuf *pcmd;
5609 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005610 uint32_t maxsize;
5611 uint16_t cmdsize;
5612 RPL *rpl;
5613 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005614
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005615 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5616 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005617 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005618 stat.un.b.lsRjtRsvd0 = 0;
5619 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5620 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5621 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005622 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5623 NULL);
James Smart90160e02008-08-24 21:49:45 -04005624 /* rejected the unsolicited RPL request and done with it */
5625 return 0;
dea31012005-04-17 16:05:31 -05005626 }
5627
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005628 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5629 lp = (uint32_t *) pcmd->virt;
5630 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005631 maxsize = be32_to_cpu(rpl->maxsize);
5632
5633 /* We support only one port */
5634 if ((rpl->index == 0) &&
5635 ((maxsize == 0) ||
5636 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5637 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005638 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005639 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5640 }
James Smart2e0fef82007-06-17 19:56:36 -05005641 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005642
5643 return 0;
5644}
5645
James Smarte59058c2008-08-24 21:49:00 -04005646/**
James Smart3621a712009-04-06 18:47:14 -04005647 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005648 * @vport: pointer to a virtual N_Port data structure.
5649 * @cmdiocb: pointer to lpfc command iocb data structure.
5650 * @ndlp: pointer to a node-list data structure.
5651 *
5652 * This routine processes Fibre Channel Address Resolution Protocol
5653 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5654 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5655 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5656 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5657 * remote PortName is compared against the FC PortName stored in the @vport
5658 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5659 * compared against the FC NodeName stored in the @vport data structure.
5660 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5661 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5662 * invoked to send out FARP Response to the remote node. Before sending the
5663 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5664 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5665 * routine is invoked to log into the remote port first.
5666 *
5667 * Return code
5668 * 0 - Either the FARP Match Mode not supported or successfully processed
5669 **/
dea31012005-04-17 16:05:31 -05005670static int
James Smart2e0fef82007-06-17 19:56:36 -05005671lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5672 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005673{
5674 struct lpfc_dmabuf *pcmd;
5675 uint32_t *lp;
5676 IOCB_t *icmd;
5677 FARP *fp;
5678 uint32_t cmd, cnt, did;
5679
5680 icmd = &cmdiocb->iocb;
5681 did = icmd->un.elsreq64.remoteID;
5682 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5683 lp = (uint32_t *) pcmd->virt;
5684
5685 cmd = *lp++;
5686 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005687 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005688 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5689 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005690 /* We will only support match on WWPN or WWNN */
5691 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005692 return 0;
dea31012005-04-17 16:05:31 -05005693 }
5694
5695 cnt = 0;
5696 /* If this FARP command is searching for my portname */
5697 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005698 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005699 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005700 cnt = 1;
5701 }
5702
5703 /* If this FARP command is searching for my nodename */
5704 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005705 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005706 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005707 cnt = 1;
5708 }
5709
5710 if (cnt) {
5711 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5712 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5713 /* Log back into the node before sending the FARP. */
5714 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005715 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005716 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005717 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005718 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005719 }
5720
5721 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005722 if (fp->Rflags & FARP_REQUEST_FARPR)
5723 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005724 }
5725 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005726 return 0;
dea31012005-04-17 16:05:31 -05005727}
5728
James Smarte59058c2008-08-24 21:49:00 -04005729/**
James Smart3621a712009-04-06 18:47:14 -04005730 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005731 * @vport: pointer to a host virtual N_Port data structure.
5732 * @cmdiocb: pointer to lpfc command iocb data structure.
5733 * @ndlp: pointer to a node-list data structure.
5734 *
5735 * This routine processes Fibre Channel Address Resolution Protocol
5736 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5737 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5738 * the FARP response request.
5739 *
5740 * Return code
5741 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5742 **/
dea31012005-04-17 16:05:31 -05005743static int
James Smart2e0fef82007-06-17 19:56:36 -05005744lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5745 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005746{
5747 struct lpfc_dmabuf *pcmd;
5748 uint32_t *lp;
5749 IOCB_t *icmd;
5750 uint32_t cmd, did;
5751
5752 icmd = &cmdiocb->iocb;
5753 did = icmd->un.elsreq64.remoteID;
5754 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5755 lp = (uint32_t *) pcmd->virt;
5756
5757 cmd = *lp++;
5758 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005759 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5760 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005761 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005762 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005763
5764 return 0;
5765}
5766
James Smarte59058c2008-08-24 21:49:00 -04005767/**
James Smart3621a712009-04-06 18:47:14 -04005768 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005769 * @vport: pointer to a host virtual N_Port data structure.
5770 * @cmdiocb: pointer to lpfc command iocb data structure.
5771 * @fan_ndlp: pointer to a node-list data structure.
5772 *
5773 * This routine processes a Fabric Address Notification (FAN) IOCB
5774 * command received as an ELS unsolicited event. The FAN ELS command will
5775 * only be processed on a physical port (i.e., the @vport represents the
5776 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5777 * compared against those in the phba data structure. If any of those is
5778 * different, the lpfc_initial_flogi() routine is invoked to initialize
5779 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5780 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5781 * is invoked to register login to the fabric.
5782 *
5783 * Return code
5784 * 0 - Successfully processed fan iocb (currently always return 0).
5785 **/
dea31012005-04-17 16:05:31 -05005786static int
James Smart2e0fef82007-06-17 19:56:36 -05005787lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5788 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005789{
James Smart2e0fef82007-06-17 19:56:36 -05005790 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005791 uint32_t *lp;
5792 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005793
James Smart0d2b6b82008-06-14 22:52:47 -04005794 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5795 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5796 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005797 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005798 if ((vport == phba->pport) &&
5799 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005800 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005801 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005802 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005803 sizeof(struct lpfc_name)))) {
5804 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05005805 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005806 } else {
5807 /* FAN verified - skip FLOGI */
5808 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005809 if (phba->sli_rev < LPFC_SLI_REV4)
5810 lpfc_issue_fabric_reglogin(vport);
5811 else
5812 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005813 }
dea31012005-04-17 16:05:31 -05005814 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005815 return 0;
dea31012005-04-17 16:05:31 -05005816}
5817
James Smarte59058c2008-08-24 21:49:00 -04005818/**
James Smart3621a712009-04-06 18:47:14 -04005819 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005820 * @ptr: holder for the timer function associated data.
5821 *
5822 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5823 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5824 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5825 * up the worker thread. It is for the worker thread to invoke the routine
5826 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5827 **/
dea31012005-04-17 16:05:31 -05005828void
5829lpfc_els_timeout(unsigned long ptr)
5830{
James Smart2e0fef82007-06-17 19:56:36 -05005831 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5832 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005833 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005834 unsigned long iflag;
5835
James Smart2e0fef82007-06-17 19:56:36 -05005836 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005837 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5838 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005839 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005840 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005841
James Smart5e9d9b82008-06-14 22:52:53 -04005842 if (!tmo_posted)
5843 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005844 return;
5845}
5846
James Smart2a9bf3d2010-06-07 15:24:45 -04005847
James Smarte59058c2008-08-24 21:49:00 -04005848/**
James Smart3621a712009-04-06 18:47:14 -04005849 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005850 * @vport: pointer to a virtual N_Port data structure.
5851 *
5852 * This routine is the actual handler function that processes an ELS timeout
5853 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5854 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5855 * invoking the lpfc_sli_issue_abort_iotag() routine.
5856 **/
dea31012005-04-17 16:05:31 -05005857void
James Smart2e0fef82007-06-17 19:56:36 -05005858lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005859{
James Smart2e0fef82007-06-17 19:56:36 -05005860 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005861 struct lpfc_sli_ring *pring;
5862 struct lpfc_iocbq *tmp_iocb, *piocb;
5863 IOCB_t *cmd = NULL;
5864 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005865 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005866 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005867 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005868 LIST_HEAD(txcmplq_completions);
5869 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005870
James Smart2a9bf3d2010-06-07 15:24:45 -04005871
dea31012005-04-17 16:05:31 -05005872 timeout = (uint32_t)(phba->fc_ratov << 1);
5873
5874 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005875
James Smart2a9bf3d2010-06-07 15:24:45 -04005876 spin_lock_irq(&phba->hbalock);
5877 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5878 spin_unlock_irq(&phba->hbalock);
5879
5880 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005881 cmd = &piocb->iocb;
5882
James Smart2e0fef82007-06-17 19:56:36 -05005883 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5884 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5885 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005886 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005887
5888 if (piocb->vport != vport)
5889 continue;
5890
dea31012005-04-17 16:05:31 -05005891 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005892 if (pcmd)
5893 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005894
James Smart92d7f7b2007-06-17 19:56:38 -05005895 if (els_command == ELS_CMD_FARP ||
5896 els_command == ELS_CMD_FARPR ||
5897 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005898 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005899
dea31012005-04-17 16:05:31 -05005900 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005901 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005902 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005903 else
dea31012005-04-17 16:05:31 -05005904 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005905 continue;
5906 }
5907
James Smart2e0fef82007-06-17 19:56:36 -05005908 remote_ID = 0xffffffff;
5909 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005910 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005911 else {
5912 struct lpfc_nodelist *ndlp;
5913 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005914 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005915 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005916 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005917 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05005918 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005919 spin_lock_irq(&phba->hbalock);
5920 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05005921 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005922
James Smart2a9bf3d2010-06-07 15:24:45 -04005923 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5924 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5925 "0127 ELS timeout Data: x%x x%x x%x "
5926 "x%x\n", els_command,
5927 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5928 spin_lock_irq(&phba->hbalock);
5929 list_del_init(&piocb->dlist);
5930 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5931 spin_unlock_irq(&phba->hbalock);
5932 }
5933
James Smart2e0fef82007-06-17 19:56:36 -05005934 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5935 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005936}
5937
James Smarte59058c2008-08-24 21:49:00 -04005938/**
James Smart3621a712009-04-06 18:47:14 -04005939 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005940 * @vport: pointer to a host virtual N_Port data structure.
5941 *
5942 * This routine is used to clean up all the outstanding ELS commands on a
5943 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5944 * routine. After that, it walks the ELS transmit queue to remove all the
5945 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5946 * the IOCBs with a non-NULL completion callback function, the callback
5947 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5948 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5949 * callback function, the IOCB will simply be released. Finally, it walks
5950 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5951 * completion queue IOCB that is associated with the @vport and is not
5952 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5953 * part of the discovery state machine) out to HBA by invoking the
5954 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5955 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5956 * the IOCBs are aborted when this function returns.
5957 **/
dea31012005-04-17 16:05:31 -05005958void
James Smart2e0fef82007-06-17 19:56:36 -05005959lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005960{
James Smart2534ba72007-04-25 09:52:20 -04005961 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005962 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005963 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005964 struct lpfc_iocbq *tmp_iocb, *piocb;
5965 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005966
5967 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005968
James Smart2e0fef82007-06-17 19:56:36 -05005969 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005970 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5971 cmd = &piocb->iocb;
5972
5973 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5974 continue;
5975 }
5976
5977 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005978 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5979 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5980 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5981 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005982 continue;
dea31012005-04-17 16:05:31 -05005983
James Smart2e0fef82007-06-17 19:56:36 -05005984 if (piocb->vport != vport)
5985 continue;
5986
James Smart2534ba72007-04-25 09:52:20 -04005987 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005988 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005989 }
5990
5991 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005992 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5993 continue;
5994 }
dea31012005-04-17 16:05:31 -05005995
James Smart2e0fef82007-06-17 19:56:36 -05005996 if (piocb->vport != vport)
5997 continue;
5998
James Smart07951072007-04-25 09:51:38 -04005999 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05006000 }
James Smart2e0fef82007-06-17 19:56:36 -05006001 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04006002
James Smarta257bf92009-04-06 18:48:10 -04006003 /* Cancell all the IOCBs from the completions list */
6004 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6005 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04006006
dea31012005-04-17 16:05:31 -05006007 return;
6008}
6009
James Smarte59058c2008-08-24 21:49:00 -04006010/**
James Smart3621a712009-04-06 18:47:14 -04006011 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04006012 * @phba: pointer to lpfc hba data structure.
6013 *
6014 * This routine is used to clean up all the outstanding ELS commands on a
6015 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6016 * routine. After that, it walks the ELS transmit queue to remove all the
6017 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6018 * the IOCBs with the completion callback function associated, the callback
6019 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6020 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6021 * callback function associated, the IOCB will simply be released. Finally,
6022 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6023 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6024 * management plane IOCBs that are not part of the discovery state machine)
6025 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6026 **/
James Smart549e55c2007-08-02 11:09:51 -04006027void
6028lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6029{
6030 LIST_HEAD(completions);
6031 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6032 struct lpfc_iocbq *tmp_iocb, *piocb;
6033 IOCB_t *cmd = NULL;
6034
6035 lpfc_fabric_abort_hba(phba);
6036 spin_lock_irq(&phba->hbalock);
6037 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6038 cmd = &piocb->iocb;
6039 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6040 continue;
6041 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6042 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6043 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6044 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6045 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6046 continue;
6047 list_move_tail(&piocb->list, &completions);
6048 pring->txq_cnt--;
6049 }
6050 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6051 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6052 continue;
6053 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6054 }
6055 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04006056
6057 /* Cancel all the IOCBs from the completions list */
6058 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6059 IOERR_SLI_ABORTED);
6060
James Smart549e55c2007-08-02 11:09:51 -04006061 return;
6062}
6063
James Smarte59058c2008-08-24 21:49:00 -04006064/**
James Smart3621a712009-04-06 18:47:14 -04006065 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04006066 * @phba: Pointer to hba context object.
6067 * @cmdiocbp: Pointer to command iocb which reported error.
6068 * @rspiocbp: Pointer to response iocb which reported error.
6069 *
6070 * This function sends an event when there is an ELS command
6071 * failure.
6072 **/
6073void
6074lpfc_send_els_failure_event(struct lpfc_hba *phba,
6075 struct lpfc_iocbq *cmdiocbp,
6076 struct lpfc_iocbq *rspiocbp)
6077{
6078 struct lpfc_vport *vport = cmdiocbp->vport;
6079 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6080 struct lpfc_lsrjt_event lsrjt_event;
6081 struct lpfc_fabric_event_header fabric_event;
6082 struct ls_rjt stat;
6083 struct lpfc_nodelist *ndlp;
6084 uint32_t *pcmd;
6085
6086 ndlp = cmdiocbp->context1;
6087 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6088 return;
6089
6090 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6091 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6092 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6093 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6094 sizeof(struct lpfc_name));
6095 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6096 sizeof(struct lpfc_name));
6097 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6098 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006099 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006100 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6101 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6102 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6103 fc_host_post_vendor_event(shost,
6104 fc_get_event_number(),
6105 sizeof(lsrjt_event),
6106 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006107 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006108 return;
6109 }
6110 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6111 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6112 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6113 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6114 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6115 else
6116 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6117 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6118 sizeof(struct lpfc_name));
6119 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6120 sizeof(struct lpfc_name));
6121 fc_host_post_vendor_event(shost,
6122 fc_get_event_number(),
6123 sizeof(fabric_event),
6124 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006125 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006126 return;
6127 }
6128
6129}
6130
6131/**
James Smart3621a712009-04-06 18:47:14 -04006132 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006133 * @vport: Pointer to vport object.
6134 * @ndlp: Pointer FC node object.
6135 * @cmd: ELS command code.
6136 *
6137 * This function posts an event when there is an incoming
6138 * unsolicited ELS command.
6139 **/
6140static void
6141lpfc_send_els_event(struct lpfc_vport *vport,
6142 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006143 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006144{
James Smartddcc50f2008-12-04 22:38:46 -05006145 struct lpfc_els_event_header *els_data = NULL;
6146 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006147 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6148
James Smartddcc50f2008-12-04 22:38:46 -05006149 if (*payload == ELS_CMD_LOGO) {
6150 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6151 if (!logo_data) {
6152 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6153 "0148 Failed to allocate memory "
6154 "for LOGO event\n");
6155 return;
6156 }
6157 els_data = &logo_data->header;
6158 } else {
6159 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6160 GFP_KERNEL);
6161 if (!els_data) {
6162 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6163 "0149 Failed to allocate memory "
6164 "for ELS event\n");
6165 return;
6166 }
6167 }
6168 els_data->event_type = FC_REG_ELS_EVENT;
6169 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006170 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006171 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006172 break;
6173 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006174 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006175 break;
6176 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006177 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6178 break;
6179 case ELS_CMD_LOGO:
6180 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6181 /* Copy the WWPN in the LOGO payload */
6182 memcpy(logo_data->logo_wwpn, &payload[2],
6183 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006184 break;
6185 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006186 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006187 return;
6188 }
James Smartddcc50f2008-12-04 22:38:46 -05006189 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6190 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6191 if (*payload == ELS_CMD_LOGO) {
6192 fc_host_post_vendor_event(shost,
6193 fc_get_event_number(),
6194 sizeof(struct lpfc_logo_event),
6195 (char *)logo_data,
6196 LPFC_NL_VENDOR_ID);
6197 kfree(logo_data);
6198 } else {
6199 fc_host_post_vendor_event(shost,
6200 fc_get_event_number(),
6201 sizeof(struct lpfc_els_event_header),
6202 (char *)els_data,
6203 LPFC_NL_VENDOR_ID);
6204 kfree(els_data);
6205 }
James Smartea2151b2008-09-07 11:52:10 -04006206
6207 return;
6208}
6209
6210
6211/**
James Smart3621a712009-04-06 18:47:14 -04006212 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006213 * @phba: pointer to lpfc hba data structure.
6214 * @pring: pointer to a SLI ring.
6215 * @vport: pointer to a host virtual N_Port data structure.
6216 * @elsiocb: pointer to lpfc els command iocb data structure.
6217 *
6218 * This routine is used for processing the IOCB associated with a unsolicited
6219 * event. It first determines whether there is an existing ndlp that matches
6220 * the DID from the unsolicited IOCB. If not, it will create a new one with
6221 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6222 * IOCB is then used to invoke the proper routine and to set up proper state
6223 * of the discovery state machine.
6224 **/
James Smarted957682007-06-17 19:56:37 -05006225static void
6226lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006227 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006228{
James Smart87af33f2007-10-27 13:37:43 -04006229 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006230 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006231 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006232 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05006233 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006234 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006235
James Smarte47c9092008-02-08 18:49:26 -05006236 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006237 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006238
dea31012005-04-17 16:05:31 -05006239 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006240 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6241 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006242 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006243 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006244
James Smart858c9f62007-06-17 19:56:39 -05006245 did = icmd->un.rcvels.remoteID;
6246 if (icmd->ulpStatus) {
6247 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6248 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6249 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006250 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006251 }
dea31012005-04-17 16:05:31 -05006252
6253 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006254 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006255 goto dropit;
dea31012005-04-17 16:05:31 -05006256
James Smartc8685952009-11-18 15:39:16 -05006257 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006258 if (vport->load_flag & FC_UNLOADING)
6259 goto dropit;
6260
James Smart92494142011-02-16 12:39:44 -05006261 /* If NPort discovery is delayed drop incoming ELS */
6262 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6263 (cmd != ELS_CMD_PLOGI))
6264 goto dropit;
6265
James Smart2e0fef82007-06-17 19:56:36 -05006266 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006267 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006268 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006269 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006270 if (!ndlp)
dea31012005-04-17 16:05:31 -05006271 goto dropit;
dea31012005-04-17 16:05:31 -05006272
James Smart2e0fef82007-06-17 19:56:36 -05006273 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006274 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006275 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006276 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006277 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006278 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6279 ndlp = lpfc_enable_node(vport, ndlp,
6280 NLP_STE_UNUSED_NODE);
6281 if (!ndlp)
6282 goto dropit;
6283 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6284 newnode = 1;
6285 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6286 ndlp->nlp_type |= NLP_FABRIC;
6287 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6288 /* This is similar to the new node path */
6289 ndlp = lpfc_nlp_get(ndlp);
6290 if (!ndlp)
6291 goto dropit;
6292 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6293 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006294 }
dea31012005-04-17 16:05:31 -05006295
6296 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006297
James Smart329f9bc2007-04-25 09:53:01 -04006298 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006299 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006300
6301 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6302 cmd &= ELS_CMD_MASK;
6303 }
6304 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006305 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6306 "0112 ELS command x%x received from NPORT x%x "
6307 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006308 switch (cmd) {
6309 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006310 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6311 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6312 did, vport->port_state, ndlp->nlp_flag);
6313
dea31012005-04-17 16:05:31 -05006314 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006315 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6316
James Smartddcc50f2008-12-04 22:38:46 -05006317 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05006318
6319 /* If Nport discovery is delayed, reject PLOGIs */
6320 if (vport->fc_flag & FC_DISC_DELAYED) {
6321 rjt_err = LSRJT_UNABLE_TPC;
6322 break;
6323 }
James Smart858c9f62007-06-17 19:56:39 -05006324 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006325 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6326 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6327 rjt_err = LSRJT_UNABLE_TPC;
6328 break;
6329 }
6330 /* We get here, and drop thru, if we are PT2PT with
6331 * another NPort and the other side has initiated
6332 * the PLOGI before responding to our FLOGI.
6333 */
dea31012005-04-17 16:05:31 -05006334 }
James Smart87af33f2007-10-27 13:37:43 -04006335
6336 shost = lpfc_shost_from_vport(vport);
6337 spin_lock_irq(shost->host_lock);
6338 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6339 spin_unlock_irq(shost->host_lock);
6340
James Smart2e0fef82007-06-17 19:56:36 -05006341 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6342 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006343
dea31012005-04-17 16:05:31 -05006344 break;
6345 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006346 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6347 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6348 did, vport->port_state, ndlp->nlp_flag);
6349
dea31012005-04-17 16:05:31 -05006350 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006351 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006352 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006353 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006354 break;
6355 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006356 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6357 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6358 did, vport->port_state, ndlp->nlp_flag);
6359
dea31012005-04-17 16:05:31 -05006360 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006361 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006362 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006363 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006364 break;
6365 }
James Smart2e0fef82007-06-17 19:56:36 -05006366 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006367 break;
6368 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006369 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6370 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6371 did, vport->port_state, ndlp->nlp_flag);
6372
dea31012005-04-17 16:05:31 -05006373 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006374 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006375 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006376 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006377 break;
6378 }
James Smart2e0fef82007-06-17 19:56:36 -05006379 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006380 break;
6381 case ELS_CMD_RSCN:
6382 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006383 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006384 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006385 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006386 break;
6387 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006388 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6389 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6390 did, vport->port_state, ndlp->nlp_flag);
6391
James Smartddcc50f2008-12-04 22:38:46 -05006392 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006393 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006394 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006395 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006396 break;
6397 }
James Smart2e0fef82007-06-17 19:56:36 -05006398 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6399 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006400 break;
6401 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006402 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6403 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6404 did, vport->port_state, ndlp->nlp_flag);
6405
dea31012005-04-17 16:05:31 -05006406 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006407 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006408 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006409 break;
6410 }
James Smart2e0fef82007-06-17 19:56:36 -05006411 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6412 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006413 break;
6414 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006415 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6416 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6417 did, vport->port_state, ndlp->nlp_flag);
6418
dea31012005-04-17 16:05:31 -05006419 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006420 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006421 break;
6422 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006423 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6424 "RCV FARP: 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.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006428 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006429 break;
6430 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006431 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6432 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6433 did, vport->port_state, ndlp->nlp_flag);
6434
dea31012005-04-17 16:05:31 -05006435 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006436 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006437 break;
dea31012005-04-17 16:05:31 -05006438 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006439 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6440 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6441 did, vport->port_state, ndlp->nlp_flag);
6442
dea31012005-04-17 16:05:31 -05006443 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006444 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006445 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006446 break;
6447 }
James Smart2e0fef82007-06-17 19:56:36 -05006448 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006449 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006450 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006451 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6452 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6453 did, vport->port_state, ndlp->nlp_flag);
6454
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006455 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006456 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006457 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006458 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006459 break;
James Smart12265f62010-10-22 11:05:53 -04006460 case ELS_CMD_RLS:
6461 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6462 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6463 did, vport->port_state, ndlp->nlp_flag);
6464
6465 phba->fc_stat.elsRcvRLS++;
6466 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6467 if (newnode)
6468 lpfc_nlp_put(ndlp);
6469 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006470 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006471 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6472 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6473 did, vport->port_state, ndlp->nlp_flag);
6474
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006475 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006476 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006477 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006478 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006479 break;
6480 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006481 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6482 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6483 did, vport->port_state, ndlp->nlp_flag);
6484
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006485 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006486 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006487 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006488 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006489 break;
dea31012005-04-17 16:05:31 -05006490 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006491 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6492 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6493 did, vport->port_state, ndlp->nlp_flag);
6494
dea31012005-04-17 16:05:31 -05006495 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006496 lpfc_els_rcv_rnid(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;
James Smart12265f62010-10-22 11:05:53 -04006500 case ELS_CMD_RTV:
6501 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6502 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6503 did, vport->port_state, ndlp->nlp_flag);
6504 phba->fc_stat.elsRcvRTV++;
6505 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6506 if (newnode)
6507 lpfc_nlp_put(ndlp);
6508 break;
James Smart5ffc2662009-11-18 15:39:44 -05006509 case ELS_CMD_RRQ:
6510 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6511 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6512 did, vport->port_state, ndlp->nlp_flag);
6513
6514 phba->fc_stat.elsRcvRRQ++;
6515 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6516 if (newnode)
6517 lpfc_nlp_put(ndlp);
6518 break;
James Smart12265f62010-10-22 11:05:53 -04006519 case ELS_CMD_ECHO:
6520 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6521 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6522 did, vport->port_state, ndlp->nlp_flag);
6523
6524 phba->fc_stat.elsRcvECHO++;
6525 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6526 if (newnode)
6527 lpfc_nlp_put(ndlp);
6528 break;
dea31012005-04-17 16:05:31 -05006529 default:
James Smart858c9f62007-06-17 19:56:39 -05006530 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6531 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6532 cmd, did, vport->port_state);
6533
dea31012005-04-17 16:05:31 -05006534 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006535 rjt_err = LSRJT_CMD_UNSUPPORTED;
dea31012005-04-17 16:05:31 -05006536
6537 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006538 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6539 "0115 Unknown ELS command x%x "
6540 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006541 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006542 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006543 break;
6544 }
6545
6546 /* check if need to LS_RJT received ELS cmd */
6547 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006548 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006549 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006550 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006551 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6552 NULL);
dea31012005-04-17 16:05:31 -05006553 }
6554
James Smartd7c255b2008-08-24 21:50:00 -04006555 lpfc_nlp_put(elsiocb->context1);
6556 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006557 return;
6558
6559dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006560 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006561 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6562 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006563 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006564 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006565 phba->fc_stat.elsRcvDrop++;
6566}
6567
James Smarte59058c2008-08-24 21:49:00 -04006568/**
James Smart3621a712009-04-06 18:47:14 -04006569 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04006570 * @phba: pointer to lpfc hba data structure.
6571 * @vpi: host virtual N_Port identifier.
6572 *
6573 * This routine finds a vport on a HBA (referred by @phba) through a
6574 * @vpi. The function walks the HBA's vport list and returns the address
6575 * of the vport with the matching @vpi.
6576 *
6577 * Return code
6578 * NULL - No vport with the matching @vpi found
6579 * Otherwise - Address to the vport with the matching @vpi.
6580 **/
James Smart6669f9b2009-10-02 15:16:45 -04006581struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05006582lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6583{
6584 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04006585 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05006586
James Smart549e55c2007-08-02 11:09:51 -04006587 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006588 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04006589 if (vport->vpi == vpi) {
6590 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006591 return vport;
James Smart549e55c2007-08-02 11:09:51 -04006592 }
James Smart92d7f7b2007-06-17 19:56:38 -05006593 }
James Smart549e55c2007-08-02 11:09:51 -04006594 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006595 return NULL;
6596}
James Smarted957682007-06-17 19:56:37 -05006597
James Smarte59058c2008-08-24 21:49:00 -04006598/**
James Smart3621a712009-04-06 18:47:14 -04006599 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006600 * @phba: pointer to lpfc hba data structure.
6601 * @pring: pointer to a SLI ring.
6602 * @elsiocb: pointer to lpfc els iocb data structure.
6603 *
6604 * This routine is used to process an unsolicited event received from a SLI
6605 * (Service Level Interface) ring. The actual processing of the data buffer
6606 * associated with the unsolicited event is done by invoking the routine
6607 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6608 * SLI ring on which the unsolicited event was received.
6609 **/
James Smarted957682007-06-17 19:56:37 -05006610void
6611lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6612 struct lpfc_iocbq *elsiocb)
6613{
6614 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006615 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006616 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006617 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6618 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006619
James Smartd7c255b2008-08-24 21:50:00 -04006620 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006621 elsiocb->context2 = NULL;
6622 elsiocb->context3 = NULL;
6623
6624 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6625 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6626 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6627 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006628 phba->fc_stat.NoRcvBuf++;
6629 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006630 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006631 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006632 return;
6633 }
6634
James Smart92d7f7b2007-06-17 19:56:38 -05006635 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6636 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6637 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6638 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6639 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006640 else
6641 vport = lpfc_find_vport_by_vpid(phba,
6642 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05006643 }
James Smart7f5f3d02008-02-08 18:50:14 -05006644 /* If there are no BDEs associated
6645 * with this IOCB, there is nothing to do.
6646 */
James Smarted957682007-06-17 19:56:37 -05006647 if (icmd->ulpBdeCount == 0)
6648 return;
6649
James Smart7f5f3d02008-02-08 18:50:14 -05006650 /* type of ELS cmd is first 32bit word
6651 * in packet
6652 */
James Smarted957682007-06-17 19:56:37 -05006653 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006654 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006655 } else {
6656 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6657 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006658 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6659 paddr);
James Smarted957682007-06-17 19:56:37 -05006660 }
6661
James Smart92d7f7b2007-06-17 19:56:38 -05006662 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6663 /*
6664 * The different unsolicited event handlers would tell us
6665 * if they are done with "mp" by setting context2 to NULL.
6666 */
dea31012005-04-17 16:05:31 -05006667 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006668 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6669 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006670 }
James Smarted957682007-06-17 19:56:37 -05006671
6672 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006673 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006674 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006675 elsiocb->context2 = bdeBuf2;
6676 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006677 /* free mp if we are done with it */
6678 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006679 lpfc_in_buf_free(phba, elsiocb->context2);
6680 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006681 }
dea31012005-04-17 16:05:31 -05006682 }
dea31012005-04-17 16:05:31 -05006683}
James Smart92d7f7b2007-06-17 19:56:38 -05006684
James Smarte59058c2008-08-24 21:49:00 -04006685/**
James Smart3621a712009-04-06 18:47:14 -04006686 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006687 * @phba: pointer to lpfc hba data structure.
6688 * @vport: pointer to a virtual N_Port data structure.
6689 *
6690 * This routine issues a Port Login (PLOGI) to the Name Server with
6691 * State Change Request (SCR) for a @vport. This routine will create an
6692 * ndlp for the Name Server associated to the @vport if such node does
6693 * not already exist. The PLOGI to Name Server is issued by invoking the
6694 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6695 * (FDMI) is configured to the @vport, a FDMI node will be created and
6696 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6697 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006698void
6699lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6700{
6701 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05006702 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6703
6704 /*
6705 * If lpfc_delay_discovery parameter is set and the clean address
6706 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6707 * discovery.
6708 */
6709 spin_lock_irq(shost->host_lock);
6710 if (vport->fc_flag & FC_DISC_DELAYED) {
6711 spin_unlock_irq(shost->host_lock);
6712 mod_timer(&vport->delayed_disc_tmo,
6713 jiffies + HZ * phba->fc_ratov);
6714 return;
6715 }
6716 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006717
6718 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6719 if (!ndlp) {
6720 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6721 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006722 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05006723 lpfc_disc_start(vport);
6724 return;
6725 }
6726 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006727 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6728 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006729 return;
6730 }
6731 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006732 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6733 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6734 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006735 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05006736 lpfc_disc_start(vport);
6737 return;
6738 }
6739 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6740 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6741 "0348 NameServer login: node freed\n");
6742 return;
6743 }
James Smart92d7f7b2007-06-17 19:56:38 -05006744 }
James Smart58da1ff2008-04-07 10:15:56 -04006745 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006746
6747 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6748
6749 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6750 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006751 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6752 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006753 return;
6754 }
6755
James Smart3de2a652007-08-02 11:09:59 -04006756 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05006757 /* If this is the first time, allocate an ndlp and initialize
6758 * it. Otherwise, make sure the node is enabled and then do the
6759 * login.
6760 */
6761 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
6762 if (!ndlp_fdmi) {
6763 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6764 GFP_KERNEL);
6765 if (ndlp_fdmi) {
6766 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6767 ndlp_fdmi->nlp_type |= NLP_FABRIC;
6768 } else
6769 return;
6770 }
6771 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
6772 ndlp_fdmi = lpfc_enable_node(vport,
6773 ndlp_fdmi,
6774 NLP_STE_NPR_NODE);
6775
James Smart92d7f7b2007-06-17 19:56:38 -05006776 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04006777 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05006778 NLP_STE_PLOGI_ISSUE);
6779 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006780 }
6781 }
James Smart92d7f7b2007-06-17 19:56:38 -05006782}
6783
James Smarte59058c2008-08-24 21:49:00 -04006784/**
James Smart3621a712009-04-06 18:47:14 -04006785 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006786 * @phba: pointer to lpfc hba data structure.
6787 * @pmb: pointer to the driver internal queue element for mailbox command.
6788 *
6789 * This routine is the completion callback function to register new vport
6790 * mailbox command. If the new vport mailbox command completes successfully,
6791 * the fabric registration login shall be performed on physical port (the
6792 * new vport created is actually a physical port, with VPI 0) or the port
6793 * login to Name Server for State Change Request (SCR) will be performed
6794 * on virtual port (real virtual port, with VPI greater than 0).
6795 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006796static void
6797lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6798{
6799 struct lpfc_vport *vport = pmb->vport;
6800 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6801 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006802 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006803 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006804
James Smart09372822008-01-11 01:52:54 -05006805 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006806 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006807 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006808
6809 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006810 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006811 "0915 Register VPI failed : Status: x%x"
6812 " upd bit: x%x \n", mb->mbxStatus,
6813 mb->un.varRegVpi.upd);
6814 if (phba->sli_rev == LPFC_SLI_REV4 &&
6815 mb->un.varRegVpi.upd)
6816 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006817
6818 switch (mb->mbxStatus) {
6819 case 0x11: /* unsupported feature */
6820 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006821 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006822 /* giving up on vport registration */
6823 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6824 spin_lock_irq(shost->host_lock);
6825 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6826 spin_unlock_irq(shost->host_lock);
6827 lpfc_can_disctmo(vport);
6828 break;
James Smart695a8142010-01-26 23:08:03 -05006829 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6830 case 0x20:
6831 spin_lock_irq(shost->host_lock);
6832 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6833 spin_unlock_irq(shost->host_lock);
6834 lpfc_init_vpi(phba, pmb, vport->vpi);
6835 pmb->vport = vport;
6836 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6837 rc = lpfc_sli_issue_mbox(phba, pmb,
6838 MBX_NOWAIT);
6839 if (rc == MBX_NOT_FINISHED) {
6840 lpfc_printf_vlog(vport,
6841 KERN_ERR, LOG_MBOX,
6842 "2732 Failed to issue INIT_VPI"
6843 " mailbox command\n");
6844 } else {
6845 lpfc_nlp_put(ndlp);
6846 return;
6847 }
6848
James Smart92d7f7b2007-06-17 19:56:38 -05006849 default:
6850 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04006851 if (phba->sli_rev == LPFC_SLI_REV4)
6852 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006853 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006854 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006855 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006856 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006857 if (vport->port_type == LPFC_PHYSICAL_PORT
6858 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05006859 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05006860 else
6861 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006862 break;
6863 }
James Smart92d7f7b2007-06-17 19:56:38 -05006864 } else {
James Smart695a8142010-01-26 23:08:03 -05006865 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006866 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006867 spin_unlock_irq(shost->host_lock);
6868 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006869 if (phba->sli_rev < LPFC_SLI_REV4)
6870 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006871 else {
James Smartfc2b9892010-02-26 14:15:29 -05006872 /*
6873 * If the physical port is instantiated using
6874 * FDISC, do not start vport discovery.
6875 */
6876 if (vport->port_state != LPFC_FDISC)
6877 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006878 lpfc_do_scr_ns_plogi(phba, vport);
6879 }
6880 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006881 lpfc_do_scr_ns_plogi(phba, vport);
6882 }
James Smart38b92ef2010-08-04 16:11:39 -04006883mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05006884 /* Now, we decrement the ndlp reference count held for this
6885 * callback function
6886 */
6887 lpfc_nlp_put(ndlp);
6888
James Smart92d7f7b2007-06-17 19:56:38 -05006889 mempool_free(pmb, phba->mbox_mem_pool);
6890 return;
6891}
6892
James Smarte59058c2008-08-24 21:49:00 -04006893/**
James Smart3621a712009-04-06 18:47:14 -04006894 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006895 * @phba: pointer to lpfc hba data structure.
6896 * @vport: pointer to a host virtual N_Port data structure.
6897 * @ndlp: pointer to a node-list data structure.
6898 *
6899 * This routine registers the @vport as a new virtual port with a HBA.
6900 * It is done through a registering vpi mailbox command.
6901 **/
James Smart695a8142010-01-26 23:08:03 -05006902void
James Smart92d7f7b2007-06-17 19:56:38 -05006903lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6904 struct lpfc_nodelist *ndlp)
6905{
James Smart09372822008-01-11 01:52:54 -05006906 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006907 LPFC_MBOXQ_t *mbox;
6908
6909 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6910 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006911 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006912 mbox->vport = vport;
6913 mbox->context2 = lpfc_nlp_get(ndlp);
6914 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006915 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006916 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006917 /* mailbox command not success, decrement ndlp
6918 * reference count for this command
6919 */
6920 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006921 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006922
James Smarte8b62012007-08-02 11:10:09 -04006923 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6924 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006925 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006926 }
6927 } else {
James Smarte8b62012007-08-02 11:10:09 -04006928 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6929 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006930 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006931 }
James Smartfa4066b2008-01-11 01:53:27 -05006932 return;
6933
6934mbox_err_exit:
6935 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6936 spin_lock_irq(shost->host_lock);
6937 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6938 spin_unlock_irq(shost->host_lock);
6939 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006940}
6941
James Smarte59058c2008-08-24 21:49:00 -04006942/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006943 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006944 * @phba: pointer to lpfc hba data structure.
6945 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006946 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006947 **/
6948void
James Smart0c9ab6f2010-02-26 14:15:57 -05006949lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006950{
6951 struct lpfc_vport **vports;
6952 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006953 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006954 int i;
James Smart695a8142010-01-26 23:08:03 -05006955
6956 /* Treat this failure as linkdown for all vports */
6957 link_state = phba->link_state;
6958 lpfc_linkdown(phba);
6959 phba->link_state = link_state;
6960
6961 vports = lpfc_create_vport_work_array(phba);
6962
6963 if (vports) {
6964 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6965 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6966 if (ndlp)
6967 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6968 lpfc_els_flush_cmd(vports[i]);
6969 }
6970 lpfc_destroy_vport_work_array(phba, vports);
6971 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006972}
6973
6974/**
6975 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6976 * @phba: pointer to lpfc hba data structure.
6977 *
6978 * This routine abort all pending discovery commands and
6979 * start a timer to retry FLOGI for the physical port
6980 * discovery.
6981 **/
6982void
6983lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6984{
6985 struct lpfc_nodelist *ndlp;
6986 struct Scsi_Host *shost;
6987
6988 /* Cancel the all vports retry delay retry timers */
6989 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05006990
6991 /* If fabric require FLOGI, then re-instantiate physical login */
6992 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6993 if (!ndlp)
6994 return;
6995
James Smart695a8142010-01-26 23:08:03 -05006996 shost = lpfc_shost_from_vport(phba->pport);
6997 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6998 spin_lock_irq(shost->host_lock);
6999 ndlp->nlp_flag |= NLP_DELAY_TMO;
7000 spin_unlock_irq(shost->host_lock);
7001 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7002 phba->pport->port_state = LPFC_FLOGI;
7003 return;
7004}
7005
7006/**
7007 * lpfc_fabric_login_reqd - Check if FLOGI required.
7008 * @phba: pointer to lpfc hba data structure.
7009 * @cmdiocb: pointer to FDISC command iocb.
7010 * @rspiocb: pointer to FDISC response iocb.
7011 *
7012 * This routine checks if a FLOGI is reguired for FDISC
7013 * to succeed.
7014 **/
7015static int
7016lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7017 struct lpfc_iocbq *cmdiocb,
7018 struct lpfc_iocbq *rspiocb)
7019{
7020
7021 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7022 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7023 return 0;
7024 else
7025 return 1;
7026}
7027
7028/**
James Smart3621a712009-04-06 18:47:14 -04007029 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007030 * @phba: pointer to lpfc hba data structure.
7031 * @cmdiocb: pointer to lpfc command iocb data structure.
7032 * @rspiocb: pointer to lpfc response iocb data structure.
7033 *
7034 * This routine is the completion callback function to a Fabric Discover
7035 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7036 * single threaded, each FDISC completion callback function will reset
7037 * the discovery timer for all vports such that the timers will not get
7038 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7039 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7040 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7041 * assigned to the vport has been changed with the completion of the FDISC
7042 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7043 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7044 * routine is invoked to register new vport with the HBA. Otherwise, the
7045 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7046 * Server for State Change Request (SCR).
7047 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007048static void
7049lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7050 struct lpfc_iocbq *rspiocb)
7051{
7052 struct lpfc_vport *vport = cmdiocb->vport;
7053 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7054 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7055 struct lpfc_nodelist *np;
7056 struct lpfc_nodelist *next_np;
7057 IOCB_t *irsp = &rspiocb->iocb;
7058 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05007059 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7060 struct serv_parm *sp;
7061 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05007062
James Smarte8b62012007-08-02 11:10:09 -04007063 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7064 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7065 irsp->ulpStatus, irsp->un.ulpWord[4],
7066 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05007067 /* Since all FDISCs are being single threaded, we
7068 * must reset the discovery timer for ALL vports
7069 * waiting to send FDISC when one completes.
7070 */
7071 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7072 lpfc_set_disctmo(piocb->vport);
7073 }
7074
James Smart858c9f62007-06-17 19:56:39 -05007075 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7076 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7077 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7078
James Smart92d7f7b2007-06-17 19:56:38 -05007079 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05007080
7081 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7082 lpfc_retry_pport_discovery(phba);
7083 goto out;
7084 }
7085
James Smart92d7f7b2007-06-17 19:56:38 -05007086 /* Check for retry */
7087 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7088 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007089 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04007090 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04007091 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04007092 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04007093 goto fdisc_failed;
7094 }
James Smartd7c255b2008-08-24 21:50:00 -04007095 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05007096 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04007097 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04007098 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05007099 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04007100 vport->fc_flag |= FC_PUBLIC_LOOP;
7101 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007102
James Smartd7c255b2008-08-24 21:50:00 -04007103 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7104 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05007105 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7106 sp = prsp->virt + sizeof(uint32_t);
7107 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7108 memcpy(&vport->fabric_portname, &sp->portName,
7109 sizeof(struct lpfc_name));
7110 memcpy(&vport->fabric_nodename, &sp->nodeName,
7111 sizeof(struct lpfc_name));
7112 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04007113 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7114 /* If our NportID changed, we need to ensure all
7115 * remaining NPORTs get unreg_login'ed so we can
7116 * issue unreg_vpi.
7117 */
7118 list_for_each_entry_safe(np, next_np,
7119 &vport->fc_nodes, nlp_listp) {
7120 if (!NLP_CHK_NODE_ACT(ndlp) ||
7121 (np->nlp_state != NLP_STE_NPR_NODE) ||
7122 !(np->nlp_flag & NLP_NPR_ADISC))
7123 continue;
James Smart09372822008-01-11 01:52:54 -05007124 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007125 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007126 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007127 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007128 }
James Smart78730cf2010-04-06 15:06:30 -04007129 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007130
7131 if (phba->sli_rev == LPFC_SLI_REV4)
7132 lpfc_sli4_unreg_all_rpis(vport);
7133
James Smartd7c255b2008-08-24 21:50:00 -04007134 lpfc_mbx_unreg_vpi(vport);
7135 spin_lock_irq(shost->host_lock);
7136 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007137 if (phba->sli_rev == LPFC_SLI_REV4)
7138 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007139 else
7140 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007141 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007142 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7143 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7144 /*
7145 * Driver needs to re-reg VPI in order for f/w
7146 * to update the MAC address.
7147 */
7148 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007149 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007150 }
7151
James Smartecfd03c2010-02-12 14:41:27 -05007152 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7153 lpfc_issue_init_vpi(vport);
7154 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007155 lpfc_register_new_vport(phba, vport, ndlp);
7156 else
7157 lpfc_do_scr_ns_plogi(phba, vport);
7158 goto out;
7159fdisc_failed:
7160 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7161 /* Cancel discovery timer */
7162 lpfc_can_disctmo(vport);
7163 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007164out:
7165 lpfc_els_free_iocb(phba, cmdiocb);
7166}
7167
James Smarte59058c2008-08-24 21:49:00 -04007168/**
James Smart3621a712009-04-06 18:47:14 -04007169 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007170 * @vport: pointer to a virtual N_Port data structure.
7171 * @ndlp: pointer to a node-list data structure.
7172 * @retry: number of retries to the command IOCB.
7173 *
7174 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7175 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7176 * routine to issue the IOCB, which makes sure only one outstanding fabric
7177 * IOCB will be sent off HBA at any given time.
7178 *
7179 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7180 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7181 * will be stored into the context1 field of the IOCB for the completion
7182 * callback function to the FDISC ELS command.
7183 *
7184 * Return code
7185 * 0 - Successfully issued fdisc iocb command
7186 * 1 - Failed to issue fdisc iocb command
7187 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007188static int
James Smart92d7f7b2007-06-17 19:56:38 -05007189lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7190 uint8_t retry)
7191{
7192 struct lpfc_hba *phba = vport->phba;
7193 IOCB_t *icmd;
7194 struct lpfc_iocbq *elsiocb;
7195 struct serv_parm *sp;
7196 uint8_t *pcmd;
7197 uint16_t cmdsize;
7198 int did = ndlp->nlp_DID;
7199 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007200
James Smart5ffc2662009-11-18 15:39:44 -05007201 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05007202 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7203 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7204 ELS_CMD_FDISC);
7205 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007206 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007207 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7208 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007209 return 1;
7210 }
7211
7212 icmd = &elsiocb->iocb;
7213 icmd->un.elsreq64.myID = 0;
7214 icmd->un.elsreq64.fl = 1;
7215
James Smart40426292010-12-15 17:58:10 -05007216 if ((phba->sli_rev == LPFC_SLI_REV4) &&
7217 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
7218 LPFC_SLI_INTF_IF_TYPE_0)) {
James Smartf1126682009-06-10 17:22:44 -04007219 /* FDISC needs to be 1 for WQE VPI */
7220 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
7221 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
7222 /* Set the ulpContext to the vpi */
7223 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
7224 } else {
7225 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
7226 icmd->ulpCt_h = 1;
7227 icmd->ulpCt_l = 0;
7228 }
James Smart92d7f7b2007-06-17 19:56:38 -05007229
7230 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7231 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7232 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7233 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7234 sp = (struct serv_parm *) pcmd;
7235 /* Setup CSPs accordingly for Fabric */
7236 sp->cmn.e_d_tov = 0;
7237 sp->cmn.w2.r_a_tov = 0;
7238 sp->cls1.classValid = 0;
7239 sp->cls2.seqDelivery = 1;
7240 sp->cls3.seqDelivery = 1;
7241
7242 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7243 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7244 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7245 pcmd += sizeof(uint32_t); /* Port Name */
7246 memcpy(pcmd, &vport->fc_portname, 8);
7247 pcmd += sizeof(uint32_t); /* Node Name */
7248 pcmd += sizeof(uint32_t); /* Node Name */
7249 memcpy(pcmd, &vport->fc_nodename, 8);
7250
7251 lpfc_set_disctmo(vport);
7252
7253 phba->fc_stat.elsXmitFDISC++;
7254 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7255
James Smart858c9f62007-06-17 19:56:39 -05007256 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7257 "Issue FDISC: did:x%x",
7258 did, 0, 0);
7259
James Smart92d7f7b2007-06-17 19:56:38 -05007260 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7261 if (rc == IOCB_ERROR) {
7262 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007263 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007264 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7265 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007266 return 1;
7267 }
7268 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007269 return 0;
7270}
7271
James Smarte59058c2008-08-24 21:49:00 -04007272/**
James Smart3621a712009-04-06 18:47:14 -04007273 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007274 * @phba: pointer to lpfc hba data structure.
7275 * @cmdiocb: pointer to lpfc command iocb data structure.
7276 * @rspiocb: pointer to lpfc response iocb data structure.
7277 *
7278 * This routine is the completion callback function to the issuing of a LOGO
7279 * ELS command off a vport. It frees the command IOCB and then decrement the
7280 * reference count held on ndlp for this completion function, indicating that
7281 * the reference to the ndlp is no long needed. Note that the
7282 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7283 * callback function and an additional explicit ndlp reference decrementation
7284 * will trigger the actual release of the ndlp.
7285 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007286static void
7287lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7288 struct lpfc_iocbq *rspiocb)
7289{
7290 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007291 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007292 struct lpfc_nodelist *ndlp;
7293 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007294
7295 irsp = &rspiocb->iocb;
7296 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7297 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7298 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007299
7300 lpfc_els_free_iocb(phba, cmdiocb);
7301 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007302
7303 /* Trigger the release of the ndlp after logo */
7304 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007305}
7306
James Smarte59058c2008-08-24 21:49:00 -04007307/**
James Smart3621a712009-04-06 18:47:14 -04007308 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007309 * @vport: pointer to a virtual N_Port data structure.
7310 * @ndlp: pointer to a node-list data structure.
7311 *
7312 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7313 *
7314 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7315 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7316 * will be stored into the context1 field of the IOCB for the completion
7317 * callback function to the LOGO ELS command.
7318 *
7319 * Return codes
7320 * 0 - Successfully issued logo off the @vport
7321 * 1 - Failed to issue logo off the @vport
7322 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007323int
7324lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7325{
7326 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7327 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007328 IOCB_t *icmd;
7329 struct lpfc_iocbq *elsiocb;
7330 uint8_t *pcmd;
7331 uint16_t cmdsize;
7332
7333 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7334 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7335 ELS_CMD_LOGO);
7336 if (!elsiocb)
7337 return 1;
7338
7339 icmd = &elsiocb->iocb;
7340 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7341 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7342 pcmd += sizeof(uint32_t);
7343
7344 /* Fill in LOGO payload */
7345 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7346 pcmd += sizeof(uint32_t);
7347 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7348
James Smart858c9f62007-06-17 19:56:39 -05007349 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7350 "Issue LOGO npiv did:x%x flg:x%x",
7351 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7352
James Smart92d7f7b2007-06-17 19:56:38 -05007353 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7354 spin_lock_irq(shost->host_lock);
7355 ndlp->nlp_flag |= NLP_LOGO_SND;
7356 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007357 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7358 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007359 spin_lock_irq(shost->host_lock);
7360 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7361 spin_unlock_irq(shost->host_lock);
7362 lpfc_els_free_iocb(phba, elsiocb);
7363 return 1;
7364 }
7365 return 0;
7366}
7367
James Smarte59058c2008-08-24 21:49:00 -04007368/**
James Smart3621a712009-04-06 18:47:14 -04007369 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007370 * @ptr: holder for the timer function associated data.
7371 *
7372 * This routine is invoked by the fabric iocb block timer after
7373 * timeout. It posts the fabric iocb block timeout event by setting the
7374 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7375 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7376 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7377 * posted event WORKER_FABRIC_BLOCK_TMO.
7378 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007379void
7380lpfc_fabric_block_timeout(unsigned long ptr)
7381{
7382 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7383 unsigned long iflags;
7384 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007385
James Smart92d7f7b2007-06-17 19:56:38 -05007386 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7387 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7388 if (!tmo_posted)
7389 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7390 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7391
James Smart5e9d9b82008-06-14 22:52:53 -04007392 if (!tmo_posted)
7393 lpfc_worker_wake_up(phba);
7394 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007395}
7396
James Smarte59058c2008-08-24 21:49:00 -04007397/**
James Smart3621a712009-04-06 18:47:14 -04007398 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007399 * @phba: pointer to lpfc hba data structure.
7400 *
7401 * This routine issues one fabric iocb from the driver internal list to
7402 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7403 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7404 * remove one pending fabric iocb from the driver internal list and invokes
7405 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7406 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007407static void
7408lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7409{
7410 struct lpfc_iocbq *iocb;
7411 unsigned long iflags;
7412 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007413 IOCB_t *cmd;
7414
7415repeat:
7416 iocb = NULL;
7417 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007418 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007419 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7420 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7421 list);
7422 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007423 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007424 atomic_inc(&phba->fabric_iocb_count);
7425 }
7426 spin_unlock_irqrestore(&phba->hbalock, iflags);
7427 if (iocb) {
7428 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7429 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7430 iocb->iocb_flag |= LPFC_IO_FABRIC;
7431
James Smart858c9f62007-06-17 19:56:39 -05007432 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7433 "Fabric sched1: ste:x%x",
7434 iocb->vport->port_state, 0, 0);
7435
James Smart3772a992009-05-22 14:50:54 -04007436 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007437
7438 if (ret == IOCB_ERROR) {
7439 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7440 iocb->fabric_iocb_cmpl = NULL;
7441 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7442 cmd = &iocb->iocb;
7443 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7444 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7445 iocb->iocb_cmpl(phba, iocb, iocb);
7446
7447 atomic_dec(&phba->fabric_iocb_count);
7448 goto repeat;
7449 }
7450 }
7451
7452 return;
7453}
7454
James Smarte59058c2008-08-24 21:49:00 -04007455/**
James Smart3621a712009-04-06 18:47:14 -04007456 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007457 * @phba: pointer to lpfc hba data structure.
7458 *
7459 * This routine unblocks the issuing fabric iocb command. The function
7460 * will clear the fabric iocb block bit and then invoke the routine
7461 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7462 * from the driver internal fabric iocb list.
7463 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007464void
7465lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7466{
7467 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7468
7469 lpfc_resume_fabric_iocbs(phba);
7470 return;
7471}
7472
James Smarte59058c2008-08-24 21:49:00 -04007473/**
James Smart3621a712009-04-06 18:47:14 -04007474 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007475 * @phba: pointer to lpfc hba data structure.
7476 *
7477 * This routine blocks the issuing fabric iocb for a specified amount of
7478 * time (currently 100 ms). This is done by set the fabric iocb block bit
7479 * and set up a timeout timer for 100ms. When the block bit is set, no more
7480 * fabric iocb will be issued out of the HBA.
7481 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007482static void
7483lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7484{
7485 int blocked;
7486
7487 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007488 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007489 if (!blocked)
7490 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7491
7492 return;
7493}
7494
James Smarte59058c2008-08-24 21:49:00 -04007495/**
James Smart3621a712009-04-06 18:47:14 -04007496 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007497 * @phba: pointer to lpfc hba data structure.
7498 * @cmdiocb: pointer to lpfc command iocb data structure.
7499 * @rspiocb: pointer to lpfc response iocb data structure.
7500 *
7501 * This routine is the callback function that is put to the fabric iocb's
7502 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7503 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7504 * function first restores and invokes the original iocb's callback function
7505 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7506 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7507 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007508static void
7509lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7510 struct lpfc_iocbq *rspiocb)
7511{
7512 struct ls_rjt stat;
7513
7514 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7515 BUG();
7516
7517 switch (rspiocb->iocb.ulpStatus) {
7518 case IOSTAT_NPORT_RJT:
7519 case IOSTAT_FABRIC_RJT:
7520 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7521 lpfc_block_fabric_iocbs(phba);
7522 }
7523 break;
7524
7525 case IOSTAT_NPORT_BSY:
7526 case IOSTAT_FABRIC_BSY:
7527 lpfc_block_fabric_iocbs(phba);
7528 break;
7529
7530 case IOSTAT_LS_RJT:
7531 stat.un.lsRjtError =
7532 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7533 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7534 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7535 lpfc_block_fabric_iocbs(phba);
7536 break;
7537 }
7538
7539 if (atomic_read(&phba->fabric_iocb_count) == 0)
7540 BUG();
7541
7542 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7543 cmdiocb->fabric_iocb_cmpl = NULL;
7544 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7545 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7546
7547 atomic_dec(&phba->fabric_iocb_count);
7548 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007549 /* Post any pending iocbs to HBA */
7550 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007551 }
7552}
7553
James Smarte59058c2008-08-24 21:49:00 -04007554/**
James Smart3621a712009-04-06 18:47:14 -04007555 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007556 * @phba: pointer to lpfc hba data structure.
7557 * @iocb: pointer to lpfc command iocb data structure.
7558 *
7559 * This routine is used as the top-level API for issuing a fabric iocb command
7560 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7561 * function makes sure that only one fabric bound iocb will be outstanding at
7562 * any given time. As such, this function will first check to see whether there
7563 * is already an outstanding fabric iocb on the wire. If so, it will put the
7564 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7565 * issued later. Otherwise, it will issue the iocb on the wire and update the
7566 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7567 *
7568 * Note, this implementation has a potential sending out fabric IOCBs out of
7569 * order. The problem is caused by the construction of the "ready" boolen does
7570 * not include the condition that the internal fabric IOCB list is empty. As
7571 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7572 * ahead of the fabric IOCBs in the internal list.
7573 *
7574 * Return code
7575 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7576 * IOCB_ERROR - failed to issue fabric iocb
7577 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007578static int
James Smart92d7f7b2007-06-17 19:56:38 -05007579lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7580{
7581 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007582 int ready;
7583 int ret;
7584
7585 if (atomic_read(&phba->fabric_iocb_count) > 1)
7586 BUG();
7587
7588 spin_lock_irqsave(&phba->hbalock, iflags);
7589 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7590 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7591
James Smart7f5f3d02008-02-08 18:50:14 -05007592 if (ready)
7593 /* Increment fabric iocb count to hold the position */
7594 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007595 spin_unlock_irqrestore(&phba->hbalock, iflags);
7596 if (ready) {
7597 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7598 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7599 iocb->iocb_flag |= LPFC_IO_FABRIC;
7600
James Smart858c9f62007-06-17 19:56:39 -05007601 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7602 "Fabric sched2: ste:x%x",
7603 iocb->vport->port_state, 0, 0);
7604
James Smart3772a992009-05-22 14:50:54 -04007605 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007606
7607 if (ret == IOCB_ERROR) {
7608 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7609 iocb->fabric_iocb_cmpl = NULL;
7610 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7611 atomic_dec(&phba->fabric_iocb_count);
7612 }
7613 } else {
7614 spin_lock_irqsave(&phba->hbalock, iflags);
7615 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7616 spin_unlock_irqrestore(&phba->hbalock, iflags);
7617 ret = IOCB_SUCCESS;
7618 }
7619 return ret;
7620}
7621
James Smarte59058c2008-08-24 21:49:00 -04007622/**
James Smart3621a712009-04-06 18:47:14 -04007623 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007624 * @vport: pointer to a virtual N_Port data structure.
7625 *
7626 * This routine aborts all the IOCBs associated with a @vport from the
7627 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7628 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7629 * list, removes each IOCB associated with the @vport off the list, set the
7630 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7631 * associated with the IOCB.
7632 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007633static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007634{
7635 LIST_HEAD(completions);
7636 struct lpfc_hba *phba = vport->phba;
7637 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007638
7639 spin_lock_irq(&phba->hbalock);
7640 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7641 list) {
7642
7643 if (piocb->vport != vport)
7644 continue;
7645
7646 list_move_tail(&piocb->list, &completions);
7647 }
7648 spin_unlock_irq(&phba->hbalock);
7649
James Smarta257bf92009-04-06 18:48:10 -04007650 /* Cancel all the IOCBs from the completions list */
7651 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7652 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007653}
7654
James Smarte59058c2008-08-24 21:49:00 -04007655/**
James Smart3621a712009-04-06 18:47:14 -04007656 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007657 * @ndlp: pointer to a node-list data structure.
7658 *
7659 * This routine aborts all the IOCBs associated with an @ndlp from the
7660 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7661 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7662 * list, removes each IOCB associated with the @ndlp off the list, set the
7663 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7664 * associated with the IOCB.
7665 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007666void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7667{
7668 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007669 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007670 struct lpfc_iocbq *tmp_iocb, *piocb;
7671 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007672
7673 spin_lock_irq(&phba->hbalock);
7674 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7675 list) {
7676 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7677
7678 list_move_tail(&piocb->list, &completions);
7679 }
7680 }
7681 spin_unlock_irq(&phba->hbalock);
7682
James Smarta257bf92009-04-06 18:48:10 -04007683 /* Cancel all the IOCBs from the completions list */
7684 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7685 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007686}
7687
James Smarte59058c2008-08-24 21:49:00 -04007688/**
James Smart3621a712009-04-06 18:47:14 -04007689 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007690 * @phba: pointer to lpfc hba data structure.
7691 *
7692 * This routine aborts all the IOCBs currently on the driver internal
7693 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7694 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7695 * list, removes IOCBs off the list, set the status feild to
7696 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7697 * the IOCB.
7698 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007699void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7700{
7701 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007702
7703 spin_lock_irq(&phba->hbalock);
7704 list_splice_init(&phba->fabric_iocb_list, &completions);
7705 spin_unlock_irq(&phba->hbalock);
7706
James Smarta257bf92009-04-06 18:48:10 -04007707 /* Cancel all the IOCBs from the completions list */
7708 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7709 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007710}
James Smart6fb120a2009-05-22 14:52:59 -04007711
7712/**
James Smart1151e3e2011-02-16 12:39:35 -05007713 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7714 * @vport: pointer to lpfc vport data structure.
7715 *
7716 * This routine is invoked by the vport cleanup for deletions and the cleanup
7717 * for an ndlp on removal.
7718 **/
7719void
7720lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
7721{
7722 struct lpfc_hba *phba = vport->phba;
7723 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7724 unsigned long iflag = 0;
7725
7726 spin_lock_irqsave(&phba->hbalock, iflag);
7727 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7728 list_for_each_entry_safe(sglq_entry, sglq_next,
7729 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7730 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
7731 sglq_entry->ndlp = NULL;
7732 }
7733 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7734 spin_unlock_irqrestore(&phba->hbalock, iflag);
7735 return;
7736}
7737
7738/**
James Smart6fb120a2009-05-22 14:52:59 -04007739 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7740 * @phba: pointer to lpfc hba data structure.
7741 * @axri: pointer to the els xri abort wcqe structure.
7742 *
7743 * This routine is invoked by the worker thread to process a SLI4 slow-path
7744 * ELS aborted xri.
7745 **/
7746void
7747lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7748 struct sli4_wcqe_xri_aborted *axri)
7749{
7750 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05007751 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
7752
James Smart6fb120a2009-05-22 14:52:59 -04007753 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7754 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05007755 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04007756 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007757
James Smart0f65ff62010-02-26 14:14:23 -05007758 spin_lock_irqsave(&phba->hbalock, iflag);
7759 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007760 list_for_each_entry_safe(sglq_entry, sglq_next,
7761 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7762 if (sglq_entry->sli4_xritag == xri) {
7763 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05007764 ndlp = sglq_entry->ndlp;
7765 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04007766 list_add_tail(&sglq_entry->list,
7767 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007768 sglq_entry->state = SGL_FREED;
7769 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007770 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart19ca7602010-11-20 23:11:55 -05007771 lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04007772
7773 /* Check if TXQ queue needs to be serviced */
7774 if (pring->txq_cnt)
7775 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007776 return;
7777 }
7778 }
James Smart0f65ff62010-02-26 14:14:23 -05007779 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7780 sglq_entry = __lpfc_get_active_sglq(phba, xri);
7781 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7782 spin_unlock_irqrestore(&phba->hbalock, iflag);
7783 return;
7784 }
7785 sglq_entry->state = SGL_XRI_ABORTED;
7786 spin_unlock_irqrestore(&phba->hbalock, iflag);
7787 return;
James Smart6fb120a2009-05-22 14:52:59 -04007788}