blob: afbed6bc31f0599ca81ec6fea2da07ca7246727e [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 Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 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 */
dea31012005-04-17 16:05:31 -050092 ha_copy = readl(phba->HAregaddr);
dea31012005-04-17 16:05:31 -050093
94 if (!(ha_copy & HA_LATT))
95 return 0;
96
97 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040098 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
99 "0237 Pending Link Event during "
100 "Discovery: State x%x\n",
101 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500102
103 /* CLEAR_LA should re-enable link attention events and
104 * we should then imediately take a LATT event. The
105 * LATT processing should call lpfc_linkdown() which
106 * will cleanup any left over in-progress discovery
107 * events.
108 */
James Smart2e0fef82007-06-17 19:56:36 -0500109 spin_lock_irq(shost->host_lock);
110 vport->fc_flag |= FC_ABORT_DISCOVERY;
111 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500112
James Smart92d7f7b2007-06-17 19:56:38 -0500113 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500114 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500115
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500116 return 1;
dea31012005-04-17 16:05:31 -0500117}
118
James Smarte59058c2008-08-24 21:49:00 -0400119/**
James Smart3621a712009-04-06 18:47:14 -0400120 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400121 * @vport: pointer to a host virtual N_Port data structure.
122 * @expectRsp: flag indicating whether response is expected.
123 * @cmdSize: size of the ELS command.
124 * @retry: number of retries to the command IOCB when it fails.
125 * @ndlp: pointer to a node-list data structure.
126 * @did: destination identifier.
127 * @elscmd: the ELS command code.
128 *
129 * This routine is used for allocating a lpfc-IOCB data structure from
130 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
131 * passed into the routine for discovery state machine to issue an Extended
132 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
133 * and preparation routine that is used by all the discovery state machine
134 * routines and the ELS command-specific fields will be later set up by
135 * the individual discovery machine routines after calling this routine
136 * allocating and preparing a generic IOCB data structure. It fills in the
137 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
138 * payload and response payload (if expected). The reference count on the
139 * ndlp is incremented by 1 and the reference to the ndlp is put into
140 * context1 of the IOCB data structure for this IOCB to hold the ndlp
141 * reference for the command's callback function to access later.
142 *
143 * Return code
144 * Pointer to the newly allocated/prepared els iocb data structure
145 * NULL - when els iocb data structure allocation/preparation failed
146 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400147struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500148lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
149 uint16_t cmdSize, uint8_t retry,
150 struct lpfc_nodelist *ndlp, uint32_t did,
151 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500152{
James Smart2e0fef82007-06-17 19:56:36 -0500153 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400154 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500155 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
156 struct ulp_bde64 *bpl;
157 IOCB_t *icmd;
158
dea31012005-04-17 16:05:31 -0500159
James Smart2e0fef82007-06-17 19:56:36 -0500160 if (!lpfc_is_link_up(phba))
161 return NULL;
dea31012005-04-17 16:05:31 -0500162
dea31012005-04-17 16:05:31 -0500163 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400164 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500165
166 if (elsiocb == NULL)
167 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500168
James Smart0c287582009-06-10 17:22:56 -0400169 /*
170 * If this command is for fabric controller and HBA running
171 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
172 */
173 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400174 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400175 ((elscmd == ELS_CMD_FLOGI) ||
176 (elscmd == ELS_CMD_FDISC) ||
177 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500178 switch (elscmd) {
179 case ELS_CMD_FLOGI:
180 elsiocb->iocb_flag |= ((ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
181 & LPFC_FIP_ELS_ID_MASK);
182 break;
183 case ELS_CMD_FDISC:
184 elsiocb->iocb_flag |= ((ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
185 & LPFC_FIP_ELS_ID_MASK);
186 break;
187 case ELS_CMD_LOGO:
188 elsiocb->iocb_flag |= ((ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
189 & LPFC_FIP_ELS_ID_MASK);
190 break;
191 }
James Smart0c287582009-06-10 17:22:56 -0400192 else
James Smartc8685952009-11-18 15:39:16 -0500193 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400194
dea31012005-04-17 16:05:31 -0500195 icmd = &elsiocb->iocb;
196
197 /* fill in BDEs for command */
198 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400199 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
200 if (pcmd)
201 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500202 if (!pcmd || !pcmd->virt)
203 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500204
205 INIT_LIST_HEAD(&pcmd->list);
206
207 /* Allocate buffer for response payload */
208 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500209 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500210 if (prsp)
211 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
212 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500213 if (!prsp || !prsp->virt)
214 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500215 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500216 } else
dea31012005-04-17 16:05:31 -0500217 prsp = NULL;
dea31012005-04-17 16:05:31 -0500218
219 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500220 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500221 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500222 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
223 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500224 if (!pbuflist || !pbuflist->virt)
225 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500226
227 INIT_LIST_HEAD(&pbuflist->list);
228
229 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
230 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400231 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart2e0fef82007-06-17 19:56:36 -0500232 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500233 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500234 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500235 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400236 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500237 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500238 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500239 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
240 }
dea31012005-04-17 16:05:31 -0500241 icmd->ulpBdeCount = 1;
242 icmd->ulpLe = 1;
243 icmd->ulpClass = CLASS3;
244
James Smart92d7f7b2007-06-17 19:56:38 -0500245 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
246 icmd->un.elsreq64.myID = vport->fc_myDID;
247
248 /* For ELS_REQUEST64_CR, use the VPI by default */
James Smartda0436e2009-05-22 14:51:39 -0400249 icmd->ulpContext = vport->vpi + phba->vpi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500250 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500251 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
252 if (elscmd == ELS_CMD_ECHO)
253 icmd->ulpCt_l = 0; /* context = invalid RPI */
254 else
255 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500256 }
257
dea31012005-04-17 16:05:31 -0500258 bpl = (struct ulp_bde64 *) pbuflist->virt;
259 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
260 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
261 bpl->tus.f.bdeSize = cmdSize;
262 bpl->tus.f.bdeFlags = 0;
263 bpl->tus.w = le32_to_cpu(bpl->tus.w);
264
265 if (expectRsp) {
266 bpl++;
267 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
268 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
269 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400270 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500271 bpl->tus.w = le32_to_cpu(bpl->tus.w);
272 }
273
James Smartfa4066b2008-01-11 01:53:27 -0500274 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400275 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500276 if (!elsiocb->context1)
277 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400278 elsiocb->context2 = pcmd;
279 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500280 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500281 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500282 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
283
284 if (prsp) {
285 list_add(&prsp->list, &pcmd->list);
286 }
dea31012005-04-17 16:05:31 -0500287 if (expectRsp) {
288 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400289 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
290 "0116 Xmit ELS command x%x to remote "
291 "NPORT x%x I/O tag: x%x, port state: x%x\n",
292 elscmd, did, elsiocb->iotag,
293 vport->port_state);
dea31012005-04-17 16:05:31 -0500294 } else {
295 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400296 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
297 "0117 Xmit ELS response x%x to remote "
298 "NPORT x%x I/O tag: x%x, size: x%x\n",
299 elscmd, ndlp->nlp_DID, elsiocb->iotag,
300 cmdSize);
dea31012005-04-17 16:05:31 -0500301 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500302 return elsiocb;
dea31012005-04-17 16:05:31 -0500303
James Smartfa4066b2008-01-11 01:53:27 -0500304els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500305 if (expectRsp)
306 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500307 kfree(pbuflist);
308
309els_iocb_free_prsp_exit:
310 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
311 kfree(prsp);
312
313els_iocb_free_pcmb_exit:
314 kfree(pcmd);
315 lpfc_sli_release_iocbq(phba, elsiocb);
316 return NULL;
317}
dea31012005-04-17 16:05:31 -0500318
James Smarte59058c2008-08-24 21:49:00 -0400319/**
James Smart3621a712009-04-06 18:47:14 -0400320 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400321 * @vport: pointer to a host virtual N_Port data structure.
322 *
323 * This routine issues a fabric registration login for a @vport. An
324 * active ndlp node with Fabric_DID must already exist for this @vport.
325 * The routine invokes two mailbox commands to carry out fabric registration
326 * login through the HBA firmware: the first mailbox command requests the
327 * HBA to perform link configuration for the @vport; and the second mailbox
328 * command requests the HBA to perform the actual fabric registration login
329 * with the @vport.
330 *
331 * Return code
332 * 0 - successfully issued fabric registration login for @vport
333 * -ENXIO -- failed to issue fabric registration login for @vport
334 **/
James Smart3772a992009-05-22 14:50:54 -0400335int
James Smart92d7f7b2007-06-17 19:56:38 -0500336lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
337{
338 struct lpfc_hba *phba = vport->phba;
339 LPFC_MBOXQ_t *mbox;
340 struct lpfc_dmabuf *mp;
341 struct lpfc_nodelist *ndlp;
342 struct serv_parm *sp;
343 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400344 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500345
346 sp = &phba->fc_fabparam;
347 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500348 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400349 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500350 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400351 }
James Smart92d7f7b2007-06-17 19:56:38 -0500352
353 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400354 if (!mbox) {
355 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500356 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400357 }
James Smart92d7f7b2007-06-17 19:56:38 -0500358
359 vport->port_state = LPFC_FABRIC_CFG_LINK;
360 lpfc_config_link(phba, mbox);
361 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
362 mbox->vport = vport;
363
James Smart0b727fe2007-10-27 13:37:25 -0400364 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400365 if (rc == MBX_NOT_FINISHED) {
366 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500367 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400368 }
James Smart92d7f7b2007-06-17 19:56:38 -0500369
370 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400371 if (!mbox) {
372 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500373 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400374 }
James Smart3772a992009-05-22 14:50:54 -0400375 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0);
James Smart98c9ea52007-10-27 13:37:33 -0400376 if (rc) {
377 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500378 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400379 }
James Smart92d7f7b2007-06-17 19:56:38 -0500380
381 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
382 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500383 /* increment the reference count on ndlp to hold reference
384 * for the callback routine.
385 */
James Smart92d7f7b2007-06-17 19:56:38 -0500386 mbox->context2 = lpfc_nlp_get(ndlp);
387
James Smart0b727fe2007-10-27 13:37:25 -0400388 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400389 if (rc == MBX_NOT_FINISHED) {
390 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500391 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400392 }
James Smart92d7f7b2007-06-17 19:56:38 -0500393
394 return 0;
395
396fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500397 /* decrement the reference count on ndlp just incremented
398 * for the failed mbox command.
399 */
James Smart92d7f7b2007-06-17 19:56:38 -0500400 lpfc_nlp_put(ndlp);
401 mp = (struct lpfc_dmabuf *) mbox->context1;
402 lpfc_mbuf_free(phba, mp->virt, mp->phys);
403 kfree(mp);
404fail_free_mbox:
405 mempool_free(mbox, phba->mbox_mem_pool);
406
407fail:
408 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400409 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400410 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500411 return -ENXIO;
412}
413
James Smarte59058c2008-08-24 21:49:00 -0400414/**
James Smart6fb120a2009-05-22 14:52:59 -0400415 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
416 * @vport: pointer to a host virtual N_Port data structure.
417 *
418 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
419 * the @vport. This mailbox command is necessary for FCoE only.
420 *
421 * Return code
422 * 0 - successfully issued REG_VFI for @vport
423 * A failure code otherwise.
424 **/
425static int
426lpfc_issue_reg_vfi(struct lpfc_vport *vport)
427{
428 struct lpfc_hba *phba = vport->phba;
429 LPFC_MBOXQ_t *mboxq;
430 struct lpfc_nodelist *ndlp;
431 struct serv_parm *sp;
432 struct lpfc_dmabuf *dmabuf;
433 int rc = 0;
434
435 sp = &phba->fc_fabparam;
436 ndlp = lpfc_findnode_did(vport, Fabric_DID);
437 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
438 rc = -ENODEV;
439 goto fail;
440 }
441
442 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
443 if (!dmabuf) {
444 rc = -ENOMEM;
445 goto fail;
446 }
447 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
448 if (!dmabuf->virt) {
449 rc = -ENOMEM;
450 goto fail_free_dmabuf;
451 }
452 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
453 if (!mboxq) {
454 rc = -ENOMEM;
455 goto fail_free_coherent;
456 }
457 vport->port_state = LPFC_FABRIC_CFG_LINK;
458 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
459 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
460 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
461 mboxq->vport = vport;
462 mboxq->context1 = dmabuf;
463 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
464 if (rc == MBX_NOT_FINISHED) {
465 rc = -ENXIO;
466 goto fail_free_mbox;
467 }
468 return 0;
469
470fail_free_mbox:
471 mempool_free(mboxq, phba->mbox_mem_pool);
472fail_free_coherent:
473 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
474fail_free_dmabuf:
475 kfree(dmabuf);
476fail:
477 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
478 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
479 "0289 Issue Register VFI failed: Err %d\n", rc);
480 return rc;
481}
482
483/**
James Smart3621a712009-04-06 18:47:14 -0400484 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400485 * @vport: pointer to a host virtual N_Port data structure.
486 * @ndlp: pointer to a node-list data structure.
487 * @sp: pointer to service parameter data structure.
488 * @irsp: pointer to the IOCB within the lpfc response IOCB.
489 *
490 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
491 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
492 * port in a fabric topology. It properly sets up the parameters to the @ndlp
493 * from the IOCB response. It also check the newly assigned N_Port ID to the
494 * @vport against the previously assigned N_Port ID. If it is different from
495 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
496 * is invoked on all the remaining nodes with the @vport to unregister the
497 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
498 * is invoked to register login to the fabric.
499 *
500 * Return code
501 * 0 - Success (currently, always return 0)
502 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500503static int
James Smart2e0fef82007-06-17 19:56:36 -0500504lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
505 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500506{
James Smart2e0fef82007-06-17 19:56:36 -0500507 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
508 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500509 struct lpfc_nodelist *np;
510 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500511
James Smart2e0fef82007-06-17 19:56:36 -0500512 spin_lock_irq(shost->host_lock);
513 vport->fc_flag |= FC_FABRIC;
514 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500515
516 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
517 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
518 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
519
520 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
521
522 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500523 spin_lock_irq(shost->host_lock);
524 vport->fc_flag |= FC_PUBLIC_LOOP;
525 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500526 } else {
527 /*
528 * If we are a N-port connected to a Fabric, fixup sparam's so
529 * logins to devices on remote loops work.
530 */
James Smart2e0fef82007-06-17 19:56:36 -0500531 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500532 }
533
James Smart2e0fef82007-06-17 19:56:36 -0500534 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500535 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500536 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500537 ndlp->nlp_class_sup = 0;
538 if (sp->cls1.classValid)
539 ndlp->nlp_class_sup |= FC_COS_CLASS1;
540 if (sp->cls2.classValid)
541 ndlp->nlp_class_sup |= FC_COS_CLASS2;
542 if (sp->cls3.classValid)
543 ndlp->nlp_class_sup |= FC_COS_CLASS3;
544 if (sp->cls4.classValid)
545 ndlp->nlp_class_sup |= FC_COS_CLASS4;
546 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
547 sp->cmn.bbRcvSizeLsb;
548 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
549
James Smart92d7f7b2007-06-17 19:56:38 -0500550 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
551 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400552 lpfc_printf_vlog(vport, KERN_WARNING,
553 LOG_ELS | LOG_VPORT,
554 "1816 FLOGI NPIV supported, "
555 "response data 0x%x\n",
556 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500557 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500558 } else {
559 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400560 to call reg_vnpid atleast for the physcial host */
561 lpfc_printf_vlog(vport, KERN_WARNING,
562 LOG_ELS | LOG_VPORT,
563 "1817 Fabric does not support NPIV "
564 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500565 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
566 }
567 }
568
569 if ((vport->fc_prevDID != vport->fc_myDID) &&
570 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
571
572 /* If our NportID changed, we need to ensure all
573 * remaining NPORTs get unreg_login'ed.
574 */
575 list_for_each_entry_safe(np, next_np,
576 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400577 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500578 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500579 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
580 !(np->nlp_flag & NLP_NPR_ADISC))
581 continue;
582 spin_lock_irq(shost->host_lock);
583 np->nlp_flag &= ~NLP_NPR_ADISC;
584 spin_unlock_irq(shost->host_lock);
585 lpfc_unreg_rpi(vport, np);
586 }
James Smart78730cf2010-04-06 15:06:30 -0400587 lpfc_cleanup_pending_mbox(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500588 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
589 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500590 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500591 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500592 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500593 }
James Smartecfd03c2010-02-12 14:41:27 -0500594 /*
595 * If VPI is unreged, driver need to do INIT_VPI
596 * before re-registering
597 */
598 if (phba->sli_rev == LPFC_SLI_REV4) {
599 spin_lock_irq(shost->host_lock);
600 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
601 spin_unlock_irq(shost->host_lock);
602 }
James Smart92d7f7b2007-06-17 19:56:38 -0500603 }
604
James Smart6fb120a2009-05-22 14:52:59 -0400605 if (phba->sli_rev < LPFC_SLI_REV4) {
606 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
607 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
608 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
609 lpfc_register_new_vport(phba, vport, ndlp);
610 else
611 lpfc_issue_fabric_reglogin(vport);
612 } else {
613 ndlp->nlp_type |= NLP_FABRIC;
614 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500615 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
616 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400617 lpfc_start_fdiscs(phba);
618 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500619 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500620 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500621 else
James Smart6fb120a2009-05-22 14:52:59 -0400622 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500623 }
dea31012005-04-17 16:05:31 -0500624 return 0;
dea31012005-04-17 16:05:31 -0500625}
James Smarte59058c2008-08-24 21:49:00 -0400626/**
James Smart3621a712009-04-06 18:47:14 -0400627 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400628 * @vport: pointer to a host virtual N_Port data structure.
629 * @ndlp: pointer to a node-list data structure.
630 * @sp: pointer to service parameter data structure.
631 *
632 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
633 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
634 * in a point-to-point topology. First, the @vport's N_Port Name is compared
635 * with the received N_Port Name: if the @vport's N_Port Name is greater than
636 * the received N_Port Name lexicographically, this node shall assign local
637 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
638 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
639 * this node shall just wait for the remote node to issue PLOGI and assign
640 * N_Port IDs.
641 *
642 * Return code
643 * 0 - Success
644 * -ENXIO - Fail
645 **/
dea31012005-04-17 16:05:31 -0500646static int
James Smart2e0fef82007-06-17 19:56:36 -0500647lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
648 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500649{
James Smart2e0fef82007-06-17 19:56:36 -0500650 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
651 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500652 LPFC_MBOXQ_t *mbox;
653 int rc;
654
James Smart2e0fef82007-06-17 19:56:36 -0500655 spin_lock_irq(shost->host_lock);
656 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
657 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500658
659 phba->fc_edtov = FF_DEF_EDTOV;
660 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500661 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500662 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500663 if (rc >= 0) {
664 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500665 spin_lock_irq(shost->host_lock);
666 vport->fc_flag |= FC_PT2PT_PLOGI;
667 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500668
669 /*
670 * N_Port ID cannot be 0, set our to LocalID the other
671 * side will be RemoteID.
672 */
673
674 /* not equal */
675 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500676 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500677
678 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
679 if (!mbox)
680 goto fail;
681
682 lpfc_config_link(phba, mbox);
683
684 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500685 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400686 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500687 if (rc == MBX_NOT_FINISHED) {
688 mempool_free(mbox, phba->mbox_mem_pool);
689 goto fail;
690 }
James Smarte47c9092008-02-08 18:49:26 -0500691 /* Decrement ndlp reference count indicating that ndlp can be
692 * safely released when other references to it are done.
693 */
James Smart329f9bc2007-04-25 09:53:01 -0400694 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500695
James Smart2e0fef82007-06-17 19:56:36 -0500696 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500697 if (!ndlp) {
698 /*
699 * Cannot find existing Fabric ndlp, so allocate a
700 * new one
701 */
702 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
703 if (!ndlp)
704 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500705 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500706 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
707 ndlp = lpfc_enable_node(vport, ndlp,
708 NLP_STE_UNUSED_NODE);
709 if(!ndlp)
710 goto fail;
dea31012005-04-17 16:05:31 -0500711 }
712
713 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500714 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500715 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500716 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500717 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500718 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
719 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500720 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500721 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500722 } else
723 /* This side will wait for the PLOGI, decrement ndlp reference
724 * count indicating that ndlp can be released when other
725 * references to it are done.
726 */
James Smart329f9bc2007-04-25 09:53:01 -0400727 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500728
James Smart09372822008-01-11 01:52:54 -0500729 /* If we are pt2pt with another NPort, force NPIV off! */
730 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
731
James Smart2e0fef82007-06-17 19:56:36 -0500732 spin_lock_irq(shost->host_lock);
733 vport->fc_flag |= FC_PT2PT;
734 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500735
736 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500737 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500738 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500739fail:
dea31012005-04-17 16:05:31 -0500740 return -ENXIO;
741}
742
James Smarte59058c2008-08-24 21:49:00 -0400743/**
James Smart3621a712009-04-06 18:47:14 -0400744 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400745 * @phba: pointer to lpfc hba data structure.
746 * @cmdiocb: pointer to lpfc command iocb data structure.
747 * @rspiocb: pointer to lpfc response iocb data structure.
748 *
749 * This routine is the top-level completion callback function for issuing
750 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
751 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
752 * retry has been made (either immediately or delayed with lpfc_els_retry()
753 * returning 1), the command IOCB will be released and function returned.
754 * If the retry attempt has been given up (possibly reach the maximum
755 * number of retries), one additional decrement of ndlp reference shall be
756 * invoked before going out after releasing the command IOCB. This will
757 * actually release the remote node (Note, lpfc_els_free_iocb() will also
758 * invoke one decrement of ndlp reference count). If no error reported in
759 * the IOCB status, the command Port ID field is used to determine whether
760 * this is a point-to-point topology or a fabric topology: if the Port ID
761 * field is assigned, it is a fabric topology; otherwise, it is a
762 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
763 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
764 * specific topology completion conditions.
765 **/
dea31012005-04-17 16:05:31 -0500766static void
James Smart329f9bc2007-04-25 09:53:01 -0400767lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
768 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500769{
James Smart2e0fef82007-06-17 19:56:36 -0500770 struct lpfc_vport *vport = cmdiocb->vport;
771 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500772 IOCB_t *irsp = &rspiocb->iocb;
773 struct lpfc_nodelist *ndlp = cmdiocb->context1;
774 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
775 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500776 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500777 int rc;
778
779 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500780 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500781 /* One additional decrement on node reference count to
782 * trigger the release of the node
783 */
James Smart329f9bc2007-04-25 09:53:01 -0400784 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500785 goto out;
786 }
787
James Smart858c9f62007-06-17 19:56:39 -0500788 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
789 "FLOGI cmpl: status:x%x/x%x state:x%x",
790 irsp->ulpStatus, irsp->un.ulpWord[4],
791 vport->port_state);
792
dea31012005-04-17 16:05:31 -0500793 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500794 /*
795 * In case of FIP mode, perform round robin FCF failover
796 * due to new FCF discovery
797 */
798 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smartdbb6b3a2010-06-08 18:31:37 -0400799 (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
800 (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) &&
801 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500802 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
803 "2611 FLOGI failed on registered "
804 "FCF record fcf_index:%d, trying "
805 "to perform round robin failover\n",
806 phba->fcf.current_rec.fcf_indx);
807 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
808 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
809 /*
810 * Exhausted the eligible FCF record list,
811 * fail through to retry FLOGI on current
812 * FCF record.
813 */
814 lpfc_printf_log(phba, KERN_WARNING,
815 LOG_FIP | LOG_ELS,
James Smart3804dc82010-07-14 15:31:37 -0400816 "2760 Completed one round "
817 "of FLOGI FCF round robin "
818 "failover list, retry FLOGI "
819 "on currently registered "
820 "FCF index:%d\n",
James Smart0c9ab6f2010-02-26 14:15:57 -0500821 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500822 } else {
James Smart3804dc82010-07-14 15:31:37 -0400823 lpfc_printf_log(phba, KERN_INFO,
824 LOG_FIP | LOG_ELS,
825 "2794 FLOGI FCF round robin "
826 "failover to FCF index x%x\n",
827 fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -0500828 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba,
829 fcf_index);
James Smart3804dc82010-07-14 15:31:37 -0400830 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -0500831 lpfc_printf_log(phba, KERN_WARNING,
832 LOG_FIP | LOG_ELS,
833 "2761 FLOGI round "
834 "robin FCF failover "
835 "read FCF failed "
836 "rc:x%x, fcf_index:"
837 "%d\n", rc,
838 phba->fcf.current_rec.fcf_indx);
James Smart3804dc82010-07-14 15:31:37 -0400839 else
James Smart0c9ab6f2010-02-26 14:15:57 -0500840 goto out;
841 }
842 }
843
dea31012005-04-17 16:05:31 -0500844 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500845 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500846 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500847
dea31012005-04-17 16:05:31 -0500848 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500849 spin_lock_irq(shost->host_lock);
850 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
851 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500852
James Smart329f9bc2007-04-25 09:53:01 -0400853 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500854 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
855 * alpa map would take too long otherwise.
856 */
857 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400858 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500859 }
860
861 /* FLOGI failure */
James Smarte40a02c2010-02-26 14:13:54 -0500862 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
863 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400864 irsp->ulpStatus, irsp->un.ulpWord[4],
865 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500866 goto flogifail;
867 }
James Smart695a8142010-01-26 23:08:03 -0500868 spin_lock_irq(shost->host_lock);
869 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400870 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500871 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500872
873 /*
874 * The FLogI succeeded. Sync the data for the CPU before
875 * accessing it.
876 */
877 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
878
879 sp = prsp->virt + sizeof(uint32_t);
880
881 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400882 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200883 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400884 "Data: x%x x%x x%x x%x\n",
885 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
886 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500887
James Smart2e0fef82007-06-17 19:56:36 -0500888 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500889 /*
890 * If Common Service Parameters indicate Nport
891 * we are point to point, if Fport we are Fabric.
892 */
893 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500894 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400895 else if (!(phba->hba_flag & HBA_FCOE_SUPPORT))
James Smart2e0fef82007-06-17 19:56:36 -0500896 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400897 else {
898 lpfc_printf_vlog(vport, KERN_ERR,
899 LOG_FIP | LOG_ELS,
900 "2831 FLOGI response with cleared Fabric "
901 "bit fcf_index 0x%x "
902 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
903 "Fabric Name "
904 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
905 phba->fcf.current_rec.fcf_indx,
906 phba->fcf.current_rec.switch_name[0],
907 phba->fcf.current_rec.switch_name[1],
908 phba->fcf.current_rec.switch_name[2],
909 phba->fcf.current_rec.switch_name[3],
910 phba->fcf.current_rec.switch_name[4],
911 phba->fcf.current_rec.switch_name[5],
912 phba->fcf.current_rec.switch_name[6],
913 phba->fcf.current_rec.switch_name[7],
914 phba->fcf.current_rec.fabric_name[0],
915 phba->fcf.current_rec.fabric_name[1],
916 phba->fcf.current_rec.fabric_name[2],
917 phba->fcf.current_rec.fabric_name[3],
918 phba->fcf.current_rec.fabric_name[4],
919 phba->fcf.current_rec.fabric_name[5],
920 phba->fcf.current_rec.fabric_name[6],
921 phba->fcf.current_rec.fabric_name[7]);
922 lpfc_nlp_put(ndlp);
923 spin_lock_irq(&phba->hbalock);
924 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
925 spin_unlock_irq(&phba->hbalock);
926 goto out;
927 }
James Smart0c9ab6f2010-02-26 14:15:57 -0500928 if (!rc) {
929 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400930 if (phba->hba_flag & HBA_FIP_SUPPORT)
931 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
932 LOG_ELS,
933 "2769 FLOGI successful on FCF "
934 "record: current_fcf_index:"
935 "x%x, terminate FCF round "
936 "robin failover process\n",
937 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500938 spin_lock_irq(&phba->hbalock);
939 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
940 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500941 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500942 }
dea31012005-04-17 16:05:31 -0500943 }
944
945flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400946 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500947
James Smart858c9f62007-06-17 19:56:39 -0500948 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500949 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500950 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500951
952 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500953 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400954 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
955 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
956 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
957 (phba->link_state != LPFC_CLEAR_LA)) {
958 /* If FLOGI failed enable link interrupt. */
959 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500960 }
dea31012005-04-17 16:05:31 -0500961out:
962 lpfc_els_free_iocb(phba, cmdiocb);
963}
964
James Smarte59058c2008-08-24 21:49:00 -0400965/**
James Smart3621a712009-04-06 18:47:14 -0400966 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400967 * @vport: pointer to a host virtual N_Port data structure.
968 * @ndlp: pointer to a node-list data structure.
969 * @retry: number of retries to the command IOCB.
970 *
971 * This routine issues a Fabric Login (FLOGI) Request ELS command
972 * for a @vport. The initiator service parameters are put into the payload
973 * of the FLOGI Request IOCB and the top-level callback function pointer
974 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
975 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
976 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
977 *
978 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
979 * will be incremented by 1 for holding the ndlp and the reference to ndlp
980 * will be stored into the context1 field of the IOCB for the completion
981 * callback function to the FLOGI ELS command.
982 *
983 * Return code
984 * 0 - successfully issued flogi iocb for @vport
985 * 1 - failed to issue flogi iocb for @vport
986 **/
dea31012005-04-17 16:05:31 -0500987static int
James Smart2e0fef82007-06-17 19:56:36 -0500988lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500989 uint8_t retry)
990{
James Smart2e0fef82007-06-17 19:56:36 -0500991 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500992 struct serv_parm *sp;
993 IOCB_t *icmd;
994 struct lpfc_iocbq *elsiocb;
995 struct lpfc_sli_ring *pring;
996 uint8_t *pcmd;
997 uint16_t cmdsize;
998 uint32_t tmo;
999 int rc;
1000
1001 pring = &phba->sli.ring[LPFC_ELS_RING];
1002
James Smart92d7f7b2007-06-17 19:56:38 -05001003 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001004 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1005 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001006
James Smart488d1462006-03-07 15:02:37 -05001007 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001008 return 1;
dea31012005-04-17 16:05:31 -05001009
1010 icmd = &elsiocb->iocb;
1011 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1012
1013 /* For FLOGI request, remainder of payload is service parameters */
1014 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001015 pcmd += sizeof(uint32_t);
1016 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001017 sp = (struct serv_parm *) pcmd;
1018
1019 /* Setup CSPs accordingly for Fabric */
1020 sp->cmn.e_d_tov = 0;
1021 sp->cmn.w2.r_a_tov = 0;
1022 sp->cls1.classValid = 0;
1023 sp->cls2.seqDelivery = 1;
1024 sp->cls3.seqDelivery = 1;
1025 if (sp->cmn.fcphLow < FC_PH3)
1026 sp->cmn.fcphLow = FC_PH3;
1027 if (sp->cmn.fcphHigh < FC_PH3)
1028 sp->cmn.fcphHigh = FC_PH3;
1029
James Smart6fb120a2009-05-22 14:52:59 -04001030 if (phba->sli_rev == LPFC_SLI_REV4) {
1031 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1032 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1033 /* FLOGI needs to be 3 for WQE FCFI */
1034 /* Set the fcfi to the fcfi we registered with */
1035 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1036 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001037 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001038 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1039 icmd->ulpCt_h = 1;
1040 icmd->ulpCt_l = 0;
1041 }
1042
James Smart858c9f62007-06-17 19:56:39 -05001043 if (phba->fc_topology != TOPOLOGY_LOOP) {
1044 icmd->un.elsreq64.myID = 0;
1045 icmd->un.elsreq64.fl = 1;
1046 }
1047
dea31012005-04-17 16:05:31 -05001048 tmo = phba->fc_ratov;
1049 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001050 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001051 phba->fc_ratov = tmo;
1052
1053 phba->fc_stat.elsXmitFLOGI++;
1054 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001055
1056 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1057 "Issue FLOGI: opt:x%x",
1058 phba->sli3_options, 0, 0);
1059
James Smart92d7f7b2007-06-17 19:56:38 -05001060 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001061 if (rc == IOCB_ERROR) {
1062 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001063 return 1;
dea31012005-04-17 16:05:31 -05001064 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001065 return 0;
dea31012005-04-17 16:05:31 -05001066}
1067
James Smarte59058c2008-08-24 21:49:00 -04001068/**
James Smart3621a712009-04-06 18:47:14 -04001069 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001070 * @phba: pointer to lpfc hba data structure.
1071 *
1072 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1073 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1074 * list and issues an abort IOCB commond on each outstanding IOCB that
1075 * contains a active Fabric_DID ndlp. Note that this function is to issue
1076 * the abort IOCB command on all the outstanding IOCBs, thus when this
1077 * function returns, it does not guarantee all the IOCBs are actually aborted.
1078 *
1079 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001080 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001081 **/
dea31012005-04-17 16:05:31 -05001082int
James Smart2e0fef82007-06-17 19:56:36 -05001083lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001084{
1085 struct lpfc_sli_ring *pring;
1086 struct lpfc_iocbq *iocb, *next_iocb;
1087 struct lpfc_nodelist *ndlp;
1088 IOCB_t *icmd;
1089
1090 /* Abort outstanding I/O on NPort <nlp_DID> */
1091 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001092 "0201 Abort outstanding I/O on NPort x%x\n",
1093 Fabric_DID);
dea31012005-04-17 16:05:31 -05001094
1095 pring = &phba->sli.ring[LPFC_ELS_RING];
1096
1097 /*
1098 * Check the txcmplq for an iocb that matches the nport the driver is
1099 * searching for.
1100 */
James Smart2e0fef82007-06-17 19:56:36 -05001101 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001102 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1103 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001104 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1105 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001106 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001107 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1108 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001109 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001110 }
1111 }
James Smart2e0fef82007-06-17 19:56:36 -05001112 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001113
1114 return 0;
1115}
1116
James Smarte59058c2008-08-24 21:49:00 -04001117/**
James Smart3621a712009-04-06 18:47:14 -04001118 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001119 * @vport: pointer to a host virtual N_Port data structure.
1120 *
1121 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1122 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1123 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1124 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1125 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1126 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1127 * @vport.
1128 *
1129 * Return code
1130 * 0 - failed to issue initial flogi for @vport
1131 * 1 - successfully issued initial flogi for @vport
1132 **/
dea31012005-04-17 16:05:31 -05001133int
James Smart2e0fef82007-06-17 19:56:36 -05001134lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001135{
James Smart2e0fef82007-06-17 19:56:36 -05001136 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001137 struct lpfc_nodelist *ndlp;
1138
James Smart98c9ea52007-10-27 13:37:33 -04001139 vport->port_state = LPFC_FLOGI;
1140 lpfc_set_disctmo(vport);
1141
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001142 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001143 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001144 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001145 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001146 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1147 if (!ndlp)
1148 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001149 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001150 /* Set the node type */
1151 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001152 /* Put ndlp onto node list */
1153 lpfc_enqueue_node(vport, ndlp);
1154 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1155 /* re-setup ndlp without removing from node list */
1156 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1157 if (!ndlp)
1158 return 0;
dea31012005-04-17 16:05:31 -05001159 }
James Smart87af33f2007-10-27 13:37:43 -04001160
James Smarte47c9092008-02-08 18:49:26 -05001161 if (lpfc_issue_els_flogi(vport, ndlp, 0))
James Smartfa4066b2008-01-11 01:53:27 -05001162 /* This decrement of reference count to node shall kick off
1163 * the release of the node.
1164 */
James Smart329f9bc2007-04-25 09:53:01 -04001165 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001166
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001167 return 1;
dea31012005-04-17 16:05:31 -05001168}
1169
James Smarte59058c2008-08-24 21:49:00 -04001170/**
James Smart3621a712009-04-06 18:47:14 -04001171 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001172 * @vport: pointer to a host virtual N_Port data structure.
1173 *
1174 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1175 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1176 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1177 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1178 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1179 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1180 * @vport.
1181 *
1182 * Return code
1183 * 0 - failed to issue initial fdisc for @vport
1184 * 1 - successfully issued initial fdisc for @vport
1185 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001186int
1187lpfc_initial_fdisc(struct lpfc_vport *vport)
1188{
1189 struct lpfc_hba *phba = vport->phba;
1190 struct lpfc_nodelist *ndlp;
1191
1192 /* First look for the Fabric ndlp */
1193 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1194 if (!ndlp) {
1195 /* Cannot find existing Fabric ndlp, so allocate a new one */
1196 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1197 if (!ndlp)
1198 return 0;
1199 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001200 /* Put ndlp onto node list */
1201 lpfc_enqueue_node(vport, ndlp);
1202 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1203 /* re-setup ndlp without removing from node list */
1204 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1205 if (!ndlp)
1206 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001207 }
James Smarte47c9092008-02-08 18:49:26 -05001208
James Smart92d7f7b2007-06-17 19:56:38 -05001209 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001210 /* decrement node reference count to trigger the release of
1211 * the node.
1212 */
James Smart92d7f7b2007-06-17 19:56:38 -05001213 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001214 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001215 }
1216 return 1;
1217}
James Smart87af33f2007-10-27 13:37:43 -04001218
James Smarte59058c2008-08-24 21:49:00 -04001219/**
James Smart3621a712009-04-06 18:47:14 -04001220 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001221 * @vport: pointer to a host virtual N_Port data structure.
1222 *
1223 * This routine checks whether there are more remaining Port Logins
1224 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1225 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1226 * to issue ELS PLOGIs up to the configured discover threads with the
1227 * @vport (@vport->cfg_discovery_threads). The function also decrement
1228 * the @vport's num_disc_node by 1 if it is not already 0.
1229 **/
James Smart87af33f2007-10-27 13:37:43 -04001230void
James Smart2e0fef82007-06-17 19:56:36 -05001231lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001232{
1233 int sentplogi;
1234
James Smart2e0fef82007-06-17 19:56:36 -05001235 if (vport->num_disc_nodes)
1236 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001237
1238 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001239 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1240 "0232 Continue discovery with %d PLOGIs to go "
1241 "Data: x%x x%x x%x\n",
1242 vport->num_disc_nodes, vport->fc_plogi_cnt,
1243 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001244 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001245 if (vport->fc_flag & FC_NLP_MORE)
1246 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1247 sentplogi = lpfc_els_disc_plogi(vport);
1248
dea31012005-04-17 16:05:31 -05001249 return;
1250}
1251
James Smarte59058c2008-08-24 21:49:00 -04001252/**
James Smart3621a712009-04-06 18:47:14 -04001253 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001254 * @phba: pointer to lpfc hba data structure.
1255 * @prsp: pointer to response IOCB payload.
1256 * @ndlp: pointer to a node-list data structure.
1257 *
1258 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1259 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1260 * The following cases are considered N_Port confirmed:
1261 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1262 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1263 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1264 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1265 * 1) if there is a node on vport list other than the @ndlp with the same
1266 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1267 * on that node to release the RPI associated with the node; 2) if there is
1268 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1269 * into, a new node shall be allocated (or activated). In either case, the
1270 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1271 * be released and the new_ndlp shall be put on to the vport node list and
1272 * its pointer returned as the confirmed node.
1273 *
1274 * Note that before the @ndlp got "released", the keepDID from not-matching
1275 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1276 * of the @ndlp. This is because the release of @ndlp is actually to put it
1277 * into an inactive state on the vport node list and the vport node list
1278 * management algorithm does not allow two node with a same DID.
1279 *
1280 * Return code
1281 * pointer to the PLOGI N_Port @ndlp
1282 **/
James Smart488d1462006-03-07 15:02:37 -05001283static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001284lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001285 struct lpfc_nodelist *ndlp)
1286{
James Smart2e0fef82007-06-17 19:56:36 -05001287 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001288 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001289 struct lpfc_rport_data *rdata;
1290 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001291 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001292 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001293 uint32_t rc, keepDID = 0;
James Smart488d1462006-03-07 15:02:37 -05001294
James Smart2fb9bd82006-12-02 13:33:57 -05001295 /* Fabric nodes can have the same WWPN so we don't bother searching
1296 * by WWPN. Just return the ndlp that was given to us.
1297 */
1298 if (ndlp->nlp_type & NLP_FABRIC)
1299 return ndlp;
1300
James Smart92d7f7b2007-06-17 19:56:38 -05001301 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001302 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001303
James Smart685f0bf2007-04-25 09:53:08 -04001304 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001305 * we have for that ndlp. If not, we have some work to do.
1306 */
James Smart2e0fef82007-06-17 19:56:36 -05001307 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001308
James Smarte47c9092008-02-08 18:49:26 -05001309 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001310 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001311
1312 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001313 rc = memcmp(&ndlp->nlp_portname, name,
1314 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001315 if (!rc)
1316 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001317 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1318 if (!new_ndlp)
1319 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001320 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001321 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001322 rc = memcmp(&ndlp->nlp_portname, name,
1323 sizeof(struct lpfc_name));
1324 if (!rc)
1325 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001326 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1327 NLP_STE_UNUSED_NODE);
1328 if (!new_ndlp)
1329 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001330 keepDID = new_ndlp->nlp_DID;
1331 } else
1332 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001333
James Smart2e0fef82007-06-17 19:56:36 -05001334 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001335 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001336 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001337
1338 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1339 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1340 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1341
James Smarte47c9092008-02-08 18:49:26 -05001342 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001343 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001344
James Smart2e0fef82007-06-17 19:56:36 -05001345 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001346 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1347 /* The new_ndlp is replacing ndlp totally, so we need
1348 * to put ndlp on UNUSED list and try to free it.
1349 */
James Smart0ff10d42008-01-11 01:52:36 -05001350
1351 /* Fix up the rport accordingly */
1352 rport = ndlp->rport;
1353 if (rport) {
1354 rdata = rport->dd_data;
1355 if (rdata->pnode == ndlp) {
1356 lpfc_nlp_put(ndlp);
1357 ndlp->rport = NULL;
1358 rdata->pnode = lpfc_nlp_get(new_ndlp);
1359 new_ndlp->rport = rport;
1360 }
1361 new_ndlp->nlp_type = ndlp->nlp_type;
1362 }
James Smart58da1ff2008-04-07 10:15:56 -04001363 /* We shall actually free the ndlp with both nlp_DID and
1364 * nlp_portname fields equals 0 to avoid any ndlp on the
1365 * nodelist never to be used.
1366 */
1367 if (ndlp->nlp_DID == 0) {
1368 spin_lock_irq(&phba->ndlp_lock);
1369 NLP_SET_FREE_REQ(ndlp);
1370 spin_unlock_irq(&phba->ndlp_lock);
1371 }
James Smart0ff10d42008-01-11 01:52:36 -05001372
James Smart58da1ff2008-04-07 10:15:56 -04001373 /* Two ndlps cannot have the same did on the nodelist */
1374 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001375 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001376 }
James Smart92795652006-07-06 15:50:02 -04001377 else {
James Smart2e0fef82007-06-17 19:56:36 -05001378 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001379 /* Two ndlps cannot have the same did */
1380 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001381 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -04001382 }
James Smart488d1462006-03-07 15:02:37 -05001383 return new_ndlp;
1384}
1385
James Smarte59058c2008-08-24 21:49:00 -04001386/**
James Smart3621a712009-04-06 18:47:14 -04001387 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001388 * @vport: pointer to a host virtual N_Port data structure.
1389 *
1390 * This routine checks whether more Registration State Change
1391 * Notifications (RSCNs) came in while the discovery state machine was in
1392 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1393 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1394 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1395 * handling the RSCNs.
1396 **/
James Smart87af33f2007-10-27 13:37:43 -04001397void
1398lpfc_end_rscn(struct lpfc_vport *vport)
1399{
1400 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1401
1402 if (vport->fc_flag & FC_RSCN_MODE) {
1403 /*
1404 * Check to see if more RSCNs came in while we were
1405 * processing this one.
1406 */
1407 if (vport->fc_rscn_id_cnt ||
1408 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1409 lpfc_els_handle_rscn(vport);
1410 else {
1411 spin_lock_irq(shost->host_lock);
1412 vport->fc_flag &= ~FC_RSCN_MODE;
1413 spin_unlock_irq(shost->host_lock);
1414 }
1415 }
1416}
1417
James Smarte59058c2008-08-24 21:49:00 -04001418/**
James Smart3621a712009-04-06 18:47:14 -04001419 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001420 * @phba: pointer to lpfc hba data structure.
1421 * @cmdiocb: pointer to lpfc command iocb data structure.
1422 * @rspiocb: pointer to lpfc response iocb data structure.
1423 *
1424 * This routine is the completion callback function for issuing the Port
1425 * Login (PLOGI) command. For PLOGI completion, there must be an active
1426 * ndlp on the vport node list that matches the remote node ID from the
1427 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1428 * ignored and command IOCB released. The PLOGI response IOCB status is
1429 * checked for error conditons. If there is error status reported, PLOGI
1430 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1431 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1432 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1433 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1434 * there are additional N_Port nodes with the vport that need to perform
1435 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1436 * PLOGIs.
1437 **/
dea31012005-04-17 16:05:31 -05001438static void
James Smart2e0fef82007-06-17 19:56:36 -05001439lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1440 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001441{
James Smart2e0fef82007-06-17 19:56:36 -05001442 struct lpfc_vport *vport = cmdiocb->vport;
1443 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001444 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001445 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001446 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001447 int disc, rc, did, type;
1448
dea31012005-04-17 16:05:31 -05001449 /* we pass cmdiocb to state machine which needs rspiocb as well */
1450 cmdiocb->context_un.rsp_iocb = rspiocb;
1451
1452 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001453 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1454 "PLOGI cmpl: status:x%x/x%x did:x%x",
1455 irsp->ulpStatus, irsp->un.ulpWord[4],
1456 irsp->un.elsreq64.remoteID);
1457
James Smart2e0fef82007-06-17 19:56:36 -05001458 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001459 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001460 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1461 "0136 PLOGI completes to NPort x%x "
1462 "with no ndlp. Data: x%x x%x x%x\n",
1463 irsp->un.elsreq64.remoteID,
1464 irsp->ulpStatus, irsp->un.ulpWord[4],
1465 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001466 goto out;
James Smarted957682007-06-17 19:56:37 -05001467 }
dea31012005-04-17 16:05:31 -05001468
1469 /* Since ndlp can be freed in the disc state machine, note if this node
1470 * is being used during discovery.
1471 */
James Smart2e0fef82007-06-17 19:56:36 -05001472 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001473 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001474 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001475 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001476 rc = 0;
1477
1478 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001479 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1480 "0102 PLOGI completes to NPort x%x "
1481 "Data: x%x x%x x%x x%x x%x\n",
1482 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1483 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001484 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001485 if (lpfc_els_chk_latt(vport)) {
1486 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001487 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001488 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001489 goto out;
1490 }
1491
1492 /* ndlp could be freed in DSM, save these values now */
1493 type = ndlp->nlp_type;
1494 did = ndlp->nlp_DID;
1495
1496 if (irsp->ulpStatus) {
1497 /* Check for retry */
1498 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1499 /* ELS command is being retried */
1500 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001501 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001502 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001503 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001504 }
1505 goto out;
1506 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001507 /* PLOGI failed Don't print the vport to vport rjts */
1508 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1509 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1510 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1511 (phba)->pport->cfg_log_verbose & LOG_ELS)
1512 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001513 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1514 ndlp->nlp_DID, irsp->ulpStatus,
1515 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001516 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001517 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001518 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001519 else
James Smart2e0fef82007-06-17 19:56:36 -05001520 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001521 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001522 } else {
1523 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001524 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001525 cmdiocb->context2)->list.next,
1526 struct lpfc_dmabuf, list);
1527 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001528 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001529 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001530 }
1531
James Smart2e0fef82007-06-17 19:56:36 -05001532 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001533 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001534 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001535
James Smart2e0fef82007-06-17 19:56:36 -05001536 if (vport->num_disc_nodes == 0) {
1537 spin_lock_irq(shost->host_lock);
1538 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1539 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001540
James Smart2e0fef82007-06-17 19:56:36 -05001541 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001542 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001543 }
1544 }
1545
1546out:
1547 lpfc_els_free_iocb(phba, cmdiocb);
1548 return;
1549}
1550
James Smarte59058c2008-08-24 21:49:00 -04001551/**
James Smart3621a712009-04-06 18:47:14 -04001552 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001553 * @vport: pointer to a host virtual N_Port data structure.
1554 * @did: destination port identifier.
1555 * @retry: number of retries to the command IOCB.
1556 *
1557 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1558 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1559 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1560 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1561 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1562 *
1563 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1564 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1565 * will be stored into the context1 field of the IOCB for the completion
1566 * callback function to the PLOGI ELS command.
1567 *
1568 * Return code
1569 * 0 - Successfully issued a plogi for @vport
1570 * 1 - failed to issue a plogi for @vport
1571 **/
dea31012005-04-17 16:05:31 -05001572int
James Smart2e0fef82007-06-17 19:56:36 -05001573lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001574{
James Smart2e0fef82007-06-17 19:56:36 -05001575 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001576 struct serv_parm *sp;
1577 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001578 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001579 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001580 struct lpfc_sli *psli;
1581 uint8_t *pcmd;
1582 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001583 int ret;
dea31012005-04-17 16:05:31 -05001584
1585 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001586
James Smart98c9ea52007-10-27 13:37:33 -04001587 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001588 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1589 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001590
James Smarte47c9092008-02-08 18:49:26 -05001591 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001592 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001593 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001594 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001595 if (!elsiocb)
1596 return 1;
dea31012005-04-17 16:05:31 -05001597
1598 icmd = &elsiocb->iocb;
1599 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1600
1601 /* For PLOGI request, remainder of payload is service parameters */
1602 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001603 pcmd += sizeof(uint32_t);
1604 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001605 sp = (struct serv_parm *) pcmd;
1606
1607 if (sp->cmn.fcphLow < FC_PH_4_3)
1608 sp->cmn.fcphLow = FC_PH_4_3;
1609
1610 if (sp->cmn.fcphHigh < FC_PH3)
1611 sp->cmn.fcphHigh = FC_PH3;
1612
James Smart858c9f62007-06-17 19:56:39 -05001613 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1614 "Issue PLOGI: did:x%x",
1615 did, 0, 0);
1616
dea31012005-04-17 16:05:31 -05001617 phba->fc_stat.elsXmitPLOGI++;
1618 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001619 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001620
1621 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001622 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001623 return 1;
dea31012005-04-17 16:05:31 -05001624 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001625 return 0;
dea31012005-04-17 16:05:31 -05001626}
1627
James Smarte59058c2008-08-24 21:49:00 -04001628/**
James Smart3621a712009-04-06 18:47:14 -04001629 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001630 * @phba: pointer to lpfc hba data structure.
1631 * @cmdiocb: pointer to lpfc command iocb data structure.
1632 * @rspiocb: pointer to lpfc response iocb data structure.
1633 *
1634 * This routine is the completion callback function for a Process Login
1635 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1636 * status. If there is error status reported, PRLI retry shall be attempted
1637 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1638 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1639 * ndlp to mark the PRLI completion.
1640 **/
dea31012005-04-17 16:05:31 -05001641static void
James Smart2e0fef82007-06-17 19:56:36 -05001642lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1643 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001644{
James Smart2e0fef82007-06-17 19:56:36 -05001645 struct lpfc_vport *vport = cmdiocb->vport;
1646 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001647 IOCB_t *irsp;
1648 struct lpfc_sli *psli;
1649 struct lpfc_nodelist *ndlp;
1650
1651 psli = &phba->sli;
1652 /* we pass cmdiocb to state machine which needs rspiocb as well */
1653 cmdiocb->context_un.rsp_iocb = rspiocb;
1654
1655 irsp = &(rspiocb->iocb);
1656 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001657 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001658 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001659 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001660
James Smart858c9f62007-06-17 19:56:39 -05001661 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1662 "PRLI cmpl: status:x%x/x%x did:x%x",
1663 irsp->ulpStatus, irsp->un.ulpWord[4],
1664 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001665 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001666 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1667 "0103 PRLI completes to NPort x%x "
1668 "Data: x%x x%x x%x x%x\n",
1669 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1670 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001671
James Smart2e0fef82007-06-17 19:56:36 -05001672 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001673 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001674 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001675 goto out;
1676
1677 if (irsp->ulpStatus) {
1678 /* Check for retry */
1679 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1680 /* ELS command is being retried */
1681 goto out;
1682 }
1683 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001684 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1685 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1686 ndlp->nlp_DID, irsp->ulpStatus,
1687 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001688 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001689 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001690 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001691 else
James Smart2e0fef82007-06-17 19:56:36 -05001692 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001693 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001694 } else
dea31012005-04-17 16:05:31 -05001695 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001696 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001697 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001698out:
1699 lpfc_els_free_iocb(phba, cmdiocb);
1700 return;
1701}
1702
James Smarte59058c2008-08-24 21:49:00 -04001703/**
James Smart3621a712009-04-06 18:47:14 -04001704 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001705 * @vport: pointer to a host virtual N_Port data structure.
1706 * @ndlp: pointer to a node-list data structure.
1707 * @retry: number of retries to the command IOCB.
1708 *
1709 * This routine issues a Process Login (PRLI) ELS command for the
1710 * @vport. The PRLI service parameters are set up in the payload of the
1711 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1712 * is put to the IOCB completion callback func field before invoking the
1713 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1714 *
1715 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1716 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1717 * will be stored into the context1 field of the IOCB for the completion
1718 * callback function to the PRLI ELS command.
1719 *
1720 * Return code
1721 * 0 - successfully issued prli iocb command for @vport
1722 * 1 - failed to issue prli iocb command for @vport
1723 **/
dea31012005-04-17 16:05:31 -05001724int
James Smart2e0fef82007-06-17 19:56:36 -05001725lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001726 uint8_t retry)
1727{
James Smart2e0fef82007-06-17 19:56:36 -05001728 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1729 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001730 PRLI *npr;
1731 IOCB_t *icmd;
1732 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001733 uint8_t *pcmd;
1734 uint16_t cmdsize;
1735
James Smart92d7f7b2007-06-17 19:56:38 -05001736 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001737 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1738 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001739 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001740 return 1;
dea31012005-04-17 16:05:31 -05001741
1742 icmd = &elsiocb->iocb;
1743 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1744
1745 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001746 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001747 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001748 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001749
1750 /* For PRLI, remainder of payload is PRLI parameter page */
1751 npr = (PRLI *) pcmd;
1752 /*
1753 * If our firmware version is 3.20 or later,
1754 * set the following bits for FC-TAPE support.
1755 */
1756 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1757 npr->ConfmComplAllowed = 1;
1758 npr->Retry = 1;
1759 npr->TaskRetryIdReq = 1;
1760 }
1761 npr->estabImagePair = 1;
1762 npr->readXferRdyDis = 1;
1763
1764 /* For FCP support */
1765 npr->prliType = PRLI_FCP_TYPE;
1766 npr->initiatorFunc = 1;
1767
James Smart858c9f62007-06-17 19:56:39 -05001768 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1769 "Issue PRLI: did:x%x",
1770 ndlp->nlp_DID, 0, 0);
1771
dea31012005-04-17 16:05:31 -05001772 phba->fc_stat.elsXmitPRLI++;
1773 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001774 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001775 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001776 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001777 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1778 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001779 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001780 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001781 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001782 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001783 return 1;
dea31012005-04-17 16:05:31 -05001784 }
James Smart2e0fef82007-06-17 19:56:36 -05001785 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001786 return 0;
dea31012005-04-17 16:05:31 -05001787}
1788
James Smarte59058c2008-08-24 21:49:00 -04001789/**
James Smart3621a712009-04-06 18:47:14 -04001790 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001791 * @vport: pointer to a host virtual N_Port data structure.
1792 *
1793 * This routine performs Registration State Change Notification (RSCN)
1794 * discovery for a @vport. If the @vport's node port recovery count is not
1795 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1796 * the nodes that need recovery. If none of the PLOGI were needed through
1797 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1798 * invoked to check and handle possible more RSCN came in during the period
1799 * of processing the current ones.
1800 **/
1801static void
1802lpfc_rscn_disc(struct lpfc_vport *vport)
1803{
1804 lpfc_can_disctmo(vport);
1805
1806 /* RSCN discovery */
1807 /* go thru NPR nodes and issue ELS PLOGIs */
1808 if (vport->fc_npr_cnt)
1809 if (lpfc_els_disc_plogi(vport))
1810 return;
1811
1812 lpfc_end_rscn(vport);
1813}
1814
1815/**
James Smart3621a712009-04-06 18:47:14 -04001816 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001817 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1818 *
1819 * This function is called when the final ADISC is completed during discovery.
1820 * This function handles clearing link attention or issuing reg_vpi depending
1821 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1822 * discovery.
1823 * This function is called with no locks held.
1824 **/
1825static void
1826lpfc_adisc_done(struct lpfc_vport *vport)
1827{
1828 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1829 struct lpfc_hba *phba = vport->phba;
1830
1831 /*
1832 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1833 * and continue discovery.
1834 */
1835 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04001836 !(vport->fc_flag & FC_RSCN_MODE) &&
1837 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04001838 lpfc_issue_reg_vpi(phba, vport);
1839 return;
1840 }
1841 /*
1842 * For SLI2, we need to set port_state to READY
1843 * and continue discovery.
1844 */
1845 if (vport->port_state < LPFC_VPORT_READY) {
1846 /* If we get here, there is nothing to ADISC */
1847 if (vport->port_type == LPFC_PHYSICAL_PORT)
1848 lpfc_issue_clear_la(phba, vport);
1849 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1850 vport->num_disc_nodes = 0;
1851 /* go thru NPR list, issue ELS PLOGIs */
1852 if (vport->fc_npr_cnt)
1853 lpfc_els_disc_plogi(vport);
1854 if (!vport->num_disc_nodes) {
1855 spin_lock_irq(shost->host_lock);
1856 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1857 spin_unlock_irq(shost->host_lock);
1858 lpfc_can_disctmo(vport);
1859 lpfc_end_rscn(vport);
1860 }
1861 }
1862 vport->port_state = LPFC_VPORT_READY;
1863 } else
1864 lpfc_rscn_disc(vport);
1865}
1866
1867/**
James Smart3621a712009-04-06 18:47:14 -04001868 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001869 * @vport: pointer to a host virtual N_Port data structure.
1870 *
1871 * This routine determines whether there are more ndlps on a @vport
1872 * node list need to have Address Discover (ADISC) issued. If so, it will
1873 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1874 * remaining nodes which need to have ADISC sent.
1875 **/
James Smart0ff10d42008-01-11 01:52:36 -05001876void
James Smart2e0fef82007-06-17 19:56:36 -05001877lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001878{
1879 int sentadisc;
1880
James Smart2e0fef82007-06-17 19:56:36 -05001881 if (vport->num_disc_nodes)
1882 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001883 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001884 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1885 "0210 Continue discovery with %d ADISCs to go "
1886 "Data: x%x x%x x%x\n",
1887 vport->num_disc_nodes, vport->fc_adisc_cnt,
1888 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001889 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001890 if (vport->fc_flag & FC_NLP_MORE) {
1891 lpfc_set_disctmo(vport);
1892 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1893 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001894 }
James Smart90160e02008-08-24 21:49:45 -04001895 if (!vport->num_disc_nodes)
1896 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001897 return;
1898}
1899
James Smarte59058c2008-08-24 21:49:00 -04001900/**
James Smart3621a712009-04-06 18:47:14 -04001901 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04001902 * @phba: pointer to lpfc hba data structure.
1903 * @cmdiocb: pointer to lpfc command iocb data structure.
1904 * @rspiocb: pointer to lpfc response iocb data structure.
1905 *
1906 * This routine is the completion function for issuing the Address Discover
1907 * (ADISC) command. It first checks to see whether link went down during
1908 * the discovery process. If so, the node will be marked as node port
1909 * recovery for issuing discover IOCB by the link attention handler and
1910 * exit. Otherwise, the response status is checked. If error was reported
1911 * in the response status, the ADISC command shall be retried by invoking
1912 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1913 * the response status, the state machine is invoked to set transition
1914 * with respect to NLP_EVT_CMPL_ADISC event.
1915 **/
dea31012005-04-17 16:05:31 -05001916static void
James Smart2e0fef82007-06-17 19:56:36 -05001917lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1918 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001919{
James Smart2e0fef82007-06-17 19:56:36 -05001920 struct lpfc_vport *vport = cmdiocb->vport;
1921 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001922 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001923 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001924 int disc;
dea31012005-04-17 16:05:31 -05001925
1926 /* we pass cmdiocb to state machine which needs rspiocb as well */
1927 cmdiocb->context_un.rsp_iocb = rspiocb;
1928
1929 irsp = &(rspiocb->iocb);
1930 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001931
James Smart858c9f62007-06-17 19:56:39 -05001932 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1933 "ADISC cmpl: status:x%x/x%x did:x%x",
1934 irsp->ulpStatus, irsp->un.ulpWord[4],
1935 ndlp->nlp_DID);
1936
dea31012005-04-17 16:05:31 -05001937 /* Since ndlp can be freed in the disc state machine, note if this node
1938 * is being used during discovery.
1939 */
James Smart2e0fef82007-06-17 19:56:36 -05001940 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001941 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001942 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001943 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001944 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001945 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1946 "0104 ADISC completes to NPort x%x "
1947 "Data: x%x x%x x%x x%x x%x\n",
1948 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1949 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001950 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001951 if (lpfc_els_chk_latt(vport)) {
1952 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001953 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001954 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001955 goto out;
1956 }
1957
1958 if (irsp->ulpStatus) {
1959 /* Check for retry */
1960 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1961 /* ELS command is being retried */
1962 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001963 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001964 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001965 spin_unlock_irq(shost->host_lock);
1966 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001967 }
1968 goto out;
1969 }
1970 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05001971 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1972 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
1973 ndlp->nlp_DID, irsp->ulpStatus,
1974 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001975 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001976 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001977 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001978 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001979 } else
dea31012005-04-17 16:05:31 -05001980 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001981 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001982 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001983
James Smart90160e02008-08-24 21:49:45 -04001984 /* Check to see if there are more ADISCs to be sent */
1985 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05001986 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001987out:
1988 lpfc_els_free_iocb(phba, cmdiocb);
1989 return;
1990}
1991
James Smarte59058c2008-08-24 21:49:00 -04001992/**
James Smart3621a712009-04-06 18:47:14 -04001993 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04001994 * @vport: pointer to a virtual N_Port data structure.
1995 * @ndlp: pointer to a node-list data structure.
1996 * @retry: number of retries to the command IOCB.
1997 *
1998 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1999 * @vport. It prepares the payload of the ADISC ELS command, updates the
2000 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2001 * to issue the ADISC ELS command.
2002 *
2003 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2004 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2005 * will be stored into the context1 field of the IOCB for the completion
2006 * callback function to the ADISC ELS command.
2007 *
2008 * Return code
2009 * 0 - successfully issued adisc
2010 * 1 - failed to issue adisc
2011 **/
dea31012005-04-17 16:05:31 -05002012int
James Smart2e0fef82007-06-17 19:56:36 -05002013lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002014 uint8_t retry)
2015{
James Smart2e0fef82007-06-17 19:56:36 -05002016 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2017 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002018 ADISC *ap;
2019 IOCB_t *icmd;
2020 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002021 uint8_t *pcmd;
2022 uint16_t cmdsize;
2023
James Smart92d7f7b2007-06-17 19:56:38 -05002024 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002025 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2026 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002027 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002028 return 1;
dea31012005-04-17 16:05:31 -05002029
2030 icmd = &elsiocb->iocb;
2031 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2032
2033 /* For ADISC request, remainder of payload is service parameters */
2034 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002035 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002036
2037 /* Fill in ADISC payload */
2038 ap = (ADISC *) pcmd;
2039 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002040 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2041 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002042 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002043
James Smart858c9f62007-06-17 19:56:39 -05002044 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2045 "Issue ADISC: did:x%x",
2046 ndlp->nlp_DID, 0, 0);
2047
dea31012005-04-17 16:05:31 -05002048 phba->fc_stat.elsXmitADISC++;
2049 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002050 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002051 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002052 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002053 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2054 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002055 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002056 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002057 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002058 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002059 return 1;
dea31012005-04-17 16:05:31 -05002060 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002061 return 0;
dea31012005-04-17 16:05:31 -05002062}
2063
James Smarte59058c2008-08-24 21:49:00 -04002064/**
James Smart3621a712009-04-06 18:47:14 -04002065 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002066 * @phba: pointer to lpfc hba data structure.
2067 * @cmdiocb: pointer to lpfc command iocb data structure.
2068 * @rspiocb: pointer to lpfc response iocb data structure.
2069 *
2070 * This routine is the completion function for issuing the ELS Logout (LOGO)
2071 * command. If no error status was reported from the LOGO response, the
2072 * state machine of the associated ndlp shall be invoked for transition with
2073 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2074 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2075 **/
dea31012005-04-17 16:05:31 -05002076static void
James Smart2e0fef82007-06-17 19:56:36 -05002077lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2078 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002079{
James Smart2e0fef82007-06-17 19:56:36 -05002080 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2081 struct lpfc_vport *vport = ndlp->vport;
2082 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002083 IOCB_t *irsp;
2084 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002085
2086 psli = &phba->sli;
2087 /* we pass cmdiocb to state machine which needs rspiocb as well */
2088 cmdiocb->context_un.rsp_iocb = rspiocb;
2089
2090 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002091 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002092 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002093 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002094
James Smart858c9f62007-06-17 19:56:39 -05002095 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2096 "LOGO cmpl: status:x%x/x%x did:x%x",
2097 irsp->ulpStatus, irsp->un.ulpWord[4],
2098 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002099 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002100 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2101 "0105 LOGO completes to NPort x%x "
2102 "Data: x%x x%x x%x x%x\n",
2103 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2104 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002105 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002106 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002107 goto out;
2108
James Smart92d7f7b2007-06-17 19:56:38 -05002109 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2110 /* NLP_EVT_DEVICE_RM should unregister the RPI
2111 * which should abort all outstanding IOs.
2112 */
2113 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2114 NLP_EVT_DEVICE_RM);
2115 goto out;
2116 }
2117
dea31012005-04-17 16:05:31 -05002118 if (irsp->ulpStatus) {
2119 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002120 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002121 /* ELS command is being retried */
2122 goto out;
dea31012005-04-17 16:05:31 -05002123 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002124 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2125 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2126 ndlp->nlp_DID, irsp->ulpStatus,
2127 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002128 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002129 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002130 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002131 else
James Smart2e0fef82007-06-17 19:56:36 -05002132 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002133 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002134 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002135 /* Good status, call state machine.
2136 * This will unregister the rpi if needed.
2137 */
James Smart2e0fef82007-06-17 19:56:36 -05002138 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002139 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002140out:
2141 lpfc_els_free_iocb(phba, cmdiocb);
2142 return;
2143}
2144
James Smarte59058c2008-08-24 21:49:00 -04002145/**
James Smart3621a712009-04-06 18:47:14 -04002146 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002147 * @vport: pointer to a virtual N_Port data structure.
2148 * @ndlp: pointer to a node-list data structure.
2149 * @retry: number of retries to the command IOCB.
2150 *
2151 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2152 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2153 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2154 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2155 *
2156 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2157 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2158 * will be stored into the context1 field of the IOCB for the completion
2159 * callback function to the LOGO ELS command.
2160 *
2161 * Return code
2162 * 0 - successfully issued logo
2163 * 1 - failed to issue logo
2164 **/
dea31012005-04-17 16:05:31 -05002165int
James Smart2e0fef82007-06-17 19:56:36 -05002166lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002167 uint8_t retry)
2168{
James Smart2e0fef82007-06-17 19:56:36 -05002169 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2170 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002171 IOCB_t *icmd;
2172 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002173 uint8_t *pcmd;
2174 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002175 int rc;
dea31012005-04-17 16:05:31 -05002176
James Smart98c9ea52007-10-27 13:37:33 -04002177 spin_lock_irq(shost->host_lock);
2178 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2179 spin_unlock_irq(shost->host_lock);
2180 return 0;
2181 }
2182 spin_unlock_irq(shost->host_lock);
2183
James Smart92d7f7b2007-06-17 19:56:38 -05002184 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002185 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2186 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002187 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002188 return 1;
dea31012005-04-17 16:05:31 -05002189
2190 icmd = &elsiocb->iocb;
2191 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2192 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002193 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002194
2195 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002196 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002197 pcmd += sizeof(uint32_t);
2198 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002199
James Smart858c9f62007-06-17 19:56:39 -05002200 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2201 "Issue LOGO: did:x%x",
2202 ndlp->nlp_DID, 0, 0);
2203
dea31012005-04-17 16:05:31 -05002204 phba->fc_stat.elsXmitLOGO++;
2205 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002206 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002207 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002208 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002209 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002210
2211 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002212 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002213 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002214 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002215 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002216 return 1;
dea31012005-04-17 16:05:31 -05002217 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002218 return 0;
dea31012005-04-17 16:05:31 -05002219}
2220
James Smarte59058c2008-08-24 21:49:00 -04002221/**
James Smart3621a712009-04-06 18:47:14 -04002222 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002223 * @phba: pointer to lpfc hba data structure.
2224 * @cmdiocb: pointer to lpfc command iocb data structure.
2225 * @rspiocb: pointer to lpfc response iocb data structure.
2226 *
2227 * This routine is a generic completion callback function for ELS commands.
2228 * Specifically, it is the callback function which does not need to perform
2229 * any command specific operations. It is currently used by the ELS command
2230 * issuing routines for the ELS State Change Request (SCR),
2231 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2232 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2233 * certain debug loggings, this callback function simply invokes the
2234 * lpfc_els_chk_latt() routine to check whether link went down during the
2235 * discovery process.
2236 **/
dea31012005-04-17 16:05:31 -05002237static void
James Smart2e0fef82007-06-17 19:56:36 -05002238lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2239 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002240{
James Smart2e0fef82007-06-17 19:56:36 -05002241 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002242 IOCB_t *irsp;
2243
2244 irsp = &rspiocb->iocb;
2245
James Smart858c9f62007-06-17 19:56:39 -05002246 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2247 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2248 irsp->ulpStatus, irsp->un.ulpWord[4],
2249 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002250 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002251 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2252 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2253 irsp->ulpIoTag, irsp->ulpStatus,
2254 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002255 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002256 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002257 lpfc_els_free_iocb(phba, cmdiocb);
2258 return;
2259}
2260
James Smarte59058c2008-08-24 21:49:00 -04002261/**
James Smart3621a712009-04-06 18:47:14 -04002262 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002263 * @vport: pointer to a host virtual N_Port data structure.
2264 * @nportid: N_Port identifier to the remote node.
2265 * @retry: number of retries to the command IOCB.
2266 *
2267 * This routine issues a State Change Request (SCR) to a fabric node
2268 * on a @vport. The remote node @nportid is passed into the function. It
2269 * first search the @vport node list to find the matching ndlp. If no such
2270 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2271 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2272 * routine is invoked to send the SCR IOCB.
2273 *
2274 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2275 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2276 * will be stored into the context1 field of the IOCB for the completion
2277 * callback function to the SCR ELS command.
2278 *
2279 * Return code
2280 * 0 - Successfully issued scr command
2281 * 1 - Failed to issue scr command
2282 **/
dea31012005-04-17 16:05:31 -05002283int
James Smart2e0fef82007-06-17 19:56:36 -05002284lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002285{
James Smart2e0fef82007-06-17 19:56:36 -05002286 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002287 IOCB_t *icmd;
2288 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002289 struct lpfc_sli *psli;
2290 uint8_t *pcmd;
2291 uint16_t cmdsize;
2292 struct lpfc_nodelist *ndlp;
2293
2294 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002295 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002296
James Smarte47c9092008-02-08 18:49:26 -05002297 ndlp = lpfc_findnode_did(vport, nportid);
2298 if (!ndlp) {
2299 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2300 if (!ndlp)
2301 return 1;
2302 lpfc_nlp_init(vport, ndlp, nportid);
2303 lpfc_enqueue_node(vport, ndlp);
2304 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2305 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2306 if (!ndlp)
2307 return 1;
2308 }
dea31012005-04-17 16:05:31 -05002309
James Smart2e0fef82007-06-17 19:56:36 -05002310 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2311 ndlp->nlp_DID, ELS_CMD_SCR);
2312
James Smart488d1462006-03-07 15:02:37 -05002313 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002314 /* This will trigger the release of the node just
2315 * allocated
2316 */
James Smart329f9bc2007-04-25 09:53:01 -04002317 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002318 return 1;
dea31012005-04-17 16:05:31 -05002319 }
2320
2321 icmd = &elsiocb->iocb;
2322 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2323
2324 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002325 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002326
2327 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002328 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002329 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2330
James Smart858c9f62007-06-17 19:56:39 -05002331 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2332 "Issue SCR: did:x%x",
2333 ndlp->nlp_DID, 0, 0);
2334
dea31012005-04-17 16:05:31 -05002335 phba->fc_stat.elsXmitSCR++;
2336 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002337 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2338 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002339 /* The additional lpfc_nlp_put will cause the following
2340 * lpfc_els_free_iocb routine to trigger the rlease of
2341 * the node.
2342 */
James Smart329f9bc2007-04-25 09:53:01 -04002343 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002344 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002345 return 1;
dea31012005-04-17 16:05:31 -05002346 }
James Smartfa4066b2008-01-11 01:53:27 -05002347 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2348 * trigger the release of node.
2349 */
James Smart329f9bc2007-04-25 09:53:01 -04002350 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002351 return 0;
dea31012005-04-17 16:05:31 -05002352}
2353
James Smarte59058c2008-08-24 21:49:00 -04002354/**
James Smart3621a712009-04-06 18:47:14 -04002355 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002356 * @vport: pointer to a host virtual N_Port data structure.
2357 * @nportid: N_Port identifier to the remote node.
2358 * @retry: number of retries to the command IOCB.
2359 *
2360 * This routine issues a Fibre Channel Address Resolution Response
2361 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2362 * is passed into the function. It first search the @vport node list to find
2363 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2364 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2365 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2366 *
2367 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2368 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2369 * will be stored into the context1 field of the IOCB for the completion
2370 * callback function to the PARPR ELS command.
2371 *
2372 * Return code
2373 * 0 - Successfully issued farpr command
2374 * 1 - Failed to issue farpr command
2375 **/
dea31012005-04-17 16:05:31 -05002376static int
James Smart2e0fef82007-06-17 19:56:36 -05002377lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002378{
James Smart2e0fef82007-06-17 19:56:36 -05002379 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002380 IOCB_t *icmd;
2381 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002382 struct lpfc_sli *psli;
2383 FARP *fp;
2384 uint8_t *pcmd;
2385 uint32_t *lp;
2386 uint16_t cmdsize;
2387 struct lpfc_nodelist *ondlp;
2388 struct lpfc_nodelist *ndlp;
2389
2390 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002391 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002392
James Smarte47c9092008-02-08 18:49:26 -05002393 ndlp = lpfc_findnode_did(vport, nportid);
2394 if (!ndlp) {
2395 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2396 if (!ndlp)
2397 return 1;
2398 lpfc_nlp_init(vport, ndlp, nportid);
2399 lpfc_enqueue_node(vport, ndlp);
2400 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2401 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2402 if (!ndlp)
2403 return 1;
2404 }
James Smart2e0fef82007-06-17 19:56:36 -05002405
2406 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2407 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002408 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002409 /* This will trigger the release of the node just
2410 * allocated
2411 */
James Smart329f9bc2007-04-25 09:53:01 -04002412 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002413 return 1;
dea31012005-04-17 16:05:31 -05002414 }
2415
2416 icmd = &elsiocb->iocb;
2417 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2418
2419 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002420 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002421
2422 /* Fill in FARPR payload */
2423 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002424 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002425 lp = (uint32_t *) pcmd;
2426 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002427 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002428 fp->Rflags = 0;
2429 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2430
James Smart92d7f7b2007-06-17 19:56:38 -05002431 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2432 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002433 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002434 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002435 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002436 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002437 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002438 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002439 }
2440
James Smart858c9f62007-06-17 19:56:39 -05002441 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2442 "Issue FARPR: did:x%x",
2443 ndlp->nlp_DID, 0, 0);
2444
dea31012005-04-17 16:05:31 -05002445 phba->fc_stat.elsXmitFARPR++;
2446 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002447 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2448 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002449 /* The additional lpfc_nlp_put will cause the following
2450 * lpfc_els_free_iocb routine to trigger the release of
2451 * the node.
2452 */
James Smart329f9bc2007-04-25 09:53:01 -04002453 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002454 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002455 return 1;
dea31012005-04-17 16:05:31 -05002456 }
James Smartfa4066b2008-01-11 01:53:27 -05002457 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2458 * trigger the release of the node.
2459 */
James Smart329f9bc2007-04-25 09:53:01 -04002460 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002461 return 0;
dea31012005-04-17 16:05:31 -05002462}
2463
James Smarte59058c2008-08-24 21:49:00 -04002464/**
James Smart3621a712009-04-06 18:47:14 -04002465 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002466 * @vport: pointer to a host virtual N_Port data structure.
2467 * @nlp: pointer to a node-list data structure.
2468 *
2469 * This routine cancels the timer with a delayed IOCB-command retry for
2470 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2471 * removes the ELS retry event if it presents. In addition, if the
2472 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2473 * commands are sent for the @vport's nodes that require issuing discovery
2474 * ADISC.
2475 **/
dea31012005-04-17 16:05:31 -05002476void
James Smart2e0fef82007-06-17 19:56:36 -05002477lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002478{
James Smart2e0fef82007-06-17 19:56:36 -05002479 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002480 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002481
James Smart0d2b6b82008-06-14 22:52:47 -04002482 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2483 return;
James Smart2e0fef82007-06-17 19:56:36 -05002484 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002485 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002486 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002487 del_timer_sync(&nlp->nlp_delayfunc);
2488 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002489 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002490 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002491 /* Decrement nlp reference count held for the delayed retry */
2492 evtp = &nlp->els_retry_evt;
2493 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2494 }
James Smartfdcebe22006-03-07 15:04:01 -05002495 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002496 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002497 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002498 spin_unlock_irq(shost->host_lock);
2499 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002500 if (vport->port_state < LPFC_VPORT_READY) {
2501 /* Check if there are more ADISCs to be sent */
2502 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002503 } else {
2504 /* Check if there are more PLOGIs to be sent */
2505 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002506 if (vport->num_disc_nodes == 0) {
2507 spin_lock_irq(shost->host_lock);
2508 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2509 spin_unlock_irq(shost->host_lock);
2510 lpfc_can_disctmo(vport);
2511 lpfc_end_rscn(vport);
2512 }
James Smartfdcebe22006-03-07 15:04:01 -05002513 }
2514 }
2515 }
2516 return;
2517}
2518
James Smarte59058c2008-08-24 21:49:00 -04002519/**
James Smart3621a712009-04-06 18:47:14 -04002520 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002521 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2522 *
2523 * This routine is invoked by the ndlp delayed-function timer to check
2524 * whether there is any pending ELS retry event(s) with the node. If not, it
2525 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2526 * adds the delayed events to the HBA work list and invokes the
2527 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2528 * event. Note that lpfc_nlp_get() is called before posting the event to
2529 * the work list to hold reference count of ndlp so that it guarantees the
2530 * reference to ndlp will still be available when the worker thread gets
2531 * to the event associated with the ndlp.
2532 **/
James Smartfdcebe22006-03-07 15:04:01 -05002533void
dea31012005-04-17 16:05:31 -05002534lpfc_els_retry_delay(unsigned long ptr)
2535{
James Smart2e0fef82007-06-17 19:56:36 -05002536 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2537 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002538 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002539 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002540 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002541
James Smart92d7f7b2007-06-17 19:56:38 -05002542 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002543 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002544 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002545 return;
2546 }
2547
James Smartfa4066b2008-01-11 01:53:27 -05002548 /* We need to hold the node by incrementing the reference
2549 * count until the queued work is done
2550 */
2551 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002552 if (evtp->evt_arg1) {
2553 evtp->evt = LPFC_EVT_ELS_RETRY;
2554 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002555 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002556 }
James Smart92d7f7b2007-06-17 19:56:38 -05002557 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002558 return;
2559}
2560
James Smarte59058c2008-08-24 21:49:00 -04002561/**
James Smart3621a712009-04-06 18:47:14 -04002562 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002563 * @ndlp: pointer to a node-list data structure.
2564 *
2565 * This routine is the worker-thread handler for processing the @ndlp delayed
2566 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2567 * the last ELS command from the associated ndlp and invokes the proper ELS
2568 * function according to the delayed ELS command to retry the command.
2569 **/
dea31012005-04-17 16:05:31 -05002570void
2571lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2572{
James Smart2e0fef82007-06-17 19:56:36 -05002573 struct lpfc_vport *vport = ndlp->vport;
2574 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2575 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002576
James Smart2e0fef82007-06-17 19:56:36 -05002577 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002578 did = ndlp->nlp_DID;
2579 cmd = ndlp->nlp_last_elscmd;
2580 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002581
2582 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002583 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002584 return;
2585 }
2586
2587 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002588 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002589 /*
2590 * If a discovery event readded nlp_delayfunc after timer
2591 * firing and before processing the timer, cancel the
2592 * nlp_delayfunc.
2593 */
2594 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002595 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002596 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002597
2598 switch (cmd) {
2599 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002600 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002601 break;
2602 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002603 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002604 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002605 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002606 }
dea31012005-04-17 16:05:31 -05002607 break;
2608 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002609 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002610 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002611 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002612 }
dea31012005-04-17 16:05:31 -05002613 break;
2614 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002615 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002616 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002617 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002618 }
dea31012005-04-17 16:05:31 -05002619 break;
2620 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002621 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002622 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002623 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002624 }
dea31012005-04-17 16:05:31 -05002625 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002626 case ELS_CMD_FDISC:
2627 lpfc_issue_els_fdisc(vport, ndlp, retry);
2628 break;
dea31012005-04-17 16:05:31 -05002629 }
2630 return;
2631}
2632
James Smarte59058c2008-08-24 21:49:00 -04002633/**
James Smart3621a712009-04-06 18:47:14 -04002634 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002635 * @phba: pointer to lpfc hba data structure.
2636 * @cmdiocb: pointer to lpfc command iocb data structure.
2637 * @rspiocb: pointer to lpfc response iocb data structure.
2638 *
2639 * This routine makes a retry decision on an ELS command IOCB, which has
2640 * failed. The following ELS IOCBs use this function for retrying the command
2641 * when previously issued command responsed with error status: FLOGI, PLOGI,
2642 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2643 * returned error status, it makes the decision whether a retry shall be
2644 * issued for the command, and whether a retry shall be made immediately or
2645 * delayed. In the former case, the corresponding ELS command issuing-function
2646 * is called to retry the command. In the later case, the ELS command shall
2647 * be posted to the ndlp delayed event and delayed function timer set to the
2648 * ndlp for the delayed command issusing.
2649 *
2650 * Return code
2651 * 0 - No retry of els command is made
2652 * 1 - Immediate or delayed retry of els command is made
2653 **/
dea31012005-04-17 16:05:31 -05002654static int
James Smart2e0fef82007-06-17 19:56:36 -05002655lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2656 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002657{
James Smart2e0fef82007-06-17 19:56:36 -05002658 struct lpfc_vport *vport = cmdiocb->vport;
2659 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2660 IOCB_t *irsp = &rspiocb->iocb;
2661 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2662 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002663 uint32_t *elscmd;
2664 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002665 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002666 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002667 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002668 uint32_t did;
dea31012005-04-17 16:05:31 -05002669
James Smart488d1462006-03-07 15:02:37 -05002670
dea31012005-04-17 16:05:31 -05002671 /* Note: context2 may be 0 for internal driver abort
2672 * of delays ELS command.
2673 */
2674
2675 if (pcmd && pcmd->virt) {
2676 elscmd = (uint32_t *) (pcmd->virt);
2677 cmd = *elscmd++;
2678 }
2679
James Smarte47c9092008-02-08 18:49:26 -05002680 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002681 did = ndlp->nlp_DID;
2682 else {
2683 /* We should only hit this case for retrying PLOGI */
2684 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002685 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002686 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2687 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002688 return 1;
2689 }
2690
James Smart858c9f62007-06-17 19:56:39 -05002691 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2692 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2693 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2694
dea31012005-04-17 16:05:31 -05002695 switch (irsp->ulpStatus) {
2696 case IOSTAT_FCP_RSP_ERROR:
2697 case IOSTAT_REMOTE_STOP:
2698 break;
2699
2700 case IOSTAT_LOCAL_REJECT:
2701 switch ((irsp->un.ulpWord[4] & 0xff)) {
2702 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002703 if (cmd == ELS_CMD_FLOGI) {
2704 if (PCI_DEVICE_ID_HORNET ==
2705 phba->pcidev->device) {
2706 phba->fc_topology = TOPOLOGY_LOOP;
2707 phba->pport->fc_myDID = 0;
2708 phba->alpa_map[0] = 0;
2709 phba->alpa_map[1] = 0;
2710 }
2711 }
James Smart2e0fef82007-06-17 19:56:36 -05002712 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002713 delay = 1000;
dea31012005-04-17 16:05:31 -05002714 retry = 1;
2715 break;
2716
James Smart92d7f7b2007-06-17 19:56:38 -05002717 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002718 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2719 "0124 Retry illegal cmd x%x "
2720 "retry:x%x delay:x%x\n",
2721 cmd, cmdiocb->retry, delay);
2722 retry = 1;
2723 /* All command's retry policy */
2724 maxretry = 8;
2725 if (cmdiocb->retry > 2)
2726 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002727 break;
2728
dea31012005-04-17 16:05:31 -05002729 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002730 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002731 retry = 1;
2732 if (cmdiocb->retry > 100)
2733 delay = 100;
2734 maxretry = 250;
2735 break;
2736
2737 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002738 delay = 100;
dea31012005-04-17 16:05:31 -05002739 retry = 1;
2740 break;
2741
James Smart858c9f62007-06-17 19:56:39 -05002742 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002743 case IOERR_INVALID_RPI:
2744 retry = 1;
2745 break;
2746 }
2747 break;
2748
2749 case IOSTAT_NPORT_RJT:
2750 case IOSTAT_FABRIC_RJT:
2751 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2752 retry = 1;
2753 break;
2754 }
2755 break;
2756
2757 case IOSTAT_NPORT_BSY:
2758 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002759 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002760 retry = 1;
2761 break;
2762
2763 case IOSTAT_LS_RJT:
2764 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2765 /* Added for Vendor specifc support
2766 * Just keep retrying for these Rsn / Exp codes
2767 */
2768 switch (stat.un.b.lsRjtRsnCode) {
2769 case LSRJT_UNABLE_TPC:
2770 if (stat.un.b.lsRjtRsnCodeExp ==
2771 LSEXP_CMD_IN_PROGRESS) {
2772 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002773 delay = 1000;
dea31012005-04-17 16:05:31 -05002774 maxretry = 48;
2775 }
2776 retry = 1;
2777 break;
2778 }
James Smartffc95492010-06-07 15:23:17 -04002779 if (stat.un.b.lsRjtRsnCodeExp ==
2780 LSEXP_CANT_GIVE_DATA) {
2781 if (cmd == ELS_CMD_PLOGI) {
2782 delay = 1000;
2783 maxretry = 48;
2784 }
2785 retry = 1;
2786 break;
2787 }
dea31012005-04-17 16:05:31 -05002788 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002789 delay = 1000;
dea31012005-04-17 16:05:31 -05002790 maxretry = lpfc_max_els_tries + 1;
2791 retry = 1;
2792 break;
2793 }
James Smart92d7f7b2007-06-17 19:56:38 -05002794 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2795 (cmd == ELS_CMD_FDISC) &&
2796 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002797 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2798 "0125 FDISC Failed (x%x). "
2799 "Fabric out of resources\n",
2800 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002801 lpfc_vport_set_state(vport,
2802 FC_VPORT_NO_FABRIC_RSCS);
2803 }
dea31012005-04-17 16:05:31 -05002804 break;
2805
2806 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002807 if ((cmd == ELS_CMD_PLOGI) ||
2808 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002809 delay = 1000;
dea31012005-04-17 16:05:31 -05002810 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002811 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002812 /* FDISC retry policy */
2813 maxretry = 48;
2814 if (cmdiocb->retry >= 32)
2815 delay = 1000;
dea31012005-04-17 16:05:31 -05002816 }
2817 retry = 1;
2818 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002819
2820 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002821 /* There are some cases where switches return this
2822 * error when they are not ready and should be returning
2823 * Logical Busy. We should delay every time.
2824 */
2825 if (cmd == ELS_CMD_FDISC &&
2826 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2827 maxretry = 3;
2828 delay = 1000;
2829 retry = 1;
2830 break;
2831 }
James Smart92d7f7b2007-06-17 19:56:38 -05002832 case LSRJT_PROTOCOL_ERR:
2833 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2834 (cmd == ELS_CMD_FDISC) &&
2835 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2836 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2837 ) {
James Smarte8b62012007-08-02 11:10:09 -04002838 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002839 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002840 "Fabric Detected Bad WWN\n",
2841 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002842 lpfc_vport_set_state(vport,
2843 FC_VPORT_FABRIC_REJ_WWN);
2844 }
2845 break;
dea31012005-04-17 16:05:31 -05002846 }
2847 break;
2848
2849 case IOSTAT_INTERMED_RSP:
2850 case IOSTAT_BA_RJT:
2851 break;
2852
2853 default:
2854 break;
2855 }
2856
James Smart488d1462006-03-07 15:02:37 -05002857 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002858 retry = 1;
dea31012005-04-17 16:05:31 -05002859
James Smart695a8142010-01-26 23:08:03 -05002860 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002861 (phba->fc_topology != TOPOLOGY_LOOP) &&
2862 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002863 /* FLOGI retry policy */
2864 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04002865 /* retry forever */
2866 maxretry = 0;
2867 if (cmdiocb->retry >= 100)
2868 delay = 5000;
2869 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04002870 delay = 1000;
2871 }
2872
James Smart6669f9b2009-10-02 15:16:45 -04002873 cmdiocb->retry++;
2874 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05002875 phba->fc_stat.elsRetryExceeded++;
2876 retry = 0;
2877 }
2878
James Smarted957682007-06-17 19:56:37 -05002879 if ((vport->load_flag & FC_UNLOADING) != 0)
2880 retry = 0;
2881
dea31012005-04-17 16:05:31 -05002882 if (retry) {
2883
2884 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002885 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2886 "0107 Retry ELS command x%x to remote "
2887 "NPORT x%x Data: x%x x%x\n",
2888 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002889
James Smart858c9f62007-06-17 19:56:39 -05002890 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2891 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2892 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2893 /* Don't reset timer for no resources */
2894
dea31012005-04-17 16:05:31 -05002895 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002896 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002897 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002898 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002899 }
2900
2901 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002902 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002903 phba->fc_stat.elsDelayRetry++;
2904 ndlp->nlp_retry = cmdiocb->retry;
2905
James Smart92d7f7b2007-06-17 19:56:38 -05002906 /* delay is specified in milliseconds */
2907 mod_timer(&ndlp->nlp_delayfunc,
2908 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002909 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002910 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002911 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002912
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002913 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002914 if (cmd == ELS_CMD_PRLI)
2915 lpfc_nlp_set_state(vport, ndlp,
2916 NLP_STE_REG_LOGIN_ISSUE);
2917 else
2918 lpfc_nlp_set_state(vport, ndlp,
2919 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002920 ndlp->nlp_last_elscmd = cmd;
2921
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002922 return 1;
dea31012005-04-17 16:05:31 -05002923 }
2924 switch (cmd) {
2925 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002926 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002927 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002928 case ELS_CMD_FDISC:
2929 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2930 return 1;
dea31012005-04-17 16:05:31 -05002931 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002932 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002933 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002934 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002935 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002936 }
James Smart2e0fef82007-06-17 19:56:36 -05002937 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002938 return 1;
dea31012005-04-17 16:05:31 -05002939 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002940 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002941 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2942 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002943 return 1;
dea31012005-04-17 16:05:31 -05002944 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002945 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002946 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2947 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002948 return 1;
dea31012005-04-17 16:05:31 -05002949 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002950 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002951 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2952 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002953 return 1;
dea31012005-04-17 16:05:31 -05002954 }
2955 }
dea31012005-04-17 16:05:31 -05002956 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002957 if (logerr) {
2958 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2959 "0137 No retry ELS command x%x to remote "
2960 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2961 cmd, did, irsp->ulpStatus,
2962 irsp->un.ulpWord[4]);
2963 }
2964 else {
2965 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002966 "0108 No retry ELS command x%x to remote "
2967 "NPORT x%x Retried:%d Error:x%x/%x\n",
2968 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2969 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002970 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002971 return 0;
dea31012005-04-17 16:05:31 -05002972}
2973
James Smarte59058c2008-08-24 21:49:00 -04002974/**
James Smart3621a712009-04-06 18:47:14 -04002975 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04002976 * @phba: pointer to lpfc hba data structure.
2977 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2978 *
2979 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2980 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2981 * checks to see whether there is a lpfc DMA buffer associated with the
2982 * response of the command IOCB. If so, it will be released before releasing
2983 * the lpfc DMA buffer associated with the IOCB itself.
2984 *
2985 * Return code
2986 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2987 **/
James Smart09372822008-01-11 01:52:54 -05002988static int
James Smart87af33f2007-10-27 13:37:43 -04002989lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2990{
2991 struct lpfc_dmabuf *buf_ptr;
2992
James Smarte59058c2008-08-24 21:49:00 -04002993 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04002994 if (!list_empty(&buf_ptr1->list)) {
2995 list_remove_head(&buf_ptr1->list, buf_ptr,
2996 struct lpfc_dmabuf,
2997 list);
2998 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2999 kfree(buf_ptr);
3000 }
3001 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3002 kfree(buf_ptr1);
3003 return 0;
3004}
3005
James Smarte59058c2008-08-24 21:49:00 -04003006/**
James Smart3621a712009-04-06 18:47:14 -04003007 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003008 * @phba: pointer to lpfc hba data structure.
3009 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3010 *
3011 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3012 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3013 * pool.
3014 *
3015 * Return code
3016 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3017 **/
James Smart09372822008-01-11 01:52:54 -05003018static int
James Smart87af33f2007-10-27 13:37:43 -04003019lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3020{
3021 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3022 kfree(buf_ptr);
3023 return 0;
3024}
3025
James Smarte59058c2008-08-24 21:49:00 -04003026/**
James Smart3621a712009-04-06 18:47:14 -04003027 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003028 * @phba: pointer to lpfc hba data structure.
3029 * @elsiocb: pointer to lpfc els command iocb data structure.
3030 *
3031 * This routine frees a command IOCB and its associated resources. The
3032 * command IOCB data structure contains the reference to various associated
3033 * resources, these fields must be set to NULL if the associated reference
3034 * not present:
3035 * context1 - reference to ndlp
3036 * context2 - reference to cmd
3037 * context2->next - reference to rsp
3038 * context3 - reference to bpl
3039 *
3040 * It first properly decrements the reference count held on ndlp for the
3041 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3042 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3043 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3044 * adds the DMA buffer the @phba data structure for the delayed release.
3045 * If reference to the Buffer Pointer List (BPL) is present, the
3046 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3047 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3048 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3049 *
3050 * Return code
3051 * 0 - Success (currently, always return 0)
3052 **/
James Smart87af33f2007-10-27 13:37:43 -04003053int
James Smart329f9bc2007-04-25 09:53:01 -04003054lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003055{
3056 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003057 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003058
James Smarta8adb832007-10-27 13:37:53 -04003059 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3060 if (ndlp) {
3061 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3062 lpfc_nlp_put(ndlp);
3063
3064 /* If the ndlp is not being used by another discovery
3065 * thread, free it.
3066 */
3067 if (!lpfc_nlp_not_used(ndlp)) {
3068 /* If ndlp is being used by another discovery
3069 * thread, just clear NLP_DEFER_RM
3070 */
3071 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3072 }
3073 }
3074 else
3075 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003076 elsiocb->context1 = NULL;
3077 }
dea31012005-04-17 16:05:31 -05003078 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3079 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003080 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3081 /* Firmware could still be in progress of DMAing
3082 * payload, so don't free data buffer till after
3083 * a hbeat.
3084 */
3085 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3086 buf_ptr = elsiocb->context2;
3087 elsiocb->context2 = NULL;
3088 if (buf_ptr) {
3089 buf_ptr1 = NULL;
3090 spin_lock_irq(&phba->hbalock);
3091 if (!list_empty(&buf_ptr->list)) {
3092 list_remove_head(&buf_ptr->list,
3093 buf_ptr1, struct lpfc_dmabuf,
3094 list);
3095 INIT_LIST_HEAD(&buf_ptr1->list);
3096 list_add_tail(&buf_ptr1->list,
3097 &phba->elsbuf);
3098 phba->elsbuf_cnt++;
3099 }
3100 INIT_LIST_HEAD(&buf_ptr->list);
3101 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3102 phba->elsbuf_cnt++;
3103 spin_unlock_irq(&phba->hbalock);
3104 }
3105 } else {
3106 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3107 lpfc_els_free_data(phba, buf_ptr1);
3108 }
dea31012005-04-17 16:05:31 -05003109 }
3110
3111 if (elsiocb->context3) {
3112 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003113 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003114 }
James Bottomley604a3e32005-10-29 10:28:33 -05003115 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003116 return 0;
3117}
3118
James Smarte59058c2008-08-24 21:49:00 -04003119/**
James Smart3621a712009-04-06 18:47:14 -04003120 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003121 * @phba: pointer to lpfc hba data structure.
3122 * @cmdiocb: pointer to lpfc command iocb data structure.
3123 * @rspiocb: pointer to lpfc response iocb data structure.
3124 *
3125 * This routine is the completion callback function to the Logout (LOGO)
3126 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3127 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3128 * release the ndlp if it has the last reference remaining (reference count
3129 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3130 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3131 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3132 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3133 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3134 * IOCB data structure.
3135 **/
dea31012005-04-17 16:05:31 -05003136static void
James Smart2e0fef82007-06-17 19:56:36 -05003137lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3138 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003139{
James Smart2e0fef82007-06-17 19:56:36 -05003140 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3141 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003142 IOCB_t *irsp;
3143
3144 irsp = &rspiocb->iocb;
3145 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3146 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3147 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003148 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003149 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3150 "0109 ACC to LOGO completes to NPort x%x "
3151 "Data: x%x x%x x%x\n",
3152 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3153 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003154
3155 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3156 /* NPort Recovery mode or node is just allocated */
3157 if (!lpfc_nlp_not_used(ndlp)) {
3158 /* If the ndlp is being used by another discovery
3159 * thread, just unregister the RPI.
3160 */
3161 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003162 } else {
3163 /* Indicate the node has already released, should
3164 * not reference to it from within lpfc_els_free_iocb.
3165 */
3166 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003167 }
dea31012005-04-17 16:05:31 -05003168 }
3169 lpfc_els_free_iocb(phba, cmdiocb);
3170 return;
3171}
3172
James Smarte59058c2008-08-24 21:49:00 -04003173/**
James Smart3621a712009-04-06 18:47:14 -04003174 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003175 * @phba: pointer to lpfc hba data structure.
3176 * @pmb: pointer to the driver internal queue element for mailbox command.
3177 *
3178 * This routine is the completion callback function for unregister default
3179 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3180 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3181 * decrements the ndlp reference count held for this completion callback
3182 * function. After that, it invokes the lpfc_nlp_not_used() to check
3183 * whether there is only one reference left on the ndlp. If so, it will
3184 * perform one more decrement and trigger the release of the ndlp.
3185 **/
James Smart858c9f62007-06-17 19:56:39 -05003186void
3187lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3188{
3189 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3190 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3191
James Smart6fb120a2009-05-22 14:52:59 -04003192 /*
3193 * This routine is used to register and unregister in previous SLI
3194 * modes.
3195 */
3196 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3197 (phba->sli_rev == LPFC_SLI_REV4))
3198 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3199
James Smart858c9f62007-06-17 19:56:39 -05003200 pmb->context1 = NULL;
3201 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3202 kfree(mp);
3203 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003204 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003205 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003206 /* This is the end of the default RPI cleanup logic for this
3207 * ndlp. If no other discovery threads are using this ndlp.
3208 * we should free all resources associated with it.
3209 */
3210 lpfc_nlp_not_used(ndlp);
3211 }
James Smart3772a992009-05-22 14:50:54 -04003212
James Smart858c9f62007-06-17 19:56:39 -05003213 return;
3214}
3215
James Smarte59058c2008-08-24 21:49:00 -04003216/**
James Smart3621a712009-04-06 18:47:14 -04003217 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003218 * @phba: pointer to lpfc hba data structure.
3219 * @cmdiocb: pointer to lpfc command iocb data structure.
3220 * @rspiocb: pointer to lpfc response iocb data structure.
3221 *
3222 * This routine is the completion callback function for ELS Response IOCB
3223 * command. In normal case, this callback function just properly sets the
3224 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3225 * field in the command IOCB is not NULL, the referred mailbox command will
3226 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3227 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3228 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3229 * routine shall be invoked trying to release the ndlp if no other threads
3230 * are currently referring it.
3231 **/
dea31012005-04-17 16:05:31 -05003232static void
James Smart858c9f62007-06-17 19:56:39 -05003233lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003234 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003235{
James Smart2e0fef82007-06-17 19:56:36 -05003236 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3237 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3238 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003239 IOCB_t *irsp;
3240 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003241 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003242 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003243 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003244
James Smart33ccf8d2006-08-17 11:57:58 -04003245 irsp = &rspiocb->iocb;
3246
dea31012005-04-17 16:05:31 -05003247 if (cmdiocb->context_un.mbox)
3248 mbox = cmdiocb->context_un.mbox;
3249
James Smartfa4066b2008-01-11 01:53:27 -05003250 /* First determine if this is a LS_RJT cmpl. Note, this callback
3251 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3252 */
James Smart87af33f2007-10-27 13:37:43 -04003253 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003254 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3255 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003256 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003257 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003258 */
3259 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3260 ls_rjt = 1;
3261 }
3262
dea31012005-04-17 16:05:31 -05003263 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003264 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003265 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003266 mp = (struct lpfc_dmabuf *) mbox->context1;
3267 if (mp) {
3268 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3269 kfree(mp);
3270 }
James Smart329f9bc2007-04-25 09:53:01 -04003271 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003272 }
James Smart58da1ff2008-04-07 10:15:56 -04003273 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3274 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003275 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003276 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003277 /* Indicate the node has already released,
3278 * should not reference to it from within
3279 * the routine lpfc_els_free_iocb.
3280 */
3281 cmdiocb->context1 = NULL;
3282 }
dea31012005-04-17 16:05:31 -05003283 goto out;
3284 }
3285
James Smart858c9f62007-06-17 19:56:39 -05003286 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003287 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003288 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003289 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003290 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003291 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3292 "0110 ELS response tag x%x completes "
3293 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3294 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3295 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3296 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3297 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003298 if (mbox) {
3299 if ((rspiocb->iocb.ulpStatus == 0)
3300 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003301 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003302 /* Increment reference count to ndlp to hold the
3303 * reference to ndlp for the callback function.
3304 */
James Smart329f9bc2007-04-25 09:53:01 -04003305 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003306 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003307 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3308 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3309 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3310 }
3311 else {
3312 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3313 ndlp->nlp_prev_state = ndlp->nlp_state;
3314 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003315 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003316 }
James Smart0b727fe2007-10-27 13:37:25 -04003317 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003318 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003319 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003320 else
3321 /* Decrement the ndlp reference count we
3322 * set for this failed mailbox command.
3323 */
3324 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003325
3326 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3327 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3328 "0138 ELS rsp: Cannot issue reg_login for x%x "
3329 "Data: x%x x%x x%x\n",
3330 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3331 ndlp->nlp_rpi);
3332
James Smartfa4066b2008-01-11 01:53:27 -05003333 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003334 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003335 /* Indicate node has already been released,
3336 * should not reference to it from within
3337 * the routine lpfc_els_free_iocb.
3338 */
3339 cmdiocb->context1 = NULL;
3340 }
dea31012005-04-17 16:05:31 -05003341 } else {
James Smart858c9f62007-06-17 19:56:39 -05003342 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3343 if (!lpfc_error_lost_link(irsp) &&
3344 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003345 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003346 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003347 /* Indicate node has already been
3348 * released, should not reference
3349 * to it from within the routine
3350 * lpfc_els_free_iocb.
3351 */
3352 cmdiocb->context1 = NULL;
3353 }
dea31012005-04-17 16:05:31 -05003354 }
3355 }
James Smart14691152006-12-02 13:34:28 -05003356 mp = (struct lpfc_dmabuf *) mbox->context1;
3357 if (mp) {
3358 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3359 kfree(mp);
3360 }
3361 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003362 }
3363out:
James Smart58da1ff2008-04-07 10:15:56 -04003364 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003365 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003366 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003367 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003368
3369 /* If the node is not being used by another discovery thread,
3370 * and we are sending a reject, we are done with it.
3371 * Release driver reference count here and free associated
3372 * resources.
3373 */
3374 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003375 if (lpfc_nlp_not_used(ndlp))
3376 /* Indicate node has already been released,
3377 * should not reference to it from within
3378 * the routine lpfc_els_free_iocb.
3379 */
3380 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003381 }
James Smart87af33f2007-10-27 13:37:43 -04003382
dea31012005-04-17 16:05:31 -05003383 lpfc_els_free_iocb(phba, cmdiocb);
3384 return;
3385}
3386
James Smarte59058c2008-08-24 21:49:00 -04003387/**
James Smart3621a712009-04-06 18:47:14 -04003388 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003389 * @vport: pointer to a host virtual N_Port data structure.
3390 * @flag: the els command code to be accepted.
3391 * @oldiocb: pointer to the original lpfc command iocb data structure.
3392 * @ndlp: pointer to a node-list data structure.
3393 * @mbox: pointer to the driver internal queue element for mailbox command.
3394 *
3395 * This routine prepares and issues an Accept (ACC) response IOCB
3396 * command. It uses the @flag to properly set up the IOCB field for the
3397 * specific ACC response command to be issued and invokes the
3398 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3399 * @mbox pointer is passed in, it will be put into the context_un.mbox
3400 * field of the IOCB for the completion callback function to issue the
3401 * mailbox command to the HBA later when callback is invoked.
3402 *
3403 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3404 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3405 * will be stored into the context1 field of the IOCB for the completion
3406 * callback function to the corresponding response ELS IOCB command.
3407 *
3408 * Return code
3409 * 0 - Successfully issued acc response
3410 * 1 - Failed to issue acc response
3411 **/
dea31012005-04-17 16:05:31 -05003412int
James Smart2e0fef82007-06-17 19:56:36 -05003413lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3414 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003415 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003416{
James Smart2e0fef82007-06-17 19:56:36 -05003417 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3418 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003419 IOCB_t *icmd;
3420 IOCB_t *oldcmd;
3421 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003422 struct lpfc_sli *psli;
3423 uint8_t *pcmd;
3424 uint16_t cmdsize;
3425 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003426 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003427
3428 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003429 oldcmd = &oldiocb->iocb;
3430
3431 switch (flag) {
3432 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003433 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003434 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3435 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003436 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003437 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003438 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003439 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003440 return 1;
dea31012005-04-17 16:05:31 -05003441 }
James Smart2e0fef82007-06-17 19:56:36 -05003442
dea31012005-04-17 16:05:31 -05003443 icmd = &elsiocb->iocb;
3444 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3445 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3446 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003447 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003448
3449 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3450 "Issue ACC: did:x%x flg:x%x",
3451 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003452 break;
3453 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003454 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003455 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3456 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003457 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003458 return 1;
James Smart488d1462006-03-07 15:02:37 -05003459
dea31012005-04-17 16:05:31 -05003460 icmd = &elsiocb->iocb;
3461 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3462 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3463
3464 if (mbox)
3465 elsiocb->context_un.mbox = mbox;
3466
3467 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003468 pcmd += sizeof(uint32_t);
3469 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003470
3471 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3472 "Issue ACC PLOGI: did:x%x flg:x%x",
3473 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003474 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003475 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003476 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003477 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003478 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3479 if (!elsiocb)
3480 return 1;
3481
3482 icmd = &elsiocb->iocb;
3483 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3484 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3485
3486 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003487 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003488 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3489 els_pkt_ptr = (ELS_PKT *) pcmd;
3490 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003491
3492 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3493 "Issue ACC PRLO: did:x%x flg:x%x",
3494 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003495 break;
dea31012005-04-17 16:05:31 -05003496 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003497 return 1;
dea31012005-04-17 16:05:31 -05003498 }
dea31012005-04-17 16:05:31 -05003499 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003500 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3501 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3502 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3503 elsiocb->iotag, elsiocb->iocb.ulpContext,
3504 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3505 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003506 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003507 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003508 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003509 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003510 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3511 } else {
James Smart858c9f62007-06-17 19:56:39 -05003512 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003513 }
3514
3515 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003516 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003517 if (rc == IOCB_ERROR) {
3518 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003519 return 1;
dea31012005-04-17 16:05:31 -05003520 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003521 return 0;
dea31012005-04-17 16:05:31 -05003522}
3523
James Smarte59058c2008-08-24 21:49:00 -04003524/**
James Smart3621a712009-04-06 18:47:14 -04003525 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003526 * @vport: pointer to a virtual N_Port data structure.
3527 * @rejectError:
3528 * @oldiocb: pointer to the original lpfc command iocb data structure.
3529 * @ndlp: pointer to a node-list data structure.
3530 * @mbox: pointer to the driver internal queue element for mailbox command.
3531 *
3532 * This routine prepares and issue an Reject (RJT) response IOCB
3533 * command. If a @mbox pointer is passed in, it will be put into the
3534 * context_un.mbox field of the IOCB for the completion callback function
3535 * to issue to the HBA later.
3536 *
3537 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3538 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3539 * will be stored into the context1 field of the IOCB for the completion
3540 * callback function to the reject response ELS IOCB command.
3541 *
3542 * Return code
3543 * 0 - Successfully issued reject response
3544 * 1 - Failed to issue reject response
3545 **/
dea31012005-04-17 16:05:31 -05003546int
James Smart2e0fef82007-06-17 19:56:36 -05003547lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003548 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3549 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003550{
James Smart2e0fef82007-06-17 19:56:36 -05003551 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003552 IOCB_t *icmd;
3553 IOCB_t *oldcmd;
3554 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003555 struct lpfc_sli *psli;
3556 uint8_t *pcmd;
3557 uint16_t cmdsize;
3558 int rc;
3559
3560 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003561 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003562 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3563 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003564 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003565 return 1;
dea31012005-04-17 16:05:31 -05003566
3567 icmd = &elsiocb->iocb;
3568 oldcmd = &oldiocb->iocb;
3569 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3570 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3571
3572 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003573 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003574 *((uint32_t *) (pcmd)) = rejectError;
3575
James Smart51ef4c22007-08-02 11:10:31 -04003576 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003577 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003578
dea31012005-04-17 16:05:31 -05003579 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003580 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3581 "0129 Xmit ELS RJT x%x response tag x%x "
3582 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3583 "rpi x%x\n",
3584 rejectError, elsiocb->iotag,
3585 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3586 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003587 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3588 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3589 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3590
dea31012005-04-17 16:05:31 -05003591 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003592 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003593 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003594
dea31012005-04-17 16:05:31 -05003595 if (rc == IOCB_ERROR) {
3596 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003597 return 1;
dea31012005-04-17 16:05:31 -05003598 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003599 return 0;
dea31012005-04-17 16:05:31 -05003600}
3601
James Smarte59058c2008-08-24 21:49:00 -04003602/**
James Smart3621a712009-04-06 18:47:14 -04003603 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003604 * @vport: pointer to a virtual N_Port data structure.
3605 * @oldiocb: pointer to the original lpfc command iocb data structure.
3606 * @ndlp: pointer to a node-list data structure.
3607 *
3608 * This routine prepares and issues an Accept (ACC) response to Address
3609 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3610 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3611 *
3612 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3613 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3614 * will be stored into the context1 field of the IOCB for the completion
3615 * callback function to the ADISC Accept response ELS IOCB command.
3616 *
3617 * Return code
3618 * 0 - Successfully issued acc adisc response
3619 * 1 - Failed to issue adisc acc response
3620 **/
dea31012005-04-17 16:05:31 -05003621int
James Smart2e0fef82007-06-17 19:56:36 -05003622lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3623 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003624{
James Smart2e0fef82007-06-17 19:56:36 -05003625 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003626 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003627 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003628 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003629 uint8_t *pcmd;
3630 uint16_t cmdsize;
3631 int rc;
3632
James Smart92d7f7b2007-06-17 19:56:38 -05003633 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003634 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3635 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003636 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003637 return 1;
dea31012005-04-17 16:05:31 -05003638
dea31012005-04-17 16:05:31 -05003639 icmd = &elsiocb->iocb;
3640 oldcmd = &oldiocb->iocb;
3641 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003642
3643 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003644 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3645 "0130 Xmit ADISC ACC response iotag x%x xri: "
3646 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3647 elsiocb->iotag, elsiocb->iocb.ulpContext,
3648 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3649 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003650 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3651
3652 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003653 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003654
3655 ap = (ADISC *) (pcmd);
3656 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003657 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3658 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003659 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003660
James Smart858c9f62007-06-17 19:56:39 -05003661 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3662 "Issue ACC ADISC: did:x%x flg:x%x",
3663 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3664
dea31012005-04-17 16:05:31 -05003665 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003666 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003667 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003668 if (rc == IOCB_ERROR) {
3669 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003670 return 1;
dea31012005-04-17 16:05:31 -05003671 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003672 return 0;
dea31012005-04-17 16:05:31 -05003673}
3674
James Smarte59058c2008-08-24 21:49:00 -04003675/**
James Smart3621a712009-04-06 18:47:14 -04003676 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003677 * @vport: pointer to a virtual N_Port data structure.
3678 * @oldiocb: pointer to the original lpfc command iocb data structure.
3679 * @ndlp: pointer to a node-list data structure.
3680 *
3681 * This routine prepares and issues an Accept (ACC) response to Process
3682 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3683 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3684 *
3685 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3686 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3687 * will be stored into the context1 field of the IOCB for the completion
3688 * callback function to the PRLI Accept response ELS IOCB command.
3689 *
3690 * Return code
3691 * 0 - Successfully issued acc prli response
3692 * 1 - Failed to issue acc prli response
3693 **/
dea31012005-04-17 16:05:31 -05003694int
James Smart2e0fef82007-06-17 19:56:36 -05003695lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003696 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003697{
James Smart2e0fef82007-06-17 19:56:36 -05003698 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003699 PRLI *npr;
3700 lpfc_vpd_t *vpd;
3701 IOCB_t *icmd;
3702 IOCB_t *oldcmd;
3703 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003704 struct lpfc_sli *psli;
3705 uint8_t *pcmd;
3706 uint16_t cmdsize;
3707 int rc;
3708
3709 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003710
James Smart92d7f7b2007-06-17 19:56:38 -05003711 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003712 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003713 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003714 if (!elsiocb)
3715 return 1;
dea31012005-04-17 16:05:31 -05003716
dea31012005-04-17 16:05:31 -05003717 icmd = &elsiocb->iocb;
3718 oldcmd = &oldiocb->iocb;
3719 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003720 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003721 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3722 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3723 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3724 elsiocb->iotag, elsiocb->iocb.ulpContext,
3725 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3726 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003727 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3728
3729 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003730 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003731
3732 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003733 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003734
3735 npr = (PRLI *) pcmd;
3736 vpd = &phba->vpd;
3737 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003738 * If the remote port is a target and our firmware version is 3.20 or
3739 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003740 */
James Smart0d2b6b82008-06-14 22:52:47 -04003741 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3742 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003743 npr->ConfmComplAllowed = 1;
3744 npr->Retry = 1;
3745 npr->TaskRetryIdReq = 1;
3746 }
3747
3748 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3749 npr->estabImagePair = 1;
3750 npr->readXferRdyDis = 1;
3751 npr->ConfmComplAllowed = 1;
3752
3753 npr->prliType = PRLI_FCP_TYPE;
3754 npr->initiatorFunc = 1;
3755
James Smart858c9f62007-06-17 19:56:39 -05003756 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3757 "Issue ACC PRLI: did:x%x flg:x%x",
3758 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3759
dea31012005-04-17 16:05:31 -05003760 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003761 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003762
James Smart3772a992009-05-22 14:50:54 -04003763 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003764 if (rc == IOCB_ERROR) {
3765 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003766 return 1;
dea31012005-04-17 16:05:31 -05003767 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003768 return 0;
dea31012005-04-17 16:05:31 -05003769}
3770
James Smarte59058c2008-08-24 21:49:00 -04003771/**
James Smart3621a712009-04-06 18:47:14 -04003772 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003773 * @vport: pointer to a virtual N_Port data structure.
3774 * @format: rnid command format.
3775 * @oldiocb: pointer to the original lpfc command iocb data structure.
3776 * @ndlp: pointer to a node-list data structure.
3777 *
3778 * This routine issues a Request Node Identification Data (RNID) Accept
3779 * (ACC) response. It constructs the RNID ACC response command according to
3780 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3781 * issue the response. Note that this command does not need to hold the ndlp
3782 * reference count for the callback. So, the ndlp reference count taken by
3783 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3784 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3785 * there is no ndlp reference available.
3786 *
3787 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3788 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3789 * will be stored into the context1 field of the IOCB for the completion
3790 * callback function. However, for the RNID Accept Response ELS command,
3791 * this is undone later by this routine after the IOCB is allocated.
3792 *
3793 * Return code
3794 * 0 - Successfully issued acc rnid response
3795 * 1 - Failed to issue acc rnid response
3796 **/
dea31012005-04-17 16:05:31 -05003797static int
James Smart2e0fef82007-06-17 19:56:36 -05003798lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003799 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003800{
James Smart2e0fef82007-06-17 19:56:36 -05003801 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003802 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003803 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003804 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003805 struct lpfc_sli *psli;
3806 uint8_t *pcmd;
3807 uint16_t cmdsize;
3808 int rc;
3809
3810 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003811 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3812 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003813 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003814 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003815
James Smart2e0fef82007-06-17 19:56:36 -05003816 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3817 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003818 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003819 return 1;
dea31012005-04-17 16:05:31 -05003820
dea31012005-04-17 16:05:31 -05003821 icmd = &elsiocb->iocb;
3822 oldcmd = &oldiocb->iocb;
3823 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003824 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003825 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3826 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3827 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003828 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003829 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003830 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003831
James Smart92d7f7b2007-06-17 19:56:38 -05003832 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003833 rn = (RNID *) (pcmd);
3834 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003835 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3836 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3837 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003838 switch (format) {
3839 case 0:
3840 rn->SpecificLen = 0;
3841 break;
3842 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003843 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003844 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003845 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003846 rn->un.topologyDisc.unitType = RNID_HBA;
3847 rn->un.topologyDisc.physPort = 0;
3848 rn->un.topologyDisc.attachedNodes = 0;
3849 break;
3850 default:
3851 rn->CommonLen = 0;
3852 rn->SpecificLen = 0;
3853 break;
3854 }
3855
James Smart858c9f62007-06-17 19:56:39 -05003856 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3857 "Issue ACC RNID: did:x%x flg:x%x",
3858 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3859
dea31012005-04-17 16:05:31 -05003860 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003861 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003862 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003863 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3864 * it could be freed */
3865
James Smart3772a992009-05-22 14:50:54 -04003866 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003867 if (rc == IOCB_ERROR) {
3868 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003869 return 1;
dea31012005-04-17 16:05:31 -05003870 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003871 return 0;
dea31012005-04-17 16:05:31 -05003872}
3873
James Smarte59058c2008-08-24 21:49:00 -04003874/**
James Smart3621a712009-04-06 18:47:14 -04003875 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04003876 * @vport: pointer to a host virtual N_Port data structure.
3877 *
3878 * This routine issues Address Discover (ADISC) ELS commands to those
3879 * N_Ports which are in node port recovery state and ADISC has not been issued
3880 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3881 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3882 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3883 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3884 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3885 * IOCBs quit for later pick up. On the other hand, after walking through
3886 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3887 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3888 * no more ADISC need to be sent.
3889 *
3890 * Return code
3891 * The number of N_Ports with adisc issued.
3892 **/
dea31012005-04-17 16:05:31 -05003893int
James Smart2e0fef82007-06-17 19:56:36 -05003894lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003895{
James Smart2e0fef82007-06-17 19:56:36 -05003896 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003897 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003898 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003899
James Smart685f0bf2007-04-25 09:53:08 -04003900 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05003901 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003902 if (!NLP_CHK_NODE_ACT(ndlp))
3903 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003904 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3905 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3906 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003907 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003908 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05003909 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003910 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003911 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3912 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003913 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05003914 vport->num_disc_nodes++;
3915 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003916 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003917 spin_lock_irq(shost->host_lock);
3918 vport->fc_flag |= FC_NLP_MORE;
3919 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003920 break;
dea31012005-04-17 16:05:31 -05003921 }
3922 }
3923 }
3924 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003925 spin_lock_irq(shost->host_lock);
3926 vport->fc_flag &= ~FC_NLP_MORE;
3927 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003928 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003929 return sentadisc;
dea31012005-04-17 16:05:31 -05003930}
3931
James Smarte59058c2008-08-24 21:49:00 -04003932/**
James Smart3621a712009-04-06 18:47:14 -04003933 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04003934 * @vport: pointer to a host virtual N_Port data structure.
3935 *
3936 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3937 * which are in node port recovery state, with a @vport. Each time an ELS
3938 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3939 * the per @vport number of discover count (num_disc_nodes) shall be
3940 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3941 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3942 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3943 * later pick up. On the other hand, after walking through all the ndlps with
3944 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3945 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3946 * PLOGI need to be sent.
3947 *
3948 * Return code
3949 * The number of N_Ports with plogi issued.
3950 **/
dea31012005-04-17 16:05:31 -05003951int
James Smart2e0fef82007-06-17 19:56:36 -05003952lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003953{
James Smart2e0fef82007-06-17 19:56:36 -05003954 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003955 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003956 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05003957
James Smart2e0fef82007-06-17 19:56:36 -05003958 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3959 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003960 if (!NLP_CHK_NODE_ACT(ndlp))
3961 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003962 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3963 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3964 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
3965 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
3966 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003967 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3968 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003969 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05003970 vport->num_disc_nodes++;
3971 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003972 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003973 spin_lock_irq(shost->host_lock);
3974 vport->fc_flag |= FC_NLP_MORE;
3975 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003976 break;
dea31012005-04-17 16:05:31 -05003977 }
3978 }
3979 }
James Smart87af33f2007-10-27 13:37:43 -04003980 if (sentplogi) {
3981 lpfc_set_disctmo(vport);
3982 }
3983 else {
James Smart2e0fef82007-06-17 19:56:36 -05003984 spin_lock_irq(shost->host_lock);
3985 vport->fc_flag &= ~FC_NLP_MORE;
3986 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003987 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003988 return sentplogi;
dea31012005-04-17 16:05:31 -05003989}
3990
James Smarte59058c2008-08-24 21:49:00 -04003991/**
James Smart3621a712009-04-06 18:47:14 -04003992 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04003993 * @vport: pointer to a host virtual N_Port data structure.
3994 *
3995 * This routine cleans up any Registration State Change Notification
3996 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3997 * @vport together with the host_lock is used to prevent multiple thread
3998 * trying to access the RSCN array on a same @vport at the same time.
3999 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004000void
James Smart2e0fef82007-06-17 19:56:36 -05004001lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004002{
James Smart2e0fef82007-06-17 19:56:36 -05004003 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4004 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004005 int i;
4006
James Smart7f5f3d02008-02-08 18:50:14 -05004007 spin_lock_irq(shost->host_lock);
4008 if (vport->fc_rscn_flush) {
4009 /* Another thread is walking fc_rscn_id_list on this vport */
4010 spin_unlock_irq(shost->host_lock);
4011 return;
4012 }
4013 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4014 vport->fc_rscn_flush = 1;
4015 spin_unlock_irq(shost->host_lock);
4016
James Smart2e0fef82007-06-17 19:56:36 -05004017 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004018 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004019 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004020 }
James Smart2e0fef82007-06-17 19:56:36 -05004021 spin_lock_irq(shost->host_lock);
4022 vport->fc_rscn_id_cnt = 0;
4023 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4024 spin_unlock_irq(shost->host_lock);
4025 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004026 /* Indicate we are done walking this fc_rscn_id_list */
4027 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004028}
4029
James Smarte59058c2008-08-24 21:49:00 -04004030/**
James Smart3621a712009-04-06 18:47:14 -04004031 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004032 * @vport: pointer to a host virtual N_Port data structure.
4033 * @did: remote destination port identifier.
4034 *
4035 * This routine checks whether there is any pending Registration State
4036 * Configuration Notification (RSCN) to a @did on @vport.
4037 *
4038 * Return code
4039 * None zero - The @did matched with a pending rscn
4040 * 0 - not able to match @did with a pending rscn
4041 **/
dea31012005-04-17 16:05:31 -05004042int
James Smart2e0fef82007-06-17 19:56:36 -05004043lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004044{
4045 D_ID ns_did;
4046 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004047 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004048 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004049 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004050
4051 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004052
4053 /* Never match fabric nodes for RSCNs */
4054 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004055 return 0;
dea31012005-04-17 16:05:31 -05004056
4057 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004058 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004059 return did;
dea31012005-04-17 16:05:31 -05004060
James Smart7f5f3d02008-02-08 18:50:14 -05004061 spin_lock_irq(shost->host_lock);
4062 if (vport->fc_rscn_flush) {
4063 /* Another thread is walking fc_rscn_id_list on this vport */
4064 spin_unlock_irq(shost->host_lock);
4065 return 0;
4066 }
4067 /* Indicate we are walking fc_rscn_id_list on this vport */
4068 vport->fc_rscn_flush = 1;
4069 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004070 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004071 lp = vport->fc_rscn_id_list[i]->virt;
4072 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4073 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004074 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004075 rscn_did.un.word = be32_to_cpu(*lp++);
4076 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004077 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4078 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004079 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4080 && (ns_did.un.b.area == rscn_did.un.b.area)
4081 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004082 goto return_did_out;
dea31012005-04-17 16:05:31 -05004083 break;
James Smarteaf15d52008-12-04 22:39:29 -05004084 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004085 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4086 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004087 goto return_did_out;
dea31012005-04-17 16:05:31 -05004088 break;
James Smarteaf15d52008-12-04 22:39:29 -05004089 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004090 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004091 goto return_did_out;
dea31012005-04-17 16:05:31 -05004092 break;
James Smarteaf15d52008-12-04 22:39:29 -05004093 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004094 goto return_did_out;
dea31012005-04-17 16:05:31 -05004095 }
4096 }
James Smart92d7f7b2007-06-17 19:56:38 -05004097 }
James Smart7f5f3d02008-02-08 18:50:14 -05004098 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4099 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004100 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004101return_did_out:
4102 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4103 vport->fc_rscn_flush = 0;
4104 return did;
dea31012005-04-17 16:05:31 -05004105}
4106
James Smarte59058c2008-08-24 21:49:00 -04004107/**
James Smart3621a712009-04-06 18:47:14 -04004108 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004109 * @vport: pointer to a host virtual N_Port data structure.
4110 *
4111 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4112 * state machine for a @vport's nodes that are with pending RSCN (Registration
4113 * State Change Notification).
4114 *
4115 * Return code
4116 * 0 - Successful (currently alway return 0)
4117 **/
dea31012005-04-17 16:05:31 -05004118static int
James Smart2e0fef82007-06-17 19:56:36 -05004119lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004120{
James Smart685f0bf2007-04-25 09:53:08 -04004121 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004122
James Smart0d2b6b82008-06-14 22:52:47 -04004123 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004124 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004125 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004126 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4127 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004128 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004129 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004130 NLP_EVT_DEVICE_RECOVERY);
4131 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004132 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004133 return 0;
dea31012005-04-17 16:05:31 -05004134}
4135
James Smarte59058c2008-08-24 21:49:00 -04004136/**
James Smart3621a712009-04-06 18:47:14 -04004137 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004138 * @vport: pointer to a host virtual N_Port data structure.
4139 * @cmdiocb: pointer to lpfc command iocb data structure.
4140 *
4141 * lpfc_send_rscn_event sends an RSCN netlink event to management
4142 * applications.
4143 */
4144static void
4145lpfc_send_rscn_event(struct lpfc_vport *vport,
4146 struct lpfc_iocbq *cmdiocb)
4147{
4148 struct lpfc_dmabuf *pcmd;
4149 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4150 uint32_t *payload_ptr;
4151 uint32_t payload_len;
4152 struct lpfc_rscn_event_header *rscn_event_data;
4153
4154 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4155 payload_ptr = (uint32_t *) pcmd->virt;
4156 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4157
4158 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4159 payload_len, GFP_KERNEL);
4160 if (!rscn_event_data) {
4161 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4162 "0147 Failed to allocate memory for RSCN event\n");
4163 return;
4164 }
4165 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4166 rscn_event_data->payload_length = payload_len;
4167 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4168 payload_len);
4169
4170 fc_host_post_vendor_event(shost,
4171 fc_get_event_number(),
4172 sizeof(struct lpfc_els_event_header) + payload_len,
4173 (char *)rscn_event_data,
4174 LPFC_NL_VENDOR_ID);
4175
4176 kfree(rscn_event_data);
4177}
4178
4179/**
James Smart3621a712009-04-06 18:47:14 -04004180 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004181 * @vport: pointer to a host virtual N_Port data structure.
4182 * @cmdiocb: pointer to lpfc command iocb data structure.
4183 * @ndlp: pointer to a node-list data structure.
4184 *
4185 * This routine processes an unsolicited RSCN (Registration State Change
4186 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4187 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4188 * discover state machine is about to begin discovery, it just accepts the
4189 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4190 * contains N_Port IDs for other vports on this HBA, it just accepts the
4191 * RSCN and ignore processing it. If the state machine is in the recovery
4192 * state, the fc_rscn_id_list of this @vport is walked and the
4193 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4194 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4195 * routine is invoked to handle the RSCN event.
4196 *
4197 * Return code
4198 * 0 - Just sent the acc response
4199 * 1 - Sent the acc response and waited for name server completion
4200 **/
dea31012005-04-17 16:05:31 -05004201static int
James Smart2e0fef82007-06-17 19:56:36 -05004202lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004203 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004204{
James Smart2e0fef82007-06-17 19:56:36 -05004205 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4206 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004207 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004208 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004209 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004210 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004211 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004212 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004213 int i;
dea31012005-04-17 16:05:31 -05004214
4215 icmd = &cmdiocb->iocb;
4216 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4217 lp = (uint32_t *) pcmd->virt;
4218
James Smart92d7f7b2007-06-17 19:56:38 -05004219 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4220 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004221 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004222 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4223 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004224 vport->fc_flag, payload_len, *lp,
4225 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004226
4227 /* Send an RSCN event to the management application */
4228 lpfc_send_rscn_event(vport, cmdiocb);
4229
James Smartd2873e42006-08-18 17:46:43 -04004230 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004231 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004232 FCH_EVT_RSCN, lp[i]);
4233
dea31012005-04-17 16:05:31 -05004234 /* If we are about to begin discovery, just ACC the RSCN.
4235 * Discovery processing will satisfy it.
4236 */
James Smart2e0fef82007-06-17 19:56:36 -05004237 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004238 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4239 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4240 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4241
James Smart51ef4c22007-08-02 11:10:31 -04004242 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004243 return 0;
dea31012005-04-17 16:05:31 -05004244 }
4245
James Smart92d7f7b2007-06-17 19:56:38 -05004246 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4247 * just ACC and ignore it.
4248 */
4249 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004250 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004251 i = payload_len;
4252 datap = lp;
4253 while (i > 0) {
4254 nportid = *datap++;
4255 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4256 i -= sizeof(uint32_t);
4257 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004258 if (lpfc_find_vport_by_did(phba, nportid))
4259 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004260 }
4261 if (rscn_id == hba_id) {
4262 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004263 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004264 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004265 "Data: x%x x%x x%x x%x\n",
4266 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004267 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004268 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4269 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4270 ndlp->nlp_DID, vport->port_state,
4271 ndlp->nlp_flag);
4272
James Smart92d7f7b2007-06-17 19:56:38 -05004273 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004274 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004275 return 0;
4276 }
4277 }
4278
James Smart7f5f3d02008-02-08 18:50:14 -05004279 spin_lock_irq(shost->host_lock);
4280 if (vport->fc_rscn_flush) {
4281 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004282 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004283 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004284 /* Send back ACC */
4285 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004286 return 0;
4287 }
4288 /* Indicate we are walking fc_rscn_id_list on this vport */
4289 vport->fc_rscn_flush = 1;
4290 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004291 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004292 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004293 /* If we are already processing an RSCN, save the received
4294 * RSCN payload buffer, cmdiocb->context2 to process later.
4295 */
James Smart2e0fef82007-06-17 19:56:36 -05004296 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004297 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4298 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4299 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4300
James Smart09372822008-01-11 01:52:54 -05004301 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004302 vport->fc_flag |= FC_RSCN_DEFERRED;
4303 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004304 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004305 vport->fc_flag |= FC_RSCN_MODE;
4306 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004307 if (rscn_cnt) {
4308 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4309 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4310 }
4311 if ((rscn_cnt) &&
4312 (payload_len + length <= LPFC_BPL_SIZE)) {
4313 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004314 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004315 memcpy(((uint8_t *)cmd) + length, lp,
4316 payload_len);
4317 } else {
4318 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4319 vport->fc_rscn_id_cnt++;
4320 /* If we zero, cmdiocb->context2, the calling
4321 * routine will not try to free it.
4322 */
4323 cmdiocb->context2 = NULL;
4324 }
dea31012005-04-17 16:05:31 -05004325 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004326 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4327 "0235 Deferred RSCN "
4328 "Data: x%x x%x x%x\n",
4329 vport->fc_rscn_id_cnt, vport->fc_flag,
4330 vport->port_state);
dea31012005-04-17 16:05:31 -05004331 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004332 vport->fc_flag |= FC_RSCN_DISCOVERY;
4333 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004334 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004335 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4336 "0234 ReDiscovery RSCN "
4337 "Data: x%x x%x x%x\n",
4338 vport->fc_rscn_id_cnt, vport->fc_flag,
4339 vport->port_state);
dea31012005-04-17 16:05:31 -05004340 }
James Smart7f5f3d02008-02-08 18:50:14 -05004341 /* Indicate we are done walking fc_rscn_id_list on this vport */
4342 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004343 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004344 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004345 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004346 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004347 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004348 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004349 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004350 return 0;
dea31012005-04-17 16:05:31 -05004351 }
James Smart858c9f62007-06-17 19:56:39 -05004352 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4353 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4354 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4355
James Smart2e0fef82007-06-17 19:56:36 -05004356 spin_lock_irq(shost->host_lock);
4357 vport->fc_flag |= FC_RSCN_MODE;
4358 spin_unlock_irq(shost->host_lock);
4359 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004360 /* Indicate we are done walking fc_rscn_id_list on this vport */
4361 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004362 /*
4363 * If we zero, cmdiocb->context2, the calling routine will
4364 * not try to free it.
4365 */
4366 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004367 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004368 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004369 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004370 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004371 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004372 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004373}
4374
James Smarte59058c2008-08-24 21:49:00 -04004375/**
James Smart3621a712009-04-06 18:47:14 -04004376 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004377 * @vport: pointer to a host virtual N_Port data structure.
4378 *
4379 * This routine handles the Registration State Configuration Notification
4380 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4381 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4382 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4383 * NameServer shall be issued. If CT command to the NameServer fails to be
4384 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4385 * RSCN activities with the @vport.
4386 *
4387 * Return code
4388 * 0 - Cleaned up rscn on the @vport
4389 * 1 - Wait for plogi to name server before proceed
4390 **/
dea31012005-04-17 16:05:31 -05004391int
James Smart2e0fef82007-06-17 19:56:36 -05004392lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004393{
4394 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004395 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004396
James Smart92d7f7b2007-06-17 19:56:38 -05004397 /* Ignore RSCN if the port is being torn down. */
4398 if (vport->load_flag & FC_UNLOADING) {
4399 lpfc_els_flush_rscn(vport);
4400 return 0;
4401 }
4402
dea31012005-04-17 16:05:31 -05004403 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004404 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004405
4406 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004407 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4408 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4409 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4410 vport->port_state);
dea31012005-04-17 16:05:31 -05004411
4412 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004413 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004414 vport->num_disc_nodes = 0;
4415
James Smart2e0fef82007-06-17 19:56:36 -05004416 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004417 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4418 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004419 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004420 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004421 /* Wait for NameServer query cmpl before we can
4422 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004423 return 1;
dea31012005-04-17 16:05:31 -05004424 } else {
4425 /* If login to NameServer does not exist, issue one */
4426 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004427 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004428 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004429 /* Wait for NameServer login cmpl before we can
4430 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004431 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004432
James Smarte47c9092008-02-08 18:49:26 -05004433 if (ndlp) {
4434 ndlp = lpfc_enable_node(vport, ndlp,
4435 NLP_STE_PLOGI_ISSUE);
4436 if (!ndlp) {
4437 lpfc_els_flush_rscn(vport);
4438 return 0;
4439 }
4440 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004441 } else {
James Smarte47c9092008-02-08 18:49:26 -05004442 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4443 if (!ndlp) {
4444 lpfc_els_flush_rscn(vport);
4445 return 0;
4446 }
James Smart2e0fef82007-06-17 19:56:36 -05004447 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004448 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004449 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004450 }
James Smarte47c9092008-02-08 18:49:26 -05004451 ndlp->nlp_type |= NLP_FABRIC;
4452 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4453 /* Wait for NameServer login cmpl before we can
4454 * continue
4455 */
4456 return 1;
dea31012005-04-17 16:05:31 -05004457 }
4458
James Smart2e0fef82007-06-17 19:56:36 -05004459 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004460 return 0;
dea31012005-04-17 16:05:31 -05004461}
4462
James Smarte59058c2008-08-24 21:49:00 -04004463/**
James Smart3621a712009-04-06 18:47:14 -04004464 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004465 * @vport: pointer to a host virtual N_Port data structure.
4466 * @cmdiocb: pointer to lpfc command iocb data structure.
4467 * @ndlp: pointer to a node-list data structure.
4468 *
4469 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4470 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4471 * point topology. As an unsolicited FLOGI should not be received in a loop
4472 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4473 * lpfc_check_sparm() routine is invoked to check the parameters in the
4474 * unsolicited FLOGI. If parameters validation failed, the routine
4475 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4476 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4477 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4478 * will initiate PLOGI. The higher lexicographical value party shall has
4479 * higher priority (as the winning port) and will initiate PLOGI and
4480 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4481 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4482 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4483 *
4484 * Return code
4485 * 0 - Successfully processed the unsolicited flogi
4486 * 1 - Failed to process the unsolicited flogi
4487 **/
dea31012005-04-17 16:05:31 -05004488static int
James Smart2e0fef82007-06-17 19:56:36 -05004489lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004490 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004491{
James Smart2e0fef82007-06-17 19:56:36 -05004492 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4493 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004494 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4495 uint32_t *lp = (uint32_t *) pcmd->virt;
4496 IOCB_t *icmd = &cmdiocb->iocb;
4497 struct serv_parm *sp;
4498 LPFC_MBOXQ_t *mbox;
4499 struct ls_rjt stat;
4500 uint32_t cmd, did;
4501 int rc;
4502
4503 cmd = *lp++;
4504 sp = (struct serv_parm *) lp;
4505
4506 /* FLOGI received */
4507
James Smart2e0fef82007-06-17 19:56:36 -05004508 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004509
4510 if (phba->fc_topology == TOPOLOGY_LOOP) {
4511 /* We should never receive a FLOGI in loop mode, ignore it */
4512 did = icmd->un.elsreq64.remoteID;
4513
4514 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4515 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004516 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4517 "0113 An FLOGI ELS command x%x was "
4518 "received from DID x%x in Loop Mode\n",
4519 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004520 return 1;
dea31012005-04-17 16:05:31 -05004521 }
4522
4523 did = Fabric_DID;
4524
James Smart341af102010-01-26 23:07:37 -05004525 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004526 /* For a FLOGI we accept, then if our portname is greater
4527 * then the remote portname we initiate Nport login.
4528 */
4529
James Smart2e0fef82007-06-17 19:56:36 -05004530 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004531 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004532
4533 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004534 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4535 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004536 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004537
dea31012005-04-17 16:05:31 -05004538 lpfc_linkdown(phba);
4539 lpfc_init_link(phba, mbox,
4540 phba->cfg_topology,
4541 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004542 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004543 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004544 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004545 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004546 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004547 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004548 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004549 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004550 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004551 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004552 spin_lock_irq(shost->host_lock);
4553 vport->fc_flag |= FC_PT2PT_PLOGI;
4554 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004555 }
James Smart2e0fef82007-06-17 19:56:36 -05004556 spin_lock_irq(shost->host_lock);
4557 vport->fc_flag |= FC_PT2PT;
4558 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4559 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004560 } else {
4561 /* Reject this request because invalid parameters */
4562 stat.un.b.lsRjtRsvd0 = 0;
4563 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4564 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4565 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004566 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4567 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004568 return 1;
dea31012005-04-17 16:05:31 -05004569 }
4570
4571 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004572 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004573
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004574 return 0;
dea31012005-04-17 16:05:31 -05004575}
4576
James Smarte59058c2008-08-24 21:49:00 -04004577/**
James Smart3621a712009-04-06 18:47:14 -04004578 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004579 * @vport: pointer to a host virtual N_Port data structure.
4580 * @cmdiocb: pointer to lpfc command iocb data structure.
4581 * @ndlp: pointer to a node-list data structure.
4582 *
4583 * This routine processes Request Node Identification Data (RNID) IOCB
4584 * received as an ELS unsolicited event. Only when the RNID specified format
4585 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4586 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4587 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4588 * rejected by invoking the lpfc_els_rsp_reject() routine.
4589 *
4590 * Return code
4591 * 0 - Successfully processed rnid iocb (currently always return 0)
4592 **/
dea31012005-04-17 16:05:31 -05004593static int
James Smart2e0fef82007-06-17 19:56:36 -05004594lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4595 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004596{
4597 struct lpfc_dmabuf *pcmd;
4598 uint32_t *lp;
4599 IOCB_t *icmd;
4600 RNID *rn;
4601 struct ls_rjt stat;
4602 uint32_t cmd, did;
4603
4604 icmd = &cmdiocb->iocb;
4605 did = icmd->un.elsreq64.remoteID;
4606 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4607 lp = (uint32_t *) pcmd->virt;
4608
4609 cmd = *lp++;
4610 rn = (RNID *) lp;
4611
4612 /* RNID received */
4613
4614 switch (rn->Format) {
4615 case 0:
4616 case RNID_TOPOLOGY_DISC:
4617 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004618 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004619 break;
4620 default:
4621 /* Reject this request because format not supported */
4622 stat.un.b.lsRjtRsvd0 = 0;
4623 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4624 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4625 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004626 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4627 NULL);
dea31012005-04-17 16:05:31 -05004628 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004629 return 0;
dea31012005-04-17 16:05:31 -05004630}
4631
James Smarte59058c2008-08-24 21:49:00 -04004632/**
James Smart3621a712009-04-06 18:47:14 -04004633 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004634 * @vport: pointer to a host virtual N_Port data structure.
4635 * @cmdiocb: pointer to lpfc command iocb data structure.
4636 * @ndlp: pointer to a node-list data structure.
4637 *
4638 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4639 * received as an ELS unsolicited event. Currently, this function just invokes
4640 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4641 *
4642 * Return code
4643 * 0 - Successfully processed lirr iocb (currently always return 0)
4644 **/
dea31012005-04-17 16:05:31 -05004645static int
James Smart2e0fef82007-06-17 19:56:36 -05004646lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4647 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004648{
4649 struct ls_rjt stat;
4650
4651 /* For now, unconditionally reject this command */
4652 stat.un.b.lsRjtRsvd0 = 0;
4653 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4654 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4655 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004656 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004657 return 0;
4658}
4659
James Smarte59058c2008-08-24 21:49:00 -04004660/**
James Smart5ffc2662009-11-18 15:39:44 -05004661 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4662 * @vport: pointer to a host virtual N_Port data structure.
4663 * @cmdiocb: pointer to lpfc command iocb data structure.
4664 * @ndlp: pointer to a node-list data structure.
4665 *
4666 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4667 * received as an ELS unsolicited event. A request to RRQ shall only
4668 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4669 * Nx_Port N_Port_ID of the target Exchange is the same as the
4670 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4671 * not accepted, an LS_RJT with reason code "Unable to perform
4672 * command request" and reason code explanation "Invalid Originator
4673 * S_ID" shall be returned. For now, we just unconditionally accept
4674 * RRQ from the target.
4675 **/
4676static void
4677lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4678 struct lpfc_nodelist *ndlp)
4679{
4680 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4681}
4682
4683/**
James Smart3621a712009-04-06 18:47:14 -04004684 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004685 * @phba: pointer to lpfc hba data structure.
4686 * @pmb: pointer to the driver internal queue element for mailbox command.
4687 *
4688 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4689 * mailbox command. This callback function is to actually send the Accept
4690 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4691 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4692 * mailbox command, constructs the RPS response with the link statistics
4693 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4694 * response to the RPS.
4695 *
4696 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4697 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4698 * will be stored into the context1 field of the IOCB for the completion
4699 * callback function to the RPS Accept Response ELS IOCB command.
4700 *
4701 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004702static void
James Smart329f9bc2007-04-25 09:53:01 -04004703lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004704{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004705 MAILBOX_t *mb;
4706 IOCB_t *icmd;
4707 RPS_RSP *rps_rsp;
4708 uint8_t *pcmd;
4709 struct lpfc_iocbq *elsiocb;
4710 struct lpfc_nodelist *ndlp;
4711 uint16_t xri, status;
4712 uint32_t cmdsize;
4713
James Smart04c68492009-05-22 14:52:52 -04004714 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004715
4716 ndlp = (struct lpfc_nodelist *) pmb->context2;
4717 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004718 pmb->context1 = NULL;
4719 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004720
4721 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004722 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004723 return;
4724 }
4725
4726 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004727 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004728 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4729 lpfc_max_els_tries, ndlp,
4730 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004731
4732 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004733 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004734
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004735 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004736 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004737
4738 icmd = &elsiocb->iocb;
4739 icmd->ulpContext = xri;
4740
4741 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4742 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004743 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004744 rps_rsp = (RPS_RSP *)pcmd;
4745
4746 if (phba->fc_topology != TOPOLOGY_LOOP)
4747 status = 0x10;
4748 else
4749 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004750 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004751 status |= 0x4;
4752
4753 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004754 rps_rsp->portStatus = cpu_to_be16(status);
4755 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4756 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4757 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4758 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4759 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4760 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004761 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004762 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4763 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4764 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4765 elsiocb->iotag, elsiocb->iocb.ulpContext,
4766 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4767 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004768 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004769 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004770 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004771 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004772 return;
4773}
4774
James Smarte59058c2008-08-24 21:49:00 -04004775/**
James Smart3621a712009-04-06 18:47:14 -04004776 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04004777 * @vport: pointer to a host virtual N_Port data structure.
4778 * @cmdiocb: pointer to lpfc command iocb data structure.
4779 * @ndlp: pointer to a node-list data structure.
4780 *
4781 * This routine processes Read Port Status (RPS) IOCB received as an
4782 * ELS unsolicited event. It first checks the remote port state. If the
4783 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4784 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4785 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4786 * for reading the HBA link statistics. It is for the callback function,
4787 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4788 * to actually sending out RPS Accept (ACC) response.
4789 *
4790 * Return codes
4791 * 0 - Successfully processed rps iocb (currently always return 0)
4792 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004793static int
James Smart2e0fef82007-06-17 19:56:36 -05004794lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4795 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004796{
James Smart2e0fef82007-06-17 19:56:36 -05004797 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004798 uint32_t *lp;
4799 uint8_t flag;
4800 LPFC_MBOXQ_t *mbox;
4801 struct lpfc_dmabuf *pcmd;
4802 RPS *rps;
4803 struct ls_rjt stat;
4804
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004805 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04004806 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4807 /* reject the unsolicited RPS request and done with it */
4808 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004809
4810 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4811 lp = (uint32_t *) pcmd->virt;
4812 flag = (be32_to_cpu(*lp++) & 0xf);
4813 rps = (RPS *) lp;
4814
4815 if ((flag == 0) ||
4816 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05004817 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004818 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05004819
James Smart92d7f7b2007-06-17 19:56:38 -05004820 printk("Fix me....\n");
4821 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05004822 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4823 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004824 lpfc_read_lnk_stat(phba, mbox);
4825 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05004826 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04004827 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004828 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004829 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05004830 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04004831 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004832 /* Mbox completion will send ELS Response */
4833 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05004834 /* Decrement reference count used for the failed mbox
4835 * command.
4836 */
James Smart329f9bc2007-04-25 09:53:01 -04004837 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004838 mempool_free(mbox, phba->mbox_mem_pool);
4839 }
4840 }
James Smart90160e02008-08-24 21:49:45 -04004841
4842reject_out:
4843 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004844 stat.un.b.lsRjtRsvd0 = 0;
4845 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4846 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4847 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004848 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004849 return 0;
4850}
4851
James Smarte59058c2008-08-24 21:49:00 -04004852/**
James Smart3621a712009-04-06 18:47:14 -04004853 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04004854 * @vport: pointer to a host virtual N_Port data structure.
4855 * @cmdsize: size of the ELS command.
4856 * @oldiocb: pointer to the original lpfc command iocb data structure.
4857 * @ndlp: pointer to a node-list data structure.
4858 *
4859 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4860 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4861 *
4862 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4863 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4864 * will be stored into the context1 field of the IOCB for the completion
4865 * callback function to the RPL Accept Response ELS command.
4866 *
4867 * Return code
4868 * 0 - Successfully issued ACC RPL ELS command
4869 * 1 - Failed to issue ACC RPL ELS command
4870 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004871static int
James Smart2e0fef82007-06-17 19:56:36 -05004872lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4873 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004874{
James Smart2e0fef82007-06-17 19:56:36 -05004875 struct lpfc_hba *phba = vport->phba;
4876 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004877 RPL_RSP rpl_rsp;
4878 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004879 uint8_t *pcmd;
4880
James Smart2e0fef82007-06-17 19:56:36 -05004881 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4882 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004883
James Smart488d1462006-03-07 15:02:37 -05004884 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004885 return 1;
James Smart488d1462006-03-07 15:02:37 -05004886
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004887 icmd = &elsiocb->iocb;
4888 oldcmd = &oldiocb->iocb;
4889 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4890
4891 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4892 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004893 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004894 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4895 pcmd += sizeof(uint16_t);
4896
4897 /* Setup the RPL ACC payload */
4898 rpl_rsp.listLen = be32_to_cpu(1);
4899 rpl_rsp.index = 0;
4900 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004901 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4902 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004903 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004904 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004905 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004906 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4907 "0120 Xmit ELS RPL ACC response tag x%x "
4908 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4909 "rpi x%x\n",
4910 elsiocb->iotag, elsiocb->iocb.ulpContext,
4911 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4912 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004913 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004914 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004915 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
4916 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004917 lpfc_els_free_iocb(phba, elsiocb);
4918 return 1;
4919 }
4920 return 0;
4921}
4922
James Smarte59058c2008-08-24 21:49:00 -04004923/**
James Smart3621a712009-04-06 18:47:14 -04004924 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04004925 * @vport: pointer to a host virtual N_Port data structure.
4926 * @cmdiocb: pointer to lpfc command iocb data structure.
4927 * @ndlp: pointer to a node-list data structure.
4928 *
4929 * This routine processes Read Port List (RPL) IOCB received as an ELS
4930 * unsolicited event. It first checks the remote port state. If the remote
4931 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4932 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4933 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4934 * to accept the RPL.
4935 *
4936 * Return code
4937 * 0 - Successfully processed rpl iocb (currently always return 0)
4938 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004939static int
James Smart2e0fef82007-06-17 19:56:36 -05004940lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4941 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004942{
4943 struct lpfc_dmabuf *pcmd;
4944 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004945 uint32_t maxsize;
4946 uint16_t cmdsize;
4947 RPL *rpl;
4948 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05004949
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004950 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4951 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04004952 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004953 stat.un.b.lsRjtRsvd0 = 0;
4954 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4955 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4956 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004957 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4958 NULL);
James Smart90160e02008-08-24 21:49:45 -04004959 /* rejected the unsolicited RPL request and done with it */
4960 return 0;
dea31012005-04-17 16:05:31 -05004961 }
4962
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004963 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4964 lp = (uint32_t *) pcmd->virt;
4965 rpl = (RPL *) (lp + 1);
4966
4967 maxsize = be32_to_cpu(rpl->maxsize);
4968
4969 /* We support only one port */
4970 if ((rpl->index == 0) &&
4971 ((maxsize == 0) ||
4972 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
4973 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004974 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004975 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
4976 }
James Smart2e0fef82007-06-17 19:56:36 -05004977 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004978
4979 return 0;
4980}
4981
James Smarte59058c2008-08-24 21:49:00 -04004982/**
James Smart3621a712009-04-06 18:47:14 -04004983 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04004984 * @vport: pointer to a virtual N_Port data structure.
4985 * @cmdiocb: pointer to lpfc command iocb data structure.
4986 * @ndlp: pointer to a node-list data structure.
4987 *
4988 * This routine processes Fibre Channel Address Resolution Protocol
4989 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4990 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4991 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4992 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4993 * remote PortName is compared against the FC PortName stored in the @vport
4994 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4995 * compared against the FC NodeName stored in the @vport data structure.
4996 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4997 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4998 * invoked to send out FARP Response to the remote node. Before sending the
4999 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5000 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5001 * routine is invoked to log into the remote port first.
5002 *
5003 * Return code
5004 * 0 - Either the FARP Match Mode not supported or successfully processed
5005 **/
dea31012005-04-17 16:05:31 -05005006static int
James Smart2e0fef82007-06-17 19:56:36 -05005007lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5008 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005009{
5010 struct lpfc_dmabuf *pcmd;
5011 uint32_t *lp;
5012 IOCB_t *icmd;
5013 FARP *fp;
5014 uint32_t cmd, cnt, did;
5015
5016 icmd = &cmdiocb->iocb;
5017 did = icmd->un.elsreq64.remoteID;
5018 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5019 lp = (uint32_t *) pcmd->virt;
5020
5021 cmd = *lp++;
5022 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005023 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005024 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5025 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005026 /* We will only support match on WWPN or WWNN */
5027 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005028 return 0;
dea31012005-04-17 16:05:31 -05005029 }
5030
5031 cnt = 0;
5032 /* If this FARP command is searching for my portname */
5033 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005034 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005035 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005036 cnt = 1;
5037 }
5038
5039 /* If this FARP command is searching for my nodename */
5040 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005041 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005042 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005043 cnt = 1;
5044 }
5045
5046 if (cnt) {
5047 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5048 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5049 /* Log back into the node before sending the FARP. */
5050 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005051 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005052 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005053 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005054 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005055 }
5056
5057 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005058 if (fp->Rflags & FARP_REQUEST_FARPR)
5059 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005060 }
5061 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005062 return 0;
dea31012005-04-17 16:05:31 -05005063}
5064
James Smarte59058c2008-08-24 21:49:00 -04005065/**
James Smart3621a712009-04-06 18:47:14 -04005066 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005067 * @vport: pointer to a host virtual N_Port data structure.
5068 * @cmdiocb: pointer to lpfc command iocb data structure.
5069 * @ndlp: pointer to a node-list data structure.
5070 *
5071 * This routine processes Fibre Channel Address Resolution Protocol
5072 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5073 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5074 * the FARP response request.
5075 *
5076 * Return code
5077 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5078 **/
dea31012005-04-17 16:05:31 -05005079static int
James Smart2e0fef82007-06-17 19:56:36 -05005080lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5081 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005082{
5083 struct lpfc_dmabuf *pcmd;
5084 uint32_t *lp;
5085 IOCB_t *icmd;
5086 uint32_t cmd, did;
5087
5088 icmd = &cmdiocb->iocb;
5089 did = icmd->un.elsreq64.remoteID;
5090 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5091 lp = (uint32_t *) pcmd->virt;
5092
5093 cmd = *lp++;
5094 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005095 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5096 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005097 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005098 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005099
5100 return 0;
5101}
5102
James Smarte59058c2008-08-24 21:49:00 -04005103/**
James Smart3621a712009-04-06 18:47:14 -04005104 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005105 * @vport: pointer to a host virtual N_Port data structure.
5106 * @cmdiocb: pointer to lpfc command iocb data structure.
5107 * @fan_ndlp: pointer to a node-list data structure.
5108 *
5109 * This routine processes a Fabric Address Notification (FAN) IOCB
5110 * command received as an ELS unsolicited event. The FAN ELS command will
5111 * only be processed on a physical port (i.e., the @vport represents the
5112 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5113 * compared against those in the phba data structure. If any of those is
5114 * different, the lpfc_initial_flogi() routine is invoked to initialize
5115 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5116 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5117 * is invoked to register login to the fabric.
5118 *
5119 * Return code
5120 * 0 - Successfully processed fan iocb (currently always return 0).
5121 **/
dea31012005-04-17 16:05:31 -05005122static int
James Smart2e0fef82007-06-17 19:56:36 -05005123lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5124 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005125{
James Smart2e0fef82007-06-17 19:56:36 -05005126 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005127 uint32_t *lp;
5128 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005129
James Smart0d2b6b82008-06-14 22:52:47 -04005130 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5131 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5132 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005133 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005134 if ((vport == phba->pport) &&
5135 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005136 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005137 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005138 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005139 sizeof(struct lpfc_name)))) {
5140 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05005141 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005142 } else {
5143 /* FAN verified - skip FLOGI */
5144 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005145 if (phba->sli_rev < LPFC_SLI_REV4)
5146 lpfc_issue_fabric_reglogin(vport);
5147 else
5148 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005149 }
dea31012005-04-17 16:05:31 -05005150 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005151 return 0;
dea31012005-04-17 16:05:31 -05005152}
5153
James Smarte59058c2008-08-24 21:49:00 -04005154/**
James Smart3621a712009-04-06 18:47:14 -04005155 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005156 * @ptr: holder for the timer function associated data.
5157 *
5158 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5159 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5160 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5161 * up the worker thread. It is for the worker thread to invoke the routine
5162 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5163 **/
dea31012005-04-17 16:05:31 -05005164void
5165lpfc_els_timeout(unsigned long ptr)
5166{
James Smart2e0fef82007-06-17 19:56:36 -05005167 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5168 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005169 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005170 unsigned long iflag;
5171
James Smart2e0fef82007-06-17 19:56:36 -05005172 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005173 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5174 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005175 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005176 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005177
James Smart5e9d9b82008-06-14 22:52:53 -04005178 if (!tmo_posted)
5179 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005180 return;
5181}
5182
James Smart2a9bf3d2010-06-07 15:24:45 -04005183
James Smarte59058c2008-08-24 21:49:00 -04005184/**
James Smart3621a712009-04-06 18:47:14 -04005185 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005186 * @vport: pointer to a virtual N_Port data structure.
5187 *
5188 * This routine is the actual handler function that processes an ELS timeout
5189 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5190 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5191 * invoking the lpfc_sli_issue_abort_iotag() routine.
5192 **/
dea31012005-04-17 16:05:31 -05005193void
James Smart2e0fef82007-06-17 19:56:36 -05005194lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005195{
James Smart2e0fef82007-06-17 19:56:36 -05005196 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005197 struct lpfc_sli_ring *pring;
5198 struct lpfc_iocbq *tmp_iocb, *piocb;
5199 IOCB_t *cmd = NULL;
5200 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005201 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005202 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005203 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005204 LIST_HEAD(txcmplq_completions);
5205 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005206
James Smart2a9bf3d2010-06-07 15:24:45 -04005207
dea31012005-04-17 16:05:31 -05005208 timeout = (uint32_t)(phba->fc_ratov << 1);
5209
5210 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005211
James Smart2a9bf3d2010-06-07 15:24:45 -04005212 spin_lock_irq(&phba->hbalock);
5213 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5214 spin_unlock_irq(&phba->hbalock);
5215
5216 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005217 cmd = &piocb->iocb;
5218
James Smart2e0fef82007-06-17 19:56:36 -05005219 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5220 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5221 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005222 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005223
5224 if (piocb->vport != vport)
5225 continue;
5226
dea31012005-04-17 16:05:31 -05005227 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005228 if (pcmd)
5229 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005230
James Smart92d7f7b2007-06-17 19:56:38 -05005231 if (els_command == ELS_CMD_FARP ||
5232 els_command == ELS_CMD_FARPR ||
5233 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005234 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005235
dea31012005-04-17 16:05:31 -05005236 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005237 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005238 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005239 else
dea31012005-04-17 16:05:31 -05005240 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005241 continue;
5242 }
5243
James Smart2e0fef82007-06-17 19:56:36 -05005244 remote_ID = 0xffffffff;
5245 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005246 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005247 else {
5248 struct lpfc_nodelist *ndlp;
5249 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005250 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005251 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005252 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005253 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05005254 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005255 spin_lock_irq(&phba->hbalock);
5256 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05005257 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005258
James Smart2a9bf3d2010-06-07 15:24:45 -04005259 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5260 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5261 "0127 ELS timeout Data: x%x x%x x%x "
5262 "x%x\n", els_command,
5263 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5264 spin_lock_irq(&phba->hbalock);
5265 list_del_init(&piocb->dlist);
5266 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5267 spin_unlock_irq(&phba->hbalock);
5268 }
5269
James Smart2e0fef82007-06-17 19:56:36 -05005270 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5271 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005272}
5273
James Smarte59058c2008-08-24 21:49:00 -04005274/**
James Smart3621a712009-04-06 18:47:14 -04005275 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005276 * @vport: pointer to a host virtual N_Port data structure.
5277 *
5278 * This routine is used to clean up all the outstanding ELS commands on a
5279 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5280 * routine. After that, it walks the ELS transmit queue to remove all the
5281 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5282 * the IOCBs with a non-NULL completion callback function, the callback
5283 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5284 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5285 * callback function, the IOCB will simply be released. Finally, it walks
5286 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5287 * completion queue IOCB that is associated with the @vport and is not
5288 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5289 * part of the discovery state machine) out to HBA by invoking the
5290 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5291 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5292 * the IOCBs are aborted when this function returns.
5293 **/
dea31012005-04-17 16:05:31 -05005294void
James Smart2e0fef82007-06-17 19:56:36 -05005295lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005296{
James Smart2534ba72007-04-25 09:52:20 -04005297 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005298 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005299 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005300 struct lpfc_iocbq *tmp_iocb, *piocb;
5301 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005302
5303 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005304
James Smart2e0fef82007-06-17 19:56:36 -05005305 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005306 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5307 cmd = &piocb->iocb;
5308
5309 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5310 continue;
5311 }
5312
5313 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005314 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5315 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5316 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5317 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005318 continue;
dea31012005-04-17 16:05:31 -05005319
James Smart2e0fef82007-06-17 19:56:36 -05005320 if (piocb->vport != vport)
5321 continue;
5322
James Smart2534ba72007-04-25 09:52:20 -04005323 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005324 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005325 }
5326
5327 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005328 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5329 continue;
5330 }
dea31012005-04-17 16:05:31 -05005331
James Smart2e0fef82007-06-17 19:56:36 -05005332 if (piocb->vport != vport)
5333 continue;
5334
James Smart07951072007-04-25 09:51:38 -04005335 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005336 }
James Smart2e0fef82007-06-17 19:56:36 -05005337 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005338
James Smarta257bf92009-04-06 18:48:10 -04005339 /* Cancell all the IOCBs from the completions list */
5340 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5341 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005342
dea31012005-04-17 16:05:31 -05005343 return;
5344}
5345
James Smarte59058c2008-08-24 21:49:00 -04005346/**
James Smart3621a712009-04-06 18:47:14 -04005347 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005348 * @phba: pointer to lpfc hba data structure.
5349 *
5350 * This routine is used to clean up all the outstanding ELS commands on a
5351 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5352 * routine. After that, it walks the ELS transmit queue to remove all the
5353 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5354 * the IOCBs with the completion callback function associated, the callback
5355 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5356 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5357 * callback function associated, the IOCB will simply be released. Finally,
5358 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5359 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5360 * management plane IOCBs that are not part of the discovery state machine)
5361 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5362 **/
James Smart549e55c2007-08-02 11:09:51 -04005363void
5364lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5365{
5366 LIST_HEAD(completions);
5367 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5368 struct lpfc_iocbq *tmp_iocb, *piocb;
5369 IOCB_t *cmd = NULL;
5370
5371 lpfc_fabric_abort_hba(phba);
5372 spin_lock_irq(&phba->hbalock);
5373 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5374 cmd = &piocb->iocb;
5375 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5376 continue;
5377 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5378 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5379 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5380 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5381 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5382 continue;
5383 list_move_tail(&piocb->list, &completions);
5384 pring->txq_cnt--;
5385 }
5386 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5387 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5388 continue;
5389 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5390 }
5391 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005392
5393 /* Cancel all the IOCBs from the completions list */
5394 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5395 IOERR_SLI_ABORTED);
5396
James Smart549e55c2007-08-02 11:09:51 -04005397 return;
5398}
5399
James Smarte59058c2008-08-24 21:49:00 -04005400/**
James Smart3621a712009-04-06 18:47:14 -04005401 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005402 * @phba: Pointer to hba context object.
5403 * @cmdiocbp: Pointer to command iocb which reported error.
5404 * @rspiocbp: Pointer to response iocb which reported error.
5405 *
5406 * This function sends an event when there is an ELS command
5407 * failure.
5408 **/
5409void
5410lpfc_send_els_failure_event(struct lpfc_hba *phba,
5411 struct lpfc_iocbq *cmdiocbp,
5412 struct lpfc_iocbq *rspiocbp)
5413{
5414 struct lpfc_vport *vport = cmdiocbp->vport;
5415 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5416 struct lpfc_lsrjt_event lsrjt_event;
5417 struct lpfc_fabric_event_header fabric_event;
5418 struct ls_rjt stat;
5419 struct lpfc_nodelist *ndlp;
5420 uint32_t *pcmd;
5421
5422 ndlp = cmdiocbp->context1;
5423 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5424 return;
5425
5426 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5427 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5428 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5429 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5430 sizeof(struct lpfc_name));
5431 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5432 sizeof(struct lpfc_name));
5433 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5434 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04005435 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04005436 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5437 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5438 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5439 fc_host_post_vendor_event(shost,
5440 fc_get_event_number(),
5441 sizeof(lsrjt_event),
5442 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005443 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005444 return;
5445 }
5446 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5447 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5448 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5449 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5450 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5451 else
5452 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5453 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5454 sizeof(struct lpfc_name));
5455 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5456 sizeof(struct lpfc_name));
5457 fc_host_post_vendor_event(shost,
5458 fc_get_event_number(),
5459 sizeof(fabric_event),
5460 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005461 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005462 return;
5463 }
5464
5465}
5466
5467/**
James Smart3621a712009-04-06 18:47:14 -04005468 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04005469 * @vport: Pointer to vport object.
5470 * @ndlp: Pointer FC node object.
5471 * @cmd: ELS command code.
5472 *
5473 * This function posts an event when there is an incoming
5474 * unsolicited ELS command.
5475 **/
5476static void
5477lpfc_send_els_event(struct lpfc_vport *vport,
5478 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005479 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005480{
James Smartddcc50f2008-12-04 22:38:46 -05005481 struct lpfc_els_event_header *els_data = NULL;
5482 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005483 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5484
James Smartddcc50f2008-12-04 22:38:46 -05005485 if (*payload == ELS_CMD_LOGO) {
5486 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5487 if (!logo_data) {
5488 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5489 "0148 Failed to allocate memory "
5490 "for LOGO event\n");
5491 return;
5492 }
5493 els_data = &logo_data->header;
5494 } else {
5495 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5496 GFP_KERNEL);
5497 if (!els_data) {
5498 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5499 "0149 Failed to allocate memory "
5500 "for ELS event\n");
5501 return;
5502 }
5503 }
5504 els_data->event_type = FC_REG_ELS_EVENT;
5505 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005506 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005507 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005508 break;
5509 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005510 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005511 break;
5512 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005513 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5514 break;
5515 case ELS_CMD_LOGO:
5516 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5517 /* Copy the WWPN in the LOGO payload */
5518 memcpy(logo_data->logo_wwpn, &payload[2],
5519 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005520 break;
5521 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005522 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005523 return;
5524 }
James Smartddcc50f2008-12-04 22:38:46 -05005525 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5526 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5527 if (*payload == ELS_CMD_LOGO) {
5528 fc_host_post_vendor_event(shost,
5529 fc_get_event_number(),
5530 sizeof(struct lpfc_logo_event),
5531 (char *)logo_data,
5532 LPFC_NL_VENDOR_ID);
5533 kfree(logo_data);
5534 } else {
5535 fc_host_post_vendor_event(shost,
5536 fc_get_event_number(),
5537 sizeof(struct lpfc_els_event_header),
5538 (char *)els_data,
5539 LPFC_NL_VENDOR_ID);
5540 kfree(els_data);
5541 }
James Smartea2151b2008-09-07 11:52:10 -04005542
5543 return;
5544}
5545
5546
5547/**
James Smart3621a712009-04-06 18:47:14 -04005548 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04005549 * @phba: pointer to lpfc hba data structure.
5550 * @pring: pointer to a SLI ring.
5551 * @vport: pointer to a host virtual N_Port data structure.
5552 * @elsiocb: pointer to lpfc els command iocb data structure.
5553 *
5554 * This routine is used for processing the IOCB associated with a unsolicited
5555 * event. It first determines whether there is an existing ndlp that matches
5556 * the DID from the unsolicited IOCB. If not, it will create a new one with
5557 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5558 * IOCB is then used to invoke the proper routine and to set up proper state
5559 * of the discovery state machine.
5560 **/
James Smarted957682007-06-17 19:56:37 -05005561static void
5562lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005563 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005564{
James Smart87af33f2007-10-27 13:37:43 -04005565 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005566 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005567 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005568 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005569 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005570 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005571
James Smarte47c9092008-02-08 18:49:26 -05005572 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005573 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005574
dea31012005-04-17 16:05:31 -05005575 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005576 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5577 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005578 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005579 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005580
James Smart858c9f62007-06-17 19:56:39 -05005581 did = icmd->un.rcvels.remoteID;
5582 if (icmd->ulpStatus) {
5583 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5584 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5585 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005586 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005587 }
dea31012005-04-17 16:05:31 -05005588
5589 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005590 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005591 goto dropit;
dea31012005-04-17 16:05:31 -05005592
James Smartc8685952009-11-18 15:39:16 -05005593 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05005594 if (vport->load_flag & FC_UNLOADING)
5595 goto dropit;
5596
James Smart2e0fef82007-06-17 19:56:36 -05005597 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005598 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005599 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005600 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005601 if (!ndlp)
dea31012005-04-17 16:05:31 -05005602 goto dropit;
dea31012005-04-17 16:05:31 -05005603
James Smart2e0fef82007-06-17 19:56:36 -05005604 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005605 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005606 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005607 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005608 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005609 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5610 ndlp = lpfc_enable_node(vport, ndlp,
5611 NLP_STE_UNUSED_NODE);
5612 if (!ndlp)
5613 goto dropit;
5614 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5615 newnode = 1;
5616 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5617 ndlp->nlp_type |= NLP_FABRIC;
5618 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5619 /* This is similar to the new node path */
5620 ndlp = lpfc_nlp_get(ndlp);
5621 if (!ndlp)
5622 goto dropit;
5623 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5624 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005625 }
dea31012005-04-17 16:05:31 -05005626
5627 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005628
James Smart329f9bc2007-04-25 09:53:01 -04005629 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005630 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005631
5632 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5633 cmd &= ELS_CMD_MASK;
5634 }
5635 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005636 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5637 "0112 ELS command x%x received from NPORT x%x "
5638 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005639 switch (cmd) {
5640 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005641 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5642 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5643 did, vport->port_state, ndlp->nlp_flag);
5644
dea31012005-04-17 16:05:31 -05005645 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005646 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5647
James Smartddcc50f2008-12-04 22:38:46 -05005648 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05005649 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05005650 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5651 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5652 rjt_err = LSRJT_UNABLE_TPC;
5653 break;
5654 }
5655 /* We get here, and drop thru, if we are PT2PT with
5656 * another NPort and the other side has initiated
5657 * the PLOGI before responding to our FLOGI.
5658 */
dea31012005-04-17 16:05:31 -05005659 }
James Smart87af33f2007-10-27 13:37:43 -04005660
5661 shost = lpfc_shost_from_vport(vport);
5662 spin_lock_irq(shost->host_lock);
5663 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5664 spin_unlock_irq(shost->host_lock);
5665
James Smart2e0fef82007-06-17 19:56:36 -05005666 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5667 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05005668
dea31012005-04-17 16:05:31 -05005669 break;
5670 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005671 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5672 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5673 did, vport->port_state, ndlp->nlp_flag);
5674
dea31012005-04-17 16:05:31 -05005675 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04005676 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005677 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005678 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005679 break;
5680 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05005681 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5682 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5683 did, vport->port_state, ndlp->nlp_flag);
5684
dea31012005-04-17 16:05:31 -05005685 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05005686 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005687 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005688 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005689 break;
5690 }
James Smart2e0fef82007-06-17 19:56:36 -05005691 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05005692 break;
5693 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05005694 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5695 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5696 did, vport->port_state, ndlp->nlp_flag);
5697
dea31012005-04-17 16:05:31 -05005698 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05005699 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005700 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005701 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005702 break;
5703 }
James Smart2e0fef82007-06-17 19:56:36 -05005704 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05005705 break;
5706 case ELS_CMD_RSCN:
5707 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04005708 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005709 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005710 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005711 break;
5712 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05005713 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5714 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5715 did, vport->port_state, ndlp->nlp_flag);
5716
James Smartddcc50f2008-12-04 22:38:46 -05005717 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05005718 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005719 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005720 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005721 break;
5722 }
James Smart2e0fef82007-06-17 19:56:36 -05005723 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5724 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05005725 break;
5726 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05005727 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5728 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5729 did, vport->port_state, ndlp->nlp_flag);
5730
dea31012005-04-17 16:05:31 -05005731 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005732 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005733 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005734 break;
5735 }
James Smart2e0fef82007-06-17 19:56:36 -05005736 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5737 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05005738 break;
5739 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05005740 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5741 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5742 did, vport->port_state, ndlp->nlp_flag);
5743
dea31012005-04-17 16:05:31 -05005744 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05005745 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005746 break;
5747 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05005748 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5749 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5750 did, vport->port_state, ndlp->nlp_flag);
5751
dea31012005-04-17 16:05:31 -05005752 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05005753 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005754 break;
5755 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05005756 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5757 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5758 did, vport->port_state, ndlp->nlp_flag);
5759
dea31012005-04-17 16:05:31 -05005760 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05005761 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005762 break;
dea31012005-04-17 16:05:31 -05005763 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05005764 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5765 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5766 did, vport->port_state, ndlp->nlp_flag);
5767
dea31012005-04-17 16:05:31 -05005768 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05005769 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005770 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005771 break;
5772 }
James Smart2e0fef82007-06-17 19:56:36 -05005773 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05005774 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005775 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05005776 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5777 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5778 did, vport->port_state, ndlp->nlp_flag);
5779
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005780 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05005781 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005782 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005783 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005784 break;
5785 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05005786 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5787 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5788 did, vport->port_state, ndlp->nlp_flag);
5789
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005790 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05005791 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005792 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005793 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005794 break;
5795 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05005796 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5797 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5798 did, vport->port_state, ndlp->nlp_flag);
5799
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005800 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05005801 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005802 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005803 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005804 break;
dea31012005-04-17 16:05:31 -05005805 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05005806 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5807 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5808 did, vport->port_state, ndlp->nlp_flag);
5809
dea31012005-04-17 16:05:31 -05005810 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05005811 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005812 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005813 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005814 break;
James Smart5ffc2662009-11-18 15:39:44 -05005815 case ELS_CMD_RRQ:
5816 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5817 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
5818 did, vport->port_state, ndlp->nlp_flag);
5819
5820 phba->fc_stat.elsRcvRRQ++;
5821 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
5822 if (newnode)
5823 lpfc_nlp_put(ndlp);
5824 break;
dea31012005-04-17 16:05:31 -05005825 default:
James Smart858c9f62007-06-17 19:56:39 -05005826 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5827 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5828 cmd, did, vport->port_state);
5829
dea31012005-04-17 16:05:31 -05005830 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05005831 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05005832
5833 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005834 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5835 "0115 Unknown ELS command x%x "
5836 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04005837 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005838 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005839 break;
5840 }
5841
5842 /* check if need to LS_RJT received ELS cmd */
5843 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05005844 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05005845 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04005846 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05005847 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5848 NULL);
dea31012005-04-17 16:05:31 -05005849 }
5850
James Smartd7c255b2008-08-24 21:50:00 -04005851 lpfc_nlp_put(elsiocb->context1);
5852 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05005853 return;
5854
5855dropit:
James Smart98c9ea52007-10-27 13:37:33 -04005856 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04005857 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5858 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05005859 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04005860 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05005861 phba->fc_stat.elsRcvDrop++;
5862}
5863
James Smarte59058c2008-08-24 21:49:00 -04005864/**
James Smart3621a712009-04-06 18:47:14 -04005865 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04005866 * @phba: pointer to lpfc hba data structure.
5867 * @vpi: host virtual N_Port identifier.
5868 *
5869 * This routine finds a vport on a HBA (referred by @phba) through a
5870 * @vpi. The function walks the HBA's vport list and returns the address
5871 * of the vport with the matching @vpi.
5872 *
5873 * Return code
5874 * NULL - No vport with the matching @vpi found
5875 * Otherwise - Address to the vport with the matching @vpi.
5876 **/
James Smart6669f9b2009-10-02 15:16:45 -04005877struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05005878lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5879{
5880 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04005881 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05005882
James Smart549e55c2007-08-02 11:09:51 -04005883 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005884 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04005885 if (vport->vpi == vpi) {
5886 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005887 return vport;
James Smart549e55c2007-08-02 11:09:51 -04005888 }
James Smart92d7f7b2007-06-17 19:56:38 -05005889 }
James Smart549e55c2007-08-02 11:09:51 -04005890 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005891 return NULL;
5892}
James Smarted957682007-06-17 19:56:37 -05005893
James Smarte59058c2008-08-24 21:49:00 -04005894/**
James Smart3621a712009-04-06 18:47:14 -04005895 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04005896 * @phba: pointer to lpfc hba data structure.
5897 * @pring: pointer to a SLI ring.
5898 * @elsiocb: pointer to lpfc els iocb data structure.
5899 *
5900 * This routine is used to process an unsolicited event received from a SLI
5901 * (Service Level Interface) ring. The actual processing of the data buffer
5902 * associated with the unsolicited event is done by invoking the routine
5903 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5904 * SLI ring on which the unsolicited event was received.
5905 **/
James Smarted957682007-06-17 19:56:37 -05005906void
5907lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5908 struct lpfc_iocbq *elsiocb)
5909{
5910 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05005911 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05005912 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05005913 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5914 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05005915
James Smartd7c255b2008-08-24 21:50:00 -04005916 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005917 elsiocb->context2 = NULL;
5918 elsiocb->context3 = NULL;
5919
5920 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5921 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5922 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5923 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05005924 phba->fc_stat.NoRcvBuf++;
5925 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05005926 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04005927 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05005928 return;
5929 }
5930
James Smart92d7f7b2007-06-17 19:56:38 -05005931 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5932 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5933 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5934 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5935 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04005936 else
5937 vport = lpfc_find_vport_by_vpid(phba,
5938 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05005939 }
James Smart7f5f3d02008-02-08 18:50:14 -05005940 /* If there are no BDEs associated
5941 * with this IOCB, there is nothing to do.
5942 */
James Smarted957682007-06-17 19:56:37 -05005943 if (icmd->ulpBdeCount == 0)
5944 return;
5945
James Smart7f5f3d02008-02-08 18:50:14 -05005946 /* type of ELS cmd is first 32bit word
5947 * in packet
5948 */
James Smarted957682007-06-17 19:56:37 -05005949 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05005950 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05005951 } else {
5952 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
5953 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05005954 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
5955 paddr);
James Smarted957682007-06-17 19:56:37 -05005956 }
5957
James Smart92d7f7b2007-06-17 19:56:38 -05005958 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5959 /*
5960 * The different unsolicited event handlers would tell us
5961 * if they are done with "mp" by setting context2 to NULL.
5962 */
dea31012005-04-17 16:05:31 -05005963 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005964 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
5965 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05005966 }
James Smarted957682007-06-17 19:56:37 -05005967
5968 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05005969 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05005970 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005971 elsiocb->context2 = bdeBuf2;
5972 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05005973 /* free mp if we are done with it */
5974 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005975 lpfc_in_buf_free(phba, elsiocb->context2);
5976 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05005977 }
dea31012005-04-17 16:05:31 -05005978 }
dea31012005-04-17 16:05:31 -05005979}
James Smart92d7f7b2007-06-17 19:56:38 -05005980
James Smarte59058c2008-08-24 21:49:00 -04005981/**
James Smart3621a712009-04-06 18:47:14 -04005982 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04005983 * @phba: pointer to lpfc hba data structure.
5984 * @vport: pointer to a virtual N_Port data structure.
5985 *
5986 * This routine issues a Port Login (PLOGI) to the Name Server with
5987 * State Change Request (SCR) for a @vport. This routine will create an
5988 * ndlp for the Name Server associated to the @vport if such node does
5989 * not already exist. The PLOGI to Name Server is issued by invoking the
5990 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5991 * (FDMI) is configured to the @vport, a FDMI node will be created and
5992 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5993 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005994void
5995lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5996{
5997 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
5998
5999 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6000 if (!ndlp) {
6001 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6002 if (!ndlp) {
6003 if (phba->fc_topology == TOPOLOGY_LOOP) {
6004 lpfc_disc_start(vport);
6005 return;
6006 }
6007 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006008 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6009 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006010 return;
6011 }
6012 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006013 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6014 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6015 if (!ndlp) {
6016 if (phba->fc_topology == TOPOLOGY_LOOP) {
6017 lpfc_disc_start(vport);
6018 return;
6019 }
6020 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6021 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6022 "0348 NameServer login: node freed\n");
6023 return;
6024 }
James Smart92d7f7b2007-06-17 19:56:38 -05006025 }
James Smart58da1ff2008-04-07 10:15:56 -04006026 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006027
6028 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6029
6030 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6031 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006032 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6033 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006034 return;
6035 }
6036
James Smart3de2a652007-08-02 11:09:59 -04006037 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05006038 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6039 GFP_KERNEL);
6040 if (ndlp_fdmi) {
6041 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6042 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006043 lpfc_nlp_set_state(vport, ndlp_fdmi,
6044 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05006045 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
6046 0);
6047 }
6048 }
6049 return;
6050}
6051
James Smarte59058c2008-08-24 21:49:00 -04006052/**
James Smart3621a712009-04-06 18:47:14 -04006053 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006054 * @phba: pointer to lpfc hba data structure.
6055 * @pmb: pointer to the driver internal queue element for mailbox command.
6056 *
6057 * This routine is the completion callback function to register new vport
6058 * mailbox command. If the new vport mailbox command completes successfully,
6059 * the fabric registration login shall be performed on physical port (the
6060 * new vport created is actually a physical port, with VPI 0) or the port
6061 * login to Name Server for State Change Request (SCR) will be performed
6062 * on virtual port (real virtual port, with VPI greater than 0).
6063 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006064static void
6065lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6066{
6067 struct lpfc_vport *vport = pmb->vport;
6068 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6069 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006070 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006071 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006072
James Smart09372822008-01-11 01:52:54 -05006073 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006074 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006075 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006076
6077 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006078 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6079 "0915 Register VPI failed: 0x%x\n",
6080 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05006081
6082 switch (mb->mbxStatus) {
6083 case 0x11: /* unsupported feature */
6084 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006085 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006086 /* giving up on vport registration */
6087 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6088 spin_lock_irq(shost->host_lock);
6089 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6090 spin_unlock_irq(shost->host_lock);
6091 lpfc_can_disctmo(vport);
6092 break;
James Smart695a8142010-01-26 23:08:03 -05006093 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6094 case 0x20:
6095 spin_lock_irq(shost->host_lock);
6096 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6097 spin_unlock_irq(shost->host_lock);
6098 lpfc_init_vpi(phba, pmb, vport->vpi);
6099 pmb->vport = vport;
6100 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6101 rc = lpfc_sli_issue_mbox(phba, pmb,
6102 MBX_NOWAIT);
6103 if (rc == MBX_NOT_FINISHED) {
6104 lpfc_printf_vlog(vport,
6105 KERN_ERR, LOG_MBOX,
6106 "2732 Failed to issue INIT_VPI"
6107 " mailbox command\n");
6108 } else {
6109 lpfc_nlp_put(ndlp);
6110 return;
6111 }
6112
James Smart92d7f7b2007-06-17 19:56:38 -05006113 default:
6114 /* Try to recover from this error */
6115 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006116 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006117 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006118 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006119 if (vport->port_type == LPFC_PHYSICAL_PORT
6120 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart7f5f3d02008-02-08 18:50:14 -05006121 lpfc_initial_flogi(vport);
6122 else
6123 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006124 break;
6125 }
James Smart92d7f7b2007-06-17 19:56:38 -05006126 } else {
James Smart695a8142010-01-26 23:08:03 -05006127 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006128 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006129 spin_unlock_irq(shost->host_lock);
6130 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006131 if (phba->sli_rev < LPFC_SLI_REV4)
6132 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006133 else {
James Smartfc2b9892010-02-26 14:15:29 -05006134 /*
6135 * If the physical port is instantiated using
6136 * FDISC, do not start vport discovery.
6137 */
6138 if (vport->port_state != LPFC_FDISC)
6139 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006140 lpfc_do_scr_ns_plogi(phba, vport);
6141 }
6142 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006143 lpfc_do_scr_ns_plogi(phba, vport);
6144 }
James Smartfa4066b2008-01-11 01:53:27 -05006145
6146 /* Now, we decrement the ndlp reference count held for this
6147 * callback function
6148 */
6149 lpfc_nlp_put(ndlp);
6150
James Smart92d7f7b2007-06-17 19:56:38 -05006151 mempool_free(pmb, phba->mbox_mem_pool);
6152 return;
6153}
6154
James Smarte59058c2008-08-24 21:49:00 -04006155/**
James Smart3621a712009-04-06 18:47:14 -04006156 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006157 * @phba: pointer to lpfc hba data structure.
6158 * @vport: pointer to a host virtual N_Port data structure.
6159 * @ndlp: pointer to a node-list data structure.
6160 *
6161 * This routine registers the @vport as a new virtual port with a HBA.
6162 * It is done through a registering vpi mailbox command.
6163 **/
James Smart695a8142010-01-26 23:08:03 -05006164void
James Smart92d7f7b2007-06-17 19:56:38 -05006165lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6166 struct lpfc_nodelist *ndlp)
6167{
James Smart09372822008-01-11 01:52:54 -05006168 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006169 LPFC_MBOXQ_t *mbox;
6170
6171 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6172 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006173 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006174 mbox->vport = vport;
6175 mbox->context2 = lpfc_nlp_get(ndlp);
6176 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006177 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006178 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006179 /* mailbox command not success, decrement ndlp
6180 * reference count for this command
6181 */
6182 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006183 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006184
James Smarte8b62012007-08-02 11:10:09 -04006185 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6186 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006187 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006188 }
6189 } else {
James Smarte8b62012007-08-02 11:10:09 -04006190 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6191 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006192 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006193 }
James Smartfa4066b2008-01-11 01:53:27 -05006194 return;
6195
6196mbox_err_exit:
6197 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6198 spin_lock_irq(shost->host_lock);
6199 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6200 spin_unlock_irq(shost->host_lock);
6201 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006202}
6203
James Smarte59058c2008-08-24 21:49:00 -04006204/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006205 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006206 * @phba: pointer to lpfc hba data structure.
6207 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006208 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006209 **/
6210void
James Smart0c9ab6f2010-02-26 14:15:57 -05006211lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006212{
6213 struct lpfc_vport **vports;
6214 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006215 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006216 int i;
James Smart695a8142010-01-26 23:08:03 -05006217
6218 /* Treat this failure as linkdown for all vports */
6219 link_state = phba->link_state;
6220 lpfc_linkdown(phba);
6221 phba->link_state = link_state;
6222
6223 vports = lpfc_create_vport_work_array(phba);
6224
6225 if (vports) {
6226 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6227 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6228 if (ndlp)
6229 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6230 lpfc_els_flush_cmd(vports[i]);
6231 }
6232 lpfc_destroy_vport_work_array(phba, vports);
6233 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006234}
6235
6236/**
6237 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6238 * @phba: pointer to lpfc hba data structure.
6239 *
6240 * This routine abort all pending discovery commands and
6241 * start a timer to retry FLOGI for the physical port
6242 * discovery.
6243 **/
6244void
6245lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6246{
6247 struct lpfc_nodelist *ndlp;
6248 struct Scsi_Host *shost;
6249
6250 /* Cancel the all vports retry delay retry timers */
6251 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05006252
6253 /* If fabric require FLOGI, then re-instantiate physical login */
6254 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6255 if (!ndlp)
6256 return;
6257
James Smart695a8142010-01-26 23:08:03 -05006258 shost = lpfc_shost_from_vport(phba->pport);
6259 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6260 spin_lock_irq(shost->host_lock);
6261 ndlp->nlp_flag |= NLP_DELAY_TMO;
6262 spin_unlock_irq(shost->host_lock);
6263 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6264 phba->pport->port_state = LPFC_FLOGI;
6265 return;
6266}
6267
6268/**
6269 * lpfc_fabric_login_reqd - Check if FLOGI required.
6270 * @phba: pointer to lpfc hba data structure.
6271 * @cmdiocb: pointer to FDISC command iocb.
6272 * @rspiocb: pointer to FDISC response iocb.
6273 *
6274 * This routine checks if a FLOGI is reguired for FDISC
6275 * to succeed.
6276 **/
6277static int
6278lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6279 struct lpfc_iocbq *cmdiocb,
6280 struct lpfc_iocbq *rspiocb)
6281{
6282
6283 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6284 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6285 return 0;
6286 else
6287 return 1;
6288}
6289
6290/**
James Smart3621a712009-04-06 18:47:14 -04006291 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006292 * @phba: pointer to lpfc hba data structure.
6293 * @cmdiocb: pointer to lpfc command iocb data structure.
6294 * @rspiocb: pointer to lpfc response iocb data structure.
6295 *
6296 * This routine is the completion callback function to a Fabric Discover
6297 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6298 * single threaded, each FDISC completion callback function will reset
6299 * the discovery timer for all vports such that the timers will not get
6300 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6301 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6302 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6303 * assigned to the vport has been changed with the completion of the FDISC
6304 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6305 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6306 * routine is invoked to register new vport with the HBA. Otherwise, the
6307 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6308 * Server for State Change Request (SCR).
6309 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006310static void
6311lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6312 struct lpfc_iocbq *rspiocb)
6313{
6314 struct lpfc_vport *vport = cmdiocb->vport;
6315 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6316 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6317 struct lpfc_nodelist *np;
6318 struct lpfc_nodelist *next_np;
6319 IOCB_t *irsp = &rspiocb->iocb;
6320 struct lpfc_iocbq *piocb;
6321
James Smarte8b62012007-08-02 11:10:09 -04006322 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6323 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6324 irsp->ulpStatus, irsp->un.ulpWord[4],
6325 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05006326 /* Since all FDISCs are being single threaded, we
6327 * must reset the discovery timer for ALL vports
6328 * waiting to send FDISC when one completes.
6329 */
6330 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6331 lpfc_set_disctmo(piocb->vport);
6332 }
6333
James Smart858c9f62007-06-17 19:56:39 -05006334 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6335 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6336 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6337
James Smart92d7f7b2007-06-17 19:56:38 -05006338 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05006339
6340 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6341 lpfc_retry_pport_discovery(phba);
6342 goto out;
6343 }
6344
James Smart92d7f7b2007-06-17 19:56:38 -05006345 /* Check for retry */
6346 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6347 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006348 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04006349 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04006350 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04006351 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04006352 goto fdisc_failed;
6353 }
James Smartd7c255b2008-08-24 21:50:00 -04006354 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05006355 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04006356 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04006357 vport->fc_flag |= FC_FABRIC;
6358 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6359 vport->fc_flag |= FC_PUBLIC_LOOP;
6360 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006361
James Smartd7c255b2008-08-24 21:50:00 -04006362 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6363 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6364 if ((vport->fc_prevDID != vport->fc_myDID) &&
6365 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6366 /* If our NportID changed, we need to ensure all
6367 * remaining NPORTs get unreg_login'ed so we can
6368 * issue unreg_vpi.
6369 */
6370 list_for_each_entry_safe(np, next_np,
6371 &vport->fc_nodes, nlp_listp) {
6372 if (!NLP_CHK_NODE_ACT(ndlp) ||
6373 (np->nlp_state != NLP_STE_NPR_NODE) ||
6374 !(np->nlp_flag & NLP_NPR_ADISC))
6375 continue;
James Smart09372822008-01-11 01:52:54 -05006376 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006377 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05006378 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006379 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05006380 }
James Smart78730cf2010-04-06 15:06:30 -04006381 lpfc_cleanup_pending_mbox(vport);
James Smartd7c255b2008-08-24 21:50:00 -04006382 lpfc_mbx_unreg_vpi(vport);
6383 spin_lock_irq(shost->host_lock);
6384 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05006385 if (phba->sli_rev == LPFC_SLI_REV4)
6386 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04006387 else
6388 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04006389 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006390 }
6391
James Smartecfd03c2010-02-12 14:41:27 -05006392 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6393 lpfc_issue_init_vpi(vport);
6394 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04006395 lpfc_register_new_vport(phba, vport, ndlp);
6396 else
6397 lpfc_do_scr_ns_plogi(phba, vport);
6398 goto out;
6399fdisc_failed:
6400 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6401 /* Cancel discovery timer */
6402 lpfc_can_disctmo(vport);
6403 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006404out:
6405 lpfc_els_free_iocb(phba, cmdiocb);
6406}
6407
James Smarte59058c2008-08-24 21:49:00 -04006408/**
James Smart3621a712009-04-06 18:47:14 -04006409 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006410 * @vport: pointer to a virtual N_Port data structure.
6411 * @ndlp: pointer to a node-list data structure.
6412 * @retry: number of retries to the command IOCB.
6413 *
6414 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6415 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6416 * routine to issue the IOCB, which makes sure only one outstanding fabric
6417 * IOCB will be sent off HBA at any given time.
6418 *
6419 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6420 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6421 * will be stored into the context1 field of the IOCB for the completion
6422 * callback function to the FDISC ELS command.
6423 *
6424 * Return code
6425 * 0 - Successfully issued fdisc iocb command
6426 * 1 - Failed to issue fdisc iocb command
6427 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006428static int
James Smart92d7f7b2007-06-17 19:56:38 -05006429lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6430 uint8_t retry)
6431{
6432 struct lpfc_hba *phba = vport->phba;
6433 IOCB_t *icmd;
6434 struct lpfc_iocbq *elsiocb;
6435 struct serv_parm *sp;
6436 uint8_t *pcmd;
6437 uint16_t cmdsize;
6438 int did = ndlp->nlp_DID;
6439 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006440
James Smart5ffc2662009-11-18 15:39:44 -05006441 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05006442 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6443 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6444 ELS_CMD_FDISC);
6445 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006446 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006447 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6448 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006449 return 1;
6450 }
6451
6452 icmd = &elsiocb->iocb;
6453 icmd->un.elsreq64.myID = 0;
6454 icmd->un.elsreq64.fl = 1;
6455
James Smartf1126682009-06-10 17:22:44 -04006456 if (phba->sli_rev == LPFC_SLI_REV4) {
6457 /* FDISC needs to be 1 for WQE VPI */
6458 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6459 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6460 /* Set the ulpContext to the vpi */
6461 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6462 } else {
6463 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6464 icmd->ulpCt_h = 1;
6465 icmd->ulpCt_l = 0;
6466 }
James Smart92d7f7b2007-06-17 19:56:38 -05006467
6468 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6469 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6470 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6471 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6472 sp = (struct serv_parm *) pcmd;
6473 /* Setup CSPs accordingly for Fabric */
6474 sp->cmn.e_d_tov = 0;
6475 sp->cmn.w2.r_a_tov = 0;
6476 sp->cls1.classValid = 0;
6477 sp->cls2.seqDelivery = 1;
6478 sp->cls3.seqDelivery = 1;
6479
6480 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6481 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6482 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6483 pcmd += sizeof(uint32_t); /* Port Name */
6484 memcpy(pcmd, &vport->fc_portname, 8);
6485 pcmd += sizeof(uint32_t); /* Node Name */
6486 pcmd += sizeof(uint32_t); /* Node Name */
6487 memcpy(pcmd, &vport->fc_nodename, 8);
6488
6489 lpfc_set_disctmo(vport);
6490
6491 phba->fc_stat.elsXmitFDISC++;
6492 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6493
James Smart858c9f62007-06-17 19:56:39 -05006494 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6495 "Issue FDISC: did:x%x",
6496 did, 0, 0);
6497
James Smart92d7f7b2007-06-17 19:56:38 -05006498 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6499 if (rc == IOCB_ERROR) {
6500 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006501 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006502 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6503 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006504 return 1;
6505 }
6506 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05006507 return 0;
6508}
6509
James Smarte59058c2008-08-24 21:49:00 -04006510/**
James Smart3621a712009-04-06 18:47:14 -04006511 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04006512 * @phba: pointer to lpfc hba data structure.
6513 * @cmdiocb: pointer to lpfc command iocb data structure.
6514 * @rspiocb: pointer to lpfc response iocb data structure.
6515 *
6516 * This routine is the completion callback function to the issuing of a LOGO
6517 * ELS command off a vport. It frees the command IOCB and then decrement the
6518 * reference count held on ndlp for this completion function, indicating that
6519 * the reference to the ndlp is no long needed. Note that the
6520 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6521 * callback function and an additional explicit ndlp reference decrementation
6522 * will trigger the actual release of the ndlp.
6523 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006524static void
6525lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6526 struct lpfc_iocbq *rspiocb)
6527{
6528 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006529 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006530 struct lpfc_nodelist *ndlp;
6531 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006532
6533 irsp = &rspiocb->iocb;
6534 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6535 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6536 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006537
6538 lpfc_els_free_iocb(phba, cmdiocb);
6539 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006540
6541 /* Trigger the release of the ndlp after logo */
6542 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006543}
6544
James Smarte59058c2008-08-24 21:49:00 -04006545/**
James Smart3621a712009-04-06 18:47:14 -04006546 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04006547 * @vport: pointer to a virtual N_Port data structure.
6548 * @ndlp: pointer to a node-list data structure.
6549 *
6550 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6551 *
6552 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6553 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6554 * will be stored into the context1 field of the IOCB for the completion
6555 * callback function to the LOGO ELS command.
6556 *
6557 * Return codes
6558 * 0 - Successfully issued logo off the @vport
6559 * 1 - Failed to issue logo off the @vport
6560 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006561int
6562lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6563{
6564 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6565 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006566 IOCB_t *icmd;
6567 struct lpfc_iocbq *elsiocb;
6568 uint8_t *pcmd;
6569 uint16_t cmdsize;
6570
6571 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6572 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6573 ELS_CMD_LOGO);
6574 if (!elsiocb)
6575 return 1;
6576
6577 icmd = &elsiocb->iocb;
6578 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6579 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6580 pcmd += sizeof(uint32_t);
6581
6582 /* Fill in LOGO payload */
6583 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6584 pcmd += sizeof(uint32_t);
6585 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6586
James Smart858c9f62007-06-17 19:56:39 -05006587 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6588 "Issue LOGO npiv did:x%x flg:x%x",
6589 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6590
James Smart92d7f7b2007-06-17 19:56:38 -05006591 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6592 spin_lock_irq(shost->host_lock);
6593 ndlp->nlp_flag |= NLP_LOGO_SND;
6594 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04006595 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6596 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05006597 spin_lock_irq(shost->host_lock);
6598 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6599 spin_unlock_irq(shost->host_lock);
6600 lpfc_els_free_iocb(phba, elsiocb);
6601 return 1;
6602 }
6603 return 0;
6604}
6605
James Smarte59058c2008-08-24 21:49:00 -04006606/**
James Smart3621a712009-04-06 18:47:14 -04006607 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04006608 * @ptr: holder for the timer function associated data.
6609 *
6610 * This routine is invoked by the fabric iocb block timer after
6611 * timeout. It posts the fabric iocb block timeout event by setting the
6612 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6613 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6614 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6615 * posted event WORKER_FABRIC_BLOCK_TMO.
6616 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006617void
6618lpfc_fabric_block_timeout(unsigned long ptr)
6619{
6620 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6621 unsigned long iflags;
6622 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04006623
James Smart92d7f7b2007-06-17 19:56:38 -05006624 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6625 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6626 if (!tmo_posted)
6627 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6628 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6629
James Smart5e9d9b82008-06-14 22:52:53 -04006630 if (!tmo_posted)
6631 lpfc_worker_wake_up(phba);
6632 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006633}
6634
James Smarte59058c2008-08-24 21:49:00 -04006635/**
James Smart3621a712009-04-06 18:47:14 -04006636 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04006637 * @phba: pointer to lpfc hba data structure.
6638 *
6639 * This routine issues one fabric iocb from the driver internal list to
6640 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6641 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6642 * remove one pending fabric iocb from the driver internal list and invokes
6643 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6644 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006645static void
6646lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6647{
6648 struct lpfc_iocbq *iocb;
6649 unsigned long iflags;
6650 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05006651 IOCB_t *cmd;
6652
6653repeat:
6654 iocb = NULL;
6655 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05006656 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05006657 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6658 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6659 list);
6660 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05006661 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05006662 atomic_inc(&phba->fabric_iocb_count);
6663 }
6664 spin_unlock_irqrestore(&phba->hbalock, iflags);
6665 if (iocb) {
6666 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6667 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6668 iocb->iocb_flag |= LPFC_IO_FABRIC;
6669
James Smart858c9f62007-06-17 19:56:39 -05006670 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6671 "Fabric sched1: ste:x%x",
6672 iocb->vport->port_state, 0, 0);
6673
James Smart3772a992009-05-22 14:50:54 -04006674 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006675
6676 if (ret == IOCB_ERROR) {
6677 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6678 iocb->fabric_iocb_cmpl = NULL;
6679 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6680 cmd = &iocb->iocb;
6681 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6682 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6683 iocb->iocb_cmpl(phba, iocb, iocb);
6684
6685 atomic_dec(&phba->fabric_iocb_count);
6686 goto repeat;
6687 }
6688 }
6689
6690 return;
6691}
6692
James Smarte59058c2008-08-24 21:49:00 -04006693/**
James Smart3621a712009-04-06 18:47:14 -04006694 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006695 * @phba: pointer to lpfc hba data structure.
6696 *
6697 * This routine unblocks the issuing fabric iocb command. The function
6698 * will clear the fabric iocb block bit and then invoke the routine
6699 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6700 * from the driver internal fabric iocb list.
6701 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006702void
6703lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6704{
6705 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6706
6707 lpfc_resume_fabric_iocbs(phba);
6708 return;
6709}
6710
James Smarte59058c2008-08-24 21:49:00 -04006711/**
James Smart3621a712009-04-06 18:47:14 -04006712 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006713 * @phba: pointer to lpfc hba data structure.
6714 *
6715 * This routine blocks the issuing fabric iocb for a specified amount of
6716 * time (currently 100 ms). This is done by set the fabric iocb block bit
6717 * and set up a timeout timer for 100ms. When the block bit is set, no more
6718 * fabric iocb will be issued out of the HBA.
6719 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006720static void
6721lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6722{
6723 int blocked;
6724
6725 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05006726 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05006727 if (!blocked)
6728 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6729
6730 return;
6731}
6732
James Smarte59058c2008-08-24 21:49:00 -04006733/**
James Smart3621a712009-04-06 18:47:14 -04006734 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04006735 * @phba: pointer to lpfc hba data structure.
6736 * @cmdiocb: pointer to lpfc command iocb data structure.
6737 * @rspiocb: pointer to lpfc response iocb data structure.
6738 *
6739 * This routine is the callback function that is put to the fabric iocb's
6740 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6741 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6742 * function first restores and invokes the original iocb's callback function
6743 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6744 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6745 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006746static void
6747lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6748 struct lpfc_iocbq *rspiocb)
6749{
6750 struct ls_rjt stat;
6751
6752 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6753 BUG();
6754
6755 switch (rspiocb->iocb.ulpStatus) {
6756 case IOSTAT_NPORT_RJT:
6757 case IOSTAT_FABRIC_RJT:
6758 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6759 lpfc_block_fabric_iocbs(phba);
6760 }
6761 break;
6762
6763 case IOSTAT_NPORT_BSY:
6764 case IOSTAT_FABRIC_BSY:
6765 lpfc_block_fabric_iocbs(phba);
6766 break;
6767
6768 case IOSTAT_LS_RJT:
6769 stat.un.lsRjtError =
6770 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6771 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6772 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6773 lpfc_block_fabric_iocbs(phba);
6774 break;
6775 }
6776
6777 if (atomic_read(&phba->fabric_iocb_count) == 0)
6778 BUG();
6779
6780 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6781 cmdiocb->fabric_iocb_cmpl = NULL;
6782 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6783 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6784
6785 atomic_dec(&phba->fabric_iocb_count);
6786 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05006787 /* Post any pending iocbs to HBA */
6788 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05006789 }
6790}
6791
James Smarte59058c2008-08-24 21:49:00 -04006792/**
James Smart3621a712009-04-06 18:47:14 -04006793 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006794 * @phba: pointer to lpfc hba data structure.
6795 * @iocb: pointer to lpfc command iocb data structure.
6796 *
6797 * This routine is used as the top-level API for issuing a fabric iocb command
6798 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6799 * function makes sure that only one fabric bound iocb will be outstanding at
6800 * any given time. As such, this function will first check to see whether there
6801 * is already an outstanding fabric iocb on the wire. If so, it will put the
6802 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6803 * issued later. Otherwise, it will issue the iocb on the wire and update the
6804 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6805 *
6806 * Note, this implementation has a potential sending out fabric IOCBs out of
6807 * order. The problem is caused by the construction of the "ready" boolen does
6808 * not include the condition that the internal fabric IOCB list is empty. As
6809 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6810 * ahead of the fabric IOCBs in the internal list.
6811 *
6812 * Return code
6813 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6814 * IOCB_ERROR - failed to issue fabric iocb
6815 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006816static int
James Smart92d7f7b2007-06-17 19:56:38 -05006817lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6818{
6819 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05006820 int ready;
6821 int ret;
6822
6823 if (atomic_read(&phba->fabric_iocb_count) > 1)
6824 BUG();
6825
6826 spin_lock_irqsave(&phba->hbalock, iflags);
6827 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6828 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6829
James Smart7f5f3d02008-02-08 18:50:14 -05006830 if (ready)
6831 /* Increment fabric iocb count to hold the position */
6832 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05006833 spin_unlock_irqrestore(&phba->hbalock, iflags);
6834 if (ready) {
6835 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6836 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6837 iocb->iocb_flag |= LPFC_IO_FABRIC;
6838
James Smart858c9f62007-06-17 19:56:39 -05006839 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6840 "Fabric sched2: ste:x%x",
6841 iocb->vport->port_state, 0, 0);
6842
James Smart3772a992009-05-22 14:50:54 -04006843 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006844
6845 if (ret == IOCB_ERROR) {
6846 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6847 iocb->fabric_iocb_cmpl = NULL;
6848 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6849 atomic_dec(&phba->fabric_iocb_count);
6850 }
6851 } else {
6852 spin_lock_irqsave(&phba->hbalock, iflags);
6853 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6854 spin_unlock_irqrestore(&phba->hbalock, iflags);
6855 ret = IOCB_SUCCESS;
6856 }
6857 return ret;
6858}
6859
James Smarte59058c2008-08-24 21:49:00 -04006860/**
James Smart3621a712009-04-06 18:47:14 -04006861 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006862 * @vport: pointer to a virtual N_Port data structure.
6863 *
6864 * This routine aborts all the IOCBs associated with a @vport from the
6865 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6866 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6867 * list, removes each IOCB associated with the @vport off the list, set the
6868 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6869 * associated with the IOCB.
6870 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006871static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05006872{
6873 LIST_HEAD(completions);
6874 struct lpfc_hba *phba = vport->phba;
6875 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05006876
6877 spin_lock_irq(&phba->hbalock);
6878 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6879 list) {
6880
6881 if (piocb->vport != vport)
6882 continue;
6883
6884 list_move_tail(&piocb->list, &completions);
6885 }
6886 spin_unlock_irq(&phba->hbalock);
6887
James Smarta257bf92009-04-06 18:48:10 -04006888 /* Cancel all the IOCBs from the completions list */
6889 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6890 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006891}
6892
James Smarte59058c2008-08-24 21:49:00 -04006893/**
James Smart3621a712009-04-06 18:47:14 -04006894 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006895 * @ndlp: pointer to a node-list data structure.
6896 *
6897 * This routine aborts all the IOCBs associated with an @ndlp from the
6898 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6899 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6900 * list, removes each IOCB associated with the @ndlp off the list, set the
6901 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6902 * associated with the IOCB.
6903 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006904void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6905{
6906 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04006907 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006908 struct lpfc_iocbq *tmp_iocb, *piocb;
6909 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05006910
6911 spin_lock_irq(&phba->hbalock);
6912 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6913 list) {
6914 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6915
6916 list_move_tail(&piocb->list, &completions);
6917 }
6918 }
6919 spin_unlock_irq(&phba->hbalock);
6920
James Smarta257bf92009-04-06 18:48:10 -04006921 /* Cancel all the IOCBs from the completions list */
6922 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6923 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006924}
6925
James Smarte59058c2008-08-24 21:49:00 -04006926/**
James Smart3621a712009-04-06 18:47:14 -04006927 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006928 * @phba: pointer to lpfc hba data structure.
6929 *
6930 * This routine aborts all the IOCBs currently on the driver internal
6931 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6932 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6933 * list, removes IOCBs off the list, set the status feild to
6934 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6935 * the IOCB.
6936 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006937void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
6938{
6939 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05006940
6941 spin_lock_irq(&phba->hbalock);
6942 list_splice_init(&phba->fabric_iocb_list, &completions);
6943 spin_unlock_irq(&phba->hbalock);
6944
James Smarta257bf92009-04-06 18:48:10 -04006945 /* Cancel all the IOCBs from the completions list */
6946 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6947 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006948}
James Smart6fb120a2009-05-22 14:52:59 -04006949
6950/**
6951 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
6952 * @phba: pointer to lpfc hba data structure.
6953 * @axri: pointer to the els xri abort wcqe structure.
6954 *
6955 * This routine is invoked by the worker thread to process a SLI4 slow-path
6956 * ELS aborted xri.
6957 **/
6958void
6959lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
6960 struct sli4_wcqe_xri_aborted *axri)
6961{
6962 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
6963 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6964 unsigned long iflag = 0;
James Smart589a52d2010-07-14 15:30:54 -04006965 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04006966
James Smart0f65ff62010-02-26 14:14:23 -05006967 spin_lock_irqsave(&phba->hbalock, iflag);
6968 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006969 list_for_each_entry_safe(sglq_entry, sglq_next,
6970 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
6971 if (sglq_entry->sli4_xritag == xri) {
6972 list_del(&sglq_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04006973 list_add_tail(&sglq_entry->list,
6974 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05006975 sglq_entry->state = SGL_FREED;
6976 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006977 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart589a52d2010-07-14 15:30:54 -04006978
6979 /* Check if TXQ queue needs to be serviced */
6980 if (pring->txq_cnt)
6981 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04006982 return;
6983 }
6984 }
James Smart0f65ff62010-02-26 14:14:23 -05006985 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
6986 sglq_entry = __lpfc_get_active_sglq(phba, xri);
6987 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
6988 spin_unlock_irqrestore(&phba->hbalock, iflag);
6989 return;
6990 }
6991 sglq_entry->state = SGL_XRI_ABORTED;
6992 spin_unlock_irqrestore(&phba->hbalock, iflag);
6993 return;
James Smart6fb120a2009-05-22 14:52:59 -04006994}