blob: b16311d60c66f3393e679c9945820737228b31cf [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 }
527
James Smart2e0fef82007-06-17 19:56:36 -0500528 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500529 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500530 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500531 ndlp->nlp_class_sup = 0;
532 if (sp->cls1.classValid)
533 ndlp->nlp_class_sup |= FC_COS_CLASS1;
534 if (sp->cls2.classValid)
535 ndlp->nlp_class_sup |= FC_COS_CLASS2;
536 if (sp->cls3.classValid)
537 ndlp->nlp_class_sup |= FC_COS_CLASS3;
538 if (sp->cls4.classValid)
539 ndlp->nlp_class_sup |= FC_COS_CLASS4;
540 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
541 sp->cmn.bbRcvSizeLsb;
542 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
543
James Smart92d7f7b2007-06-17 19:56:38 -0500544 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
545 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400546 lpfc_printf_vlog(vport, KERN_WARNING,
547 LOG_ELS | LOG_VPORT,
548 "1816 FLOGI NPIV supported, "
549 "response data 0x%x\n",
550 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500551 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500552 } else {
553 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400554 to call reg_vnpid atleast for the physcial host */
555 lpfc_printf_vlog(vport, KERN_WARNING,
556 LOG_ELS | LOG_VPORT,
557 "1817 Fabric does not support NPIV "
558 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500559 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
560 }
561 }
562
563 if ((vport->fc_prevDID != vport->fc_myDID) &&
564 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
565
566 /* If our NportID changed, we need to ensure all
567 * remaining NPORTs get unreg_login'ed.
568 */
569 list_for_each_entry_safe(np, next_np,
570 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400571 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500572 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500573 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
574 !(np->nlp_flag & NLP_NPR_ADISC))
575 continue;
576 spin_lock_irq(shost->host_lock);
577 np->nlp_flag &= ~NLP_NPR_ADISC;
578 spin_unlock_irq(shost->host_lock);
579 lpfc_unreg_rpi(vport, np);
580 }
James Smart78730cf2010-04-06 15:06:30 -0400581 lpfc_cleanup_pending_mbox(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500582 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
583 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500584 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500585 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500586 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500587 }
James Smartecfd03c2010-02-12 14:41:27 -0500588 /*
589 * If VPI is unreged, driver need to do INIT_VPI
590 * before re-registering
591 */
592 if (phba->sli_rev == LPFC_SLI_REV4) {
593 spin_lock_irq(shost->host_lock);
594 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
595 spin_unlock_irq(shost->host_lock);
596 }
James Smart38b92ef2010-08-04 16:11:39 -0400597 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
598 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
599 /*
600 * Driver needs to re-reg VPI in order for f/w
601 * to update the MAC address.
602 */
603 lpfc_register_new_vport(phba, vport, ndlp);
604 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500605 }
606
James Smart6fb120a2009-05-22 14:52:59 -0400607 if (phba->sli_rev < LPFC_SLI_REV4) {
608 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
609 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
610 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
611 lpfc_register_new_vport(phba, vport, ndlp);
612 else
613 lpfc_issue_fabric_reglogin(vport);
614 } else {
615 ndlp->nlp_type |= NLP_FABRIC;
616 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500617 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
618 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400619 lpfc_start_fdiscs(phba);
620 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500621 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500622 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500623 else
James Smart6fb120a2009-05-22 14:52:59 -0400624 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500625 }
dea31012005-04-17 16:05:31 -0500626 return 0;
dea31012005-04-17 16:05:31 -0500627}
James Smarte59058c2008-08-24 21:49:00 -0400628/**
James Smart3621a712009-04-06 18:47:14 -0400629 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400630 * @vport: pointer to a host virtual N_Port data structure.
631 * @ndlp: pointer to a node-list data structure.
632 * @sp: pointer to service parameter data structure.
633 *
634 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
635 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
636 * in a point-to-point topology. First, the @vport's N_Port Name is compared
637 * with the received N_Port Name: if the @vport's N_Port Name is greater than
638 * the received N_Port Name lexicographically, this node shall assign local
639 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
640 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
641 * this node shall just wait for the remote node to issue PLOGI and assign
642 * N_Port IDs.
643 *
644 * Return code
645 * 0 - Success
646 * -ENXIO - Fail
647 **/
dea31012005-04-17 16:05:31 -0500648static int
James Smart2e0fef82007-06-17 19:56:36 -0500649lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
650 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500651{
James Smart2e0fef82007-06-17 19:56:36 -0500652 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
653 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500654 LPFC_MBOXQ_t *mbox;
655 int rc;
656
James Smart2e0fef82007-06-17 19:56:36 -0500657 spin_lock_irq(shost->host_lock);
658 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
659 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500660
661 phba->fc_edtov = FF_DEF_EDTOV;
662 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500663 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500664 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500665 if (rc >= 0) {
666 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500667 spin_lock_irq(shost->host_lock);
668 vport->fc_flag |= FC_PT2PT_PLOGI;
669 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500670
671 /*
672 * N_Port ID cannot be 0, set our to LocalID the other
673 * side will be RemoteID.
674 */
675
676 /* not equal */
677 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500678 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500679
680 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
681 if (!mbox)
682 goto fail;
683
684 lpfc_config_link(phba, mbox);
685
686 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500687 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400688 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500689 if (rc == MBX_NOT_FINISHED) {
690 mempool_free(mbox, phba->mbox_mem_pool);
691 goto fail;
692 }
James Smarte47c9092008-02-08 18:49:26 -0500693 /* Decrement ndlp reference count indicating that ndlp can be
694 * safely released when other references to it are done.
695 */
James Smart329f9bc2007-04-25 09:53:01 -0400696 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500697
James Smart2e0fef82007-06-17 19:56:36 -0500698 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500699 if (!ndlp) {
700 /*
701 * Cannot find existing Fabric ndlp, so allocate a
702 * new one
703 */
704 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
705 if (!ndlp)
706 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500707 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500708 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
709 ndlp = lpfc_enable_node(vport, ndlp,
710 NLP_STE_UNUSED_NODE);
711 if(!ndlp)
712 goto fail;
dea31012005-04-17 16:05:31 -0500713 }
714
715 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500716 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500717 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500718 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500719 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500720 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
721 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500722 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500723 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500724 } else
725 /* This side will wait for the PLOGI, decrement ndlp reference
726 * count indicating that ndlp can be released when other
727 * references to it are done.
728 */
James Smart329f9bc2007-04-25 09:53:01 -0400729 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500730
James Smart09372822008-01-11 01:52:54 -0500731 /* If we are pt2pt with another NPort, force NPIV off! */
732 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
733
James Smart2e0fef82007-06-17 19:56:36 -0500734 spin_lock_irq(shost->host_lock);
735 vport->fc_flag |= FC_PT2PT;
736 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500737
738 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500739 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500740 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500741fail:
dea31012005-04-17 16:05:31 -0500742 return -ENXIO;
743}
744
James Smarte59058c2008-08-24 21:49:00 -0400745/**
James Smart3621a712009-04-06 18:47:14 -0400746 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400747 * @phba: pointer to lpfc hba data structure.
748 * @cmdiocb: pointer to lpfc command iocb data structure.
749 * @rspiocb: pointer to lpfc response iocb data structure.
750 *
751 * This routine is the top-level completion callback function for issuing
752 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
753 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
754 * retry has been made (either immediately or delayed with lpfc_els_retry()
755 * returning 1), the command IOCB will be released and function returned.
756 * If the retry attempt has been given up (possibly reach the maximum
757 * number of retries), one additional decrement of ndlp reference shall be
758 * invoked before going out after releasing the command IOCB. This will
759 * actually release the remote node (Note, lpfc_els_free_iocb() will also
760 * invoke one decrement of ndlp reference count). If no error reported in
761 * the IOCB status, the command Port ID field is used to determine whether
762 * this is a point-to-point topology or a fabric topology: if the Port ID
763 * field is assigned, it is a fabric topology; otherwise, it is a
764 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
765 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
766 * specific topology completion conditions.
767 **/
dea31012005-04-17 16:05:31 -0500768static void
James Smart329f9bc2007-04-25 09:53:01 -0400769lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
770 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500771{
James Smart2e0fef82007-06-17 19:56:36 -0500772 struct lpfc_vport *vport = cmdiocb->vport;
773 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500774 IOCB_t *irsp = &rspiocb->iocb;
775 struct lpfc_nodelist *ndlp = cmdiocb->context1;
776 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
777 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500778 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500779 int rc;
780
781 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500782 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500783 /* One additional decrement on node reference count to
784 * trigger the release of the node
785 */
James Smart329f9bc2007-04-25 09:53:01 -0400786 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500787 goto out;
788 }
789
James Smart858c9f62007-06-17 19:56:39 -0500790 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
791 "FLOGI cmpl: status:x%x/x%x state:x%x",
792 irsp->ulpStatus, irsp->un.ulpWord[4],
793 vport->port_state);
794
dea31012005-04-17 16:05:31 -0500795 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500796 /*
797 * In case of FIP mode, perform round robin FCF failover
798 * due to new FCF discovery
799 */
800 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smartdbb6b3a2010-06-08 18:31:37 -0400801 (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
802 (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) &&
803 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500804 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
805 "2611 FLOGI failed on registered "
James Smart38b92ef2010-08-04 16:11:39 -0400806 "FCF record fcf_index(%d), status: "
807 "x%x/x%x, tmo:x%x, trying to perform "
808 "round robin failover\n",
809 phba->fcf.current_rec.fcf_indx,
810 irsp->ulpStatus, irsp->un.ulpWord[4],
811 irsp->ulpTimeout);
James Smart0c9ab6f2010-02-26 14:15:57 -0500812 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
813 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
814 /*
815 * Exhausted the eligible FCF record list,
816 * fail through to retry FLOGI on current
817 * FCF record.
818 */
819 lpfc_printf_log(phba, KERN_WARNING,
820 LOG_FIP | LOG_ELS,
James Smart3804dc82010-07-14 15:31:37 -0400821 "2760 Completed one round "
822 "of FLOGI FCF round robin "
823 "failover list, retry FLOGI "
824 "on currently registered "
825 "FCF index:%d\n",
James Smart0c9ab6f2010-02-26 14:15:57 -0500826 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500827 } else {
James Smart3804dc82010-07-14 15:31:37 -0400828 lpfc_printf_log(phba, KERN_INFO,
829 LOG_FIP | LOG_ELS,
830 "2794 FLOGI FCF round robin "
831 "failover to FCF index x%x\n",
832 fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -0500833 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba,
834 fcf_index);
James Smart3804dc82010-07-14 15:31:37 -0400835 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -0500836 lpfc_printf_log(phba, KERN_WARNING,
837 LOG_FIP | LOG_ELS,
838 "2761 FLOGI round "
839 "robin FCF failover "
840 "read FCF failed "
841 "rc:x%x, fcf_index:"
842 "%d\n", rc,
843 phba->fcf.current_rec.fcf_indx);
James Smart3804dc82010-07-14 15:31:37 -0400844 else
James Smart0c9ab6f2010-02-26 14:15:57 -0500845 goto out;
846 }
847 }
848
James Smart38b92ef2010-08-04 16:11:39 -0400849 /* FLOGI failure */
850 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
851 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
852 irsp->ulpStatus, irsp->un.ulpWord[4],
853 irsp->ulpTimeout);
854
dea31012005-04-17 16:05:31 -0500855 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500856 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500857 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500858
dea31012005-04-17 16:05:31 -0500859 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500860 spin_lock_irq(shost->host_lock);
861 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
862 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500863
James Smart329f9bc2007-04-25 09:53:01 -0400864 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500865 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
866 * alpa map would take too long otherwise.
867 */
868 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400869 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500870 }
871
872 /* FLOGI failure */
James Smarte40a02c2010-02-26 14:13:54 -0500873 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
874 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400875 irsp->ulpStatus, irsp->un.ulpWord[4],
876 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500877 goto flogifail;
878 }
James Smart695a8142010-01-26 23:08:03 -0500879 spin_lock_irq(shost->host_lock);
880 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400881 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500882 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500883
884 /*
885 * The FLogI succeeded. Sync the data for the CPU before
886 * accessing it.
887 */
888 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
889
890 sp = prsp->virt + sizeof(uint32_t);
891
892 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400893 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200894 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400895 "Data: x%x x%x x%x x%x\n",
896 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
897 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500898
James Smart2e0fef82007-06-17 19:56:36 -0500899 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500900 /*
901 * If Common Service Parameters indicate Nport
902 * we are point to point, if Fport we are Fabric.
903 */
904 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500905 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400906 else if (!(phba->hba_flag & HBA_FCOE_SUPPORT))
James Smart2e0fef82007-06-17 19:56:36 -0500907 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400908 else {
909 lpfc_printf_vlog(vport, KERN_ERR,
910 LOG_FIP | LOG_ELS,
911 "2831 FLOGI response with cleared Fabric "
912 "bit fcf_index 0x%x "
913 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
914 "Fabric Name "
915 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
916 phba->fcf.current_rec.fcf_indx,
917 phba->fcf.current_rec.switch_name[0],
918 phba->fcf.current_rec.switch_name[1],
919 phba->fcf.current_rec.switch_name[2],
920 phba->fcf.current_rec.switch_name[3],
921 phba->fcf.current_rec.switch_name[4],
922 phba->fcf.current_rec.switch_name[5],
923 phba->fcf.current_rec.switch_name[6],
924 phba->fcf.current_rec.switch_name[7],
925 phba->fcf.current_rec.fabric_name[0],
926 phba->fcf.current_rec.fabric_name[1],
927 phba->fcf.current_rec.fabric_name[2],
928 phba->fcf.current_rec.fabric_name[3],
929 phba->fcf.current_rec.fabric_name[4],
930 phba->fcf.current_rec.fabric_name[5],
931 phba->fcf.current_rec.fabric_name[6],
932 phba->fcf.current_rec.fabric_name[7]);
933 lpfc_nlp_put(ndlp);
934 spin_lock_irq(&phba->hbalock);
935 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
936 spin_unlock_irq(&phba->hbalock);
937 goto out;
938 }
James Smart0c9ab6f2010-02-26 14:15:57 -0500939 if (!rc) {
940 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400941 if (phba->hba_flag & HBA_FIP_SUPPORT)
942 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
943 LOG_ELS,
944 "2769 FLOGI successful on FCF "
945 "record: current_fcf_index:"
946 "x%x, terminate FCF round "
947 "robin failover process\n",
948 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500949 spin_lock_irq(&phba->hbalock);
950 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
951 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500952 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500953 }
dea31012005-04-17 16:05:31 -0500954 }
955
956flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400957 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500958
James Smart858c9f62007-06-17 19:56:39 -0500959 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500960 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500961 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500962
963 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500964 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400965 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
966 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
967 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
968 (phba->link_state != LPFC_CLEAR_LA)) {
969 /* If FLOGI failed enable link interrupt. */
970 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500971 }
dea31012005-04-17 16:05:31 -0500972out:
973 lpfc_els_free_iocb(phba, cmdiocb);
974}
975
James Smarte59058c2008-08-24 21:49:00 -0400976/**
James Smart3621a712009-04-06 18:47:14 -0400977 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400978 * @vport: pointer to a host virtual N_Port data structure.
979 * @ndlp: pointer to a node-list data structure.
980 * @retry: number of retries to the command IOCB.
981 *
982 * This routine issues a Fabric Login (FLOGI) Request ELS command
983 * for a @vport. The initiator service parameters are put into the payload
984 * of the FLOGI Request IOCB and the top-level callback function pointer
985 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
986 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
987 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
988 *
989 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
990 * will be incremented by 1 for holding the ndlp and the reference to ndlp
991 * will be stored into the context1 field of the IOCB for the completion
992 * callback function to the FLOGI ELS command.
993 *
994 * Return code
995 * 0 - successfully issued flogi iocb for @vport
996 * 1 - failed to issue flogi iocb for @vport
997 **/
dea31012005-04-17 16:05:31 -0500998static int
James Smart2e0fef82007-06-17 19:56:36 -0500999lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001000 uint8_t retry)
1001{
James Smart2e0fef82007-06-17 19:56:36 -05001002 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001003 struct serv_parm *sp;
1004 IOCB_t *icmd;
1005 struct lpfc_iocbq *elsiocb;
1006 struct lpfc_sli_ring *pring;
1007 uint8_t *pcmd;
1008 uint16_t cmdsize;
1009 uint32_t tmo;
1010 int rc;
1011
1012 pring = &phba->sli.ring[LPFC_ELS_RING];
1013
James Smart92d7f7b2007-06-17 19:56:38 -05001014 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001015 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1016 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001017
James Smart488d1462006-03-07 15:02:37 -05001018 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001019 return 1;
dea31012005-04-17 16:05:31 -05001020
1021 icmd = &elsiocb->iocb;
1022 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1023
1024 /* For FLOGI request, remainder of payload is service parameters */
1025 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001026 pcmd += sizeof(uint32_t);
1027 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001028 sp = (struct serv_parm *) pcmd;
1029
1030 /* Setup CSPs accordingly for Fabric */
1031 sp->cmn.e_d_tov = 0;
1032 sp->cmn.w2.r_a_tov = 0;
1033 sp->cls1.classValid = 0;
1034 sp->cls2.seqDelivery = 1;
1035 sp->cls3.seqDelivery = 1;
1036 if (sp->cmn.fcphLow < FC_PH3)
1037 sp->cmn.fcphLow = FC_PH3;
1038 if (sp->cmn.fcphHigh < FC_PH3)
1039 sp->cmn.fcphHigh = FC_PH3;
1040
James Smart6fb120a2009-05-22 14:52:59 -04001041 if (phba->sli_rev == LPFC_SLI_REV4) {
1042 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1043 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1044 /* FLOGI needs to be 3 for WQE FCFI */
1045 /* Set the fcfi to the fcfi we registered with */
1046 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1047 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001048 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001049 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1050 icmd->ulpCt_h = 1;
1051 icmd->ulpCt_l = 0;
1052 }
1053
James Smart858c9f62007-06-17 19:56:39 -05001054 if (phba->fc_topology != TOPOLOGY_LOOP) {
1055 icmd->un.elsreq64.myID = 0;
1056 icmd->un.elsreq64.fl = 1;
1057 }
1058
dea31012005-04-17 16:05:31 -05001059 tmo = phba->fc_ratov;
1060 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001061 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001062 phba->fc_ratov = tmo;
1063
1064 phba->fc_stat.elsXmitFLOGI++;
1065 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001066
1067 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1068 "Issue FLOGI: opt:x%x",
1069 phba->sli3_options, 0, 0);
1070
James Smart92d7f7b2007-06-17 19:56:38 -05001071 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001072 if (rc == IOCB_ERROR) {
1073 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001074 return 1;
dea31012005-04-17 16:05:31 -05001075 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001076 return 0;
dea31012005-04-17 16:05:31 -05001077}
1078
James Smarte59058c2008-08-24 21:49:00 -04001079/**
James Smart3621a712009-04-06 18:47:14 -04001080 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001081 * @phba: pointer to lpfc hba data structure.
1082 *
1083 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1084 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1085 * list and issues an abort IOCB commond on each outstanding IOCB that
1086 * contains a active Fabric_DID ndlp. Note that this function is to issue
1087 * the abort IOCB command on all the outstanding IOCBs, thus when this
1088 * function returns, it does not guarantee all the IOCBs are actually aborted.
1089 *
1090 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001091 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001092 **/
dea31012005-04-17 16:05:31 -05001093int
James Smart2e0fef82007-06-17 19:56:36 -05001094lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001095{
1096 struct lpfc_sli_ring *pring;
1097 struct lpfc_iocbq *iocb, *next_iocb;
1098 struct lpfc_nodelist *ndlp;
1099 IOCB_t *icmd;
1100
1101 /* Abort outstanding I/O on NPort <nlp_DID> */
1102 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001103 "0201 Abort outstanding I/O on NPort x%x\n",
1104 Fabric_DID);
dea31012005-04-17 16:05:31 -05001105
1106 pring = &phba->sli.ring[LPFC_ELS_RING];
1107
1108 /*
1109 * Check the txcmplq for an iocb that matches the nport the driver is
1110 * searching for.
1111 */
James Smart2e0fef82007-06-17 19:56:36 -05001112 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001113 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1114 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001115 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1116 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001117 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001118 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1119 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001120 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001121 }
1122 }
James Smart2e0fef82007-06-17 19:56:36 -05001123 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001124
1125 return 0;
1126}
1127
James Smarte59058c2008-08-24 21:49:00 -04001128/**
James Smart3621a712009-04-06 18:47:14 -04001129 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001130 * @vport: pointer to a host virtual N_Port data structure.
1131 *
1132 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1133 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1134 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1135 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1136 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1137 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1138 * @vport.
1139 *
1140 * Return code
1141 * 0 - failed to issue initial flogi for @vport
1142 * 1 - successfully issued initial flogi for @vport
1143 **/
dea31012005-04-17 16:05:31 -05001144int
James Smart2e0fef82007-06-17 19:56:36 -05001145lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001146{
James Smart2e0fef82007-06-17 19:56:36 -05001147 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001148 struct lpfc_nodelist *ndlp;
1149
James Smart98c9ea52007-10-27 13:37:33 -04001150 vport->port_state = LPFC_FLOGI;
1151 lpfc_set_disctmo(vport);
1152
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001153 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001154 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001155 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001156 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001157 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1158 if (!ndlp)
1159 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001160 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001161 /* Set the node type */
1162 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001163 /* Put ndlp onto node list */
1164 lpfc_enqueue_node(vport, ndlp);
1165 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1166 /* re-setup ndlp without removing from node list */
1167 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1168 if (!ndlp)
1169 return 0;
dea31012005-04-17 16:05:31 -05001170 }
James Smart87af33f2007-10-27 13:37:43 -04001171
James Smart5ac6b302010-10-22 11:05:36 -04001172 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001173 /* This decrement of reference count to node shall kick off
1174 * the release of the node.
1175 */
James Smart329f9bc2007-04-25 09:53:01 -04001176 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001177 return 0;
1178 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001179 return 1;
dea31012005-04-17 16:05:31 -05001180}
1181
James Smarte59058c2008-08-24 21:49:00 -04001182/**
James Smart3621a712009-04-06 18:47:14 -04001183 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001184 * @vport: pointer to a host virtual N_Port data structure.
1185 *
1186 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1187 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1188 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1189 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1190 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1191 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1192 * @vport.
1193 *
1194 * Return code
1195 * 0 - failed to issue initial fdisc for @vport
1196 * 1 - successfully issued initial fdisc for @vport
1197 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001198int
1199lpfc_initial_fdisc(struct lpfc_vport *vport)
1200{
1201 struct lpfc_hba *phba = vport->phba;
1202 struct lpfc_nodelist *ndlp;
1203
1204 /* First look for the Fabric ndlp */
1205 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1206 if (!ndlp) {
1207 /* Cannot find existing Fabric ndlp, so allocate a new one */
1208 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1209 if (!ndlp)
1210 return 0;
1211 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001212 /* Put ndlp onto node list */
1213 lpfc_enqueue_node(vport, ndlp);
1214 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1215 /* re-setup ndlp without removing from node list */
1216 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1217 if (!ndlp)
1218 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001219 }
James Smarte47c9092008-02-08 18:49:26 -05001220
James Smart92d7f7b2007-06-17 19:56:38 -05001221 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001222 /* decrement node reference count to trigger the release of
1223 * the node.
1224 */
James Smart92d7f7b2007-06-17 19:56:38 -05001225 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001226 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001227 }
1228 return 1;
1229}
James Smart87af33f2007-10-27 13:37:43 -04001230
James Smarte59058c2008-08-24 21:49:00 -04001231/**
James Smart3621a712009-04-06 18:47:14 -04001232 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001233 * @vport: pointer to a host virtual N_Port data structure.
1234 *
1235 * This routine checks whether there are more remaining Port Logins
1236 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1237 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1238 * to issue ELS PLOGIs up to the configured discover threads with the
1239 * @vport (@vport->cfg_discovery_threads). The function also decrement
1240 * the @vport's num_disc_node by 1 if it is not already 0.
1241 **/
James Smart87af33f2007-10-27 13:37:43 -04001242void
James Smart2e0fef82007-06-17 19:56:36 -05001243lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001244{
1245 int sentplogi;
1246
James Smart2e0fef82007-06-17 19:56:36 -05001247 if (vport->num_disc_nodes)
1248 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001249
1250 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001251 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1252 "0232 Continue discovery with %d PLOGIs to go "
1253 "Data: x%x x%x x%x\n",
1254 vport->num_disc_nodes, vport->fc_plogi_cnt,
1255 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001256 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001257 if (vport->fc_flag & FC_NLP_MORE)
1258 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1259 sentplogi = lpfc_els_disc_plogi(vport);
1260
dea31012005-04-17 16:05:31 -05001261 return;
1262}
1263
James Smarte59058c2008-08-24 21:49:00 -04001264/**
James Smart3621a712009-04-06 18:47:14 -04001265 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001266 * @phba: pointer to lpfc hba data structure.
1267 * @prsp: pointer to response IOCB payload.
1268 * @ndlp: pointer to a node-list data structure.
1269 *
1270 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1271 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1272 * The following cases are considered N_Port confirmed:
1273 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1274 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1275 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1276 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1277 * 1) if there is a node on vport list other than the @ndlp with the same
1278 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1279 * on that node to release the RPI associated with the node; 2) if there is
1280 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1281 * into, a new node shall be allocated (or activated). In either case, the
1282 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1283 * be released and the new_ndlp shall be put on to the vport node list and
1284 * its pointer returned as the confirmed node.
1285 *
1286 * Note that before the @ndlp got "released", the keepDID from not-matching
1287 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1288 * of the @ndlp. This is because the release of @ndlp is actually to put it
1289 * into an inactive state on the vport node list and the vport node list
1290 * management algorithm does not allow two node with a same DID.
1291 *
1292 * Return code
1293 * pointer to the PLOGI N_Port @ndlp
1294 **/
James Smart488d1462006-03-07 15:02:37 -05001295static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001296lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001297 struct lpfc_nodelist *ndlp)
1298{
James Smart2e0fef82007-06-17 19:56:36 -05001299 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001300 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001301 struct lpfc_rport_data *rdata;
1302 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001303 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001304 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001305 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001306 int put_node;
1307 int put_rport;
James Smart488d1462006-03-07 15:02:37 -05001308
James Smart2fb9bd82006-12-02 13:33:57 -05001309 /* Fabric nodes can have the same WWPN so we don't bother searching
1310 * by WWPN. Just return the ndlp that was given to us.
1311 */
1312 if (ndlp->nlp_type & NLP_FABRIC)
1313 return ndlp;
1314
James Smart92d7f7b2007-06-17 19:56:38 -05001315 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001316 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001317
James Smart685f0bf2007-04-25 09:53:08 -04001318 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001319 * we have for that ndlp. If not, we have some work to do.
1320 */
James Smart2e0fef82007-06-17 19:56:36 -05001321 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001322
James Smarte47c9092008-02-08 18:49:26 -05001323 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001324 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001325
1326 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001327 rc = memcmp(&ndlp->nlp_portname, name,
1328 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001329 if (!rc)
1330 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001331 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1332 if (!new_ndlp)
1333 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001334 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001335 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001336 rc = memcmp(&ndlp->nlp_portname, name,
1337 sizeof(struct lpfc_name));
1338 if (!rc)
1339 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001340 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1341 NLP_STE_UNUSED_NODE);
1342 if (!new_ndlp)
1343 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001344 keepDID = new_ndlp->nlp_DID;
1345 } else
1346 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001347
James Smart2e0fef82007-06-17 19:56:36 -05001348 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001349 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001350 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001351
1352 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1353 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1354 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1355
James Smarte47c9092008-02-08 18:49:26 -05001356 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001357 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001358
James Smart2e0fef82007-06-17 19:56:36 -05001359 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001360 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1361 /* The new_ndlp is replacing ndlp totally, so we need
1362 * to put ndlp on UNUSED list and try to free it.
1363 */
James Smart0ff10d42008-01-11 01:52:36 -05001364
1365 /* Fix up the rport accordingly */
1366 rport = ndlp->rport;
1367 if (rport) {
1368 rdata = rport->dd_data;
1369 if (rdata->pnode == ndlp) {
1370 lpfc_nlp_put(ndlp);
1371 ndlp->rport = NULL;
1372 rdata->pnode = lpfc_nlp_get(new_ndlp);
1373 new_ndlp->rport = rport;
1374 }
1375 new_ndlp->nlp_type = ndlp->nlp_type;
1376 }
James Smart58da1ff2008-04-07 10:15:56 -04001377 /* We shall actually free the ndlp with both nlp_DID and
1378 * nlp_portname fields equals 0 to avoid any ndlp on the
1379 * nodelist never to be used.
1380 */
1381 if (ndlp->nlp_DID == 0) {
1382 spin_lock_irq(&phba->ndlp_lock);
1383 NLP_SET_FREE_REQ(ndlp);
1384 spin_unlock_irq(&phba->ndlp_lock);
1385 }
James Smart0ff10d42008-01-11 01:52:36 -05001386
James Smart58da1ff2008-04-07 10:15:56 -04001387 /* Two ndlps cannot have the same did on the nodelist */
1388 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001389 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001390 }
James Smart92795652006-07-06 15:50:02 -04001391 else {
James Smart2e0fef82007-06-17 19:56:36 -05001392 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001393 /* Two ndlps cannot have the same did */
1394 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001395 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart38b92ef2010-08-04 16:11:39 -04001396 /* Since we are swapping the ndlp passed in with the new one
1397 * and the did has already been swapped, copy over the
1398 * state and names.
1399 */
1400 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1401 sizeof(struct lpfc_name));
1402 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1403 sizeof(struct lpfc_name));
1404 new_ndlp->nlp_state = ndlp->nlp_state;
1405 /* Fix up the rport accordingly */
1406 rport = ndlp->rport;
1407 if (rport) {
1408 rdata = rport->dd_data;
1409 put_node = rdata->pnode != NULL;
1410 put_rport = ndlp->rport != NULL;
1411 rdata->pnode = NULL;
1412 ndlp->rport = NULL;
1413 if (put_node)
1414 lpfc_nlp_put(ndlp);
1415 if (put_rport)
1416 put_device(&rport->dev);
1417 }
James Smart92795652006-07-06 15:50:02 -04001418 }
James Smart488d1462006-03-07 15:02:37 -05001419 return new_ndlp;
1420}
1421
James Smarte59058c2008-08-24 21:49:00 -04001422/**
James Smart3621a712009-04-06 18:47:14 -04001423 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001424 * @vport: pointer to a host virtual N_Port data structure.
1425 *
1426 * This routine checks whether more Registration State Change
1427 * Notifications (RSCNs) came in while the discovery state machine was in
1428 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1429 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1430 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1431 * handling the RSCNs.
1432 **/
James Smart87af33f2007-10-27 13:37:43 -04001433void
1434lpfc_end_rscn(struct lpfc_vport *vport)
1435{
1436 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1437
1438 if (vport->fc_flag & FC_RSCN_MODE) {
1439 /*
1440 * Check to see if more RSCNs came in while we were
1441 * processing this one.
1442 */
1443 if (vport->fc_rscn_id_cnt ||
1444 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1445 lpfc_els_handle_rscn(vport);
1446 else {
1447 spin_lock_irq(shost->host_lock);
1448 vport->fc_flag &= ~FC_RSCN_MODE;
1449 spin_unlock_irq(shost->host_lock);
1450 }
1451 }
1452}
1453
James Smarte59058c2008-08-24 21:49:00 -04001454/**
James Smart3621a712009-04-06 18:47:14 -04001455 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001456 * @phba: pointer to lpfc hba data structure.
1457 * @cmdiocb: pointer to lpfc command iocb data structure.
1458 * @rspiocb: pointer to lpfc response iocb data structure.
1459 *
1460 * This routine is the completion callback function for issuing the Port
1461 * Login (PLOGI) command. For PLOGI completion, there must be an active
1462 * ndlp on the vport node list that matches the remote node ID from the
1463 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1464 * ignored and command IOCB released. The PLOGI response IOCB status is
1465 * checked for error conditons. If there is error status reported, PLOGI
1466 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1467 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1468 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1469 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1470 * there are additional N_Port nodes with the vport that need to perform
1471 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1472 * PLOGIs.
1473 **/
dea31012005-04-17 16:05:31 -05001474static void
James Smart2e0fef82007-06-17 19:56:36 -05001475lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1476 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001477{
James Smart2e0fef82007-06-17 19:56:36 -05001478 struct lpfc_vport *vport = cmdiocb->vport;
1479 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001480 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001481 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001482 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001483 int disc, rc, did, type;
1484
dea31012005-04-17 16:05:31 -05001485 /* we pass cmdiocb to state machine which needs rspiocb as well */
1486 cmdiocb->context_un.rsp_iocb = rspiocb;
1487
1488 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001489 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1490 "PLOGI cmpl: status:x%x/x%x did:x%x",
1491 irsp->ulpStatus, irsp->un.ulpWord[4],
1492 irsp->un.elsreq64.remoteID);
1493
James Smart2e0fef82007-06-17 19:56:36 -05001494 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001495 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001496 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1497 "0136 PLOGI completes to NPort x%x "
1498 "with no ndlp. Data: x%x x%x x%x\n",
1499 irsp->un.elsreq64.remoteID,
1500 irsp->ulpStatus, irsp->un.ulpWord[4],
1501 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001502 goto out;
James Smarted957682007-06-17 19:56:37 -05001503 }
dea31012005-04-17 16:05:31 -05001504
1505 /* Since ndlp can be freed in the disc state machine, note if this node
1506 * is being used during discovery.
1507 */
James Smart2e0fef82007-06-17 19:56:36 -05001508 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001509 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001510 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001511 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001512 rc = 0;
1513
1514 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001515 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1516 "0102 PLOGI completes to NPort x%x "
1517 "Data: x%x x%x x%x x%x x%x\n",
1518 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1519 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001520 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001521 if (lpfc_els_chk_latt(vport)) {
1522 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001523 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001524 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001525 goto out;
1526 }
1527
1528 /* ndlp could be freed in DSM, save these values now */
1529 type = ndlp->nlp_type;
1530 did = ndlp->nlp_DID;
1531
1532 if (irsp->ulpStatus) {
1533 /* Check for retry */
1534 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1535 /* ELS command is being retried */
1536 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001537 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001538 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001539 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001540 }
1541 goto out;
1542 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001543 /* PLOGI failed Don't print the vport to vport rjts */
1544 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1545 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1546 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1547 (phba)->pport->cfg_log_verbose & LOG_ELS)
1548 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001549 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1550 ndlp->nlp_DID, irsp->ulpStatus,
1551 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001552 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001553 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001554 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001555 else
James Smart2e0fef82007-06-17 19:56:36 -05001556 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001557 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001558 } else {
1559 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001560 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001561 cmdiocb->context2)->list.next,
1562 struct lpfc_dmabuf, list);
1563 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001564 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001565 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001566 }
1567
James Smart2e0fef82007-06-17 19:56:36 -05001568 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001569 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001570 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001571
James Smart2e0fef82007-06-17 19:56:36 -05001572 if (vport->num_disc_nodes == 0) {
1573 spin_lock_irq(shost->host_lock);
1574 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1575 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001576
James Smart2e0fef82007-06-17 19:56:36 -05001577 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001578 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001579 }
1580 }
1581
1582out:
1583 lpfc_els_free_iocb(phba, cmdiocb);
1584 return;
1585}
1586
James Smarte59058c2008-08-24 21:49:00 -04001587/**
James Smart3621a712009-04-06 18:47:14 -04001588 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001589 * @vport: pointer to a host virtual N_Port data structure.
1590 * @did: destination port identifier.
1591 * @retry: number of retries to the command IOCB.
1592 *
1593 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1594 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1595 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1596 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1597 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1598 *
1599 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1600 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1601 * will be stored into the context1 field of the IOCB for the completion
1602 * callback function to the PLOGI ELS command.
1603 *
1604 * Return code
1605 * 0 - Successfully issued a plogi for @vport
1606 * 1 - failed to issue a plogi for @vport
1607 **/
dea31012005-04-17 16:05:31 -05001608int
James Smart2e0fef82007-06-17 19:56:36 -05001609lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001610{
James Smart2e0fef82007-06-17 19:56:36 -05001611 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001612 struct serv_parm *sp;
1613 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001614 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001615 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001616 struct lpfc_sli *psli;
1617 uint8_t *pcmd;
1618 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001619 int ret;
dea31012005-04-17 16:05:31 -05001620
1621 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001622
James Smart98c9ea52007-10-27 13:37:33 -04001623 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001624 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1625 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001626
James Smarte47c9092008-02-08 18:49:26 -05001627 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001628 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001629 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001630 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001631 if (!elsiocb)
1632 return 1;
dea31012005-04-17 16:05:31 -05001633
1634 icmd = &elsiocb->iocb;
1635 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1636
1637 /* For PLOGI request, remainder of payload is service parameters */
1638 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001639 pcmd += sizeof(uint32_t);
1640 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001641 sp = (struct serv_parm *) pcmd;
1642
James Smart5ac6b302010-10-22 11:05:36 -04001643 /*
1644 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1645 * to device on remote loops work.
1646 */
1647 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1648 sp->cmn.altBbCredit = 1;
1649
dea31012005-04-17 16:05:31 -05001650 if (sp->cmn.fcphLow < FC_PH_4_3)
1651 sp->cmn.fcphLow = FC_PH_4_3;
1652
1653 if (sp->cmn.fcphHigh < FC_PH3)
1654 sp->cmn.fcphHigh = FC_PH3;
1655
James Smart858c9f62007-06-17 19:56:39 -05001656 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1657 "Issue PLOGI: did:x%x",
1658 did, 0, 0);
1659
dea31012005-04-17 16:05:31 -05001660 phba->fc_stat.elsXmitPLOGI++;
1661 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001662 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001663
1664 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001665 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001666 return 1;
dea31012005-04-17 16:05:31 -05001667 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001668 return 0;
dea31012005-04-17 16:05:31 -05001669}
1670
James Smarte59058c2008-08-24 21:49:00 -04001671/**
James Smart3621a712009-04-06 18:47:14 -04001672 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001673 * @phba: pointer to lpfc hba data structure.
1674 * @cmdiocb: pointer to lpfc command iocb data structure.
1675 * @rspiocb: pointer to lpfc response iocb data structure.
1676 *
1677 * This routine is the completion callback function for a Process Login
1678 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1679 * status. If there is error status reported, PRLI retry shall be attempted
1680 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1681 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1682 * ndlp to mark the PRLI completion.
1683 **/
dea31012005-04-17 16:05:31 -05001684static void
James Smart2e0fef82007-06-17 19:56:36 -05001685lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1686 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001687{
James Smart2e0fef82007-06-17 19:56:36 -05001688 struct lpfc_vport *vport = cmdiocb->vport;
1689 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001690 IOCB_t *irsp;
1691 struct lpfc_sli *psli;
1692 struct lpfc_nodelist *ndlp;
1693
1694 psli = &phba->sli;
1695 /* we pass cmdiocb to state machine which needs rspiocb as well */
1696 cmdiocb->context_un.rsp_iocb = rspiocb;
1697
1698 irsp = &(rspiocb->iocb);
1699 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001700 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001701 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001702 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001703
James Smart858c9f62007-06-17 19:56:39 -05001704 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1705 "PRLI cmpl: status:x%x/x%x did:x%x",
1706 irsp->ulpStatus, irsp->un.ulpWord[4],
1707 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001708 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001709 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1710 "0103 PRLI completes to NPort x%x "
1711 "Data: x%x x%x x%x x%x\n",
1712 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1713 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001714
James Smart2e0fef82007-06-17 19:56:36 -05001715 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001716 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001717 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001718 goto out;
1719
1720 if (irsp->ulpStatus) {
1721 /* Check for retry */
1722 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1723 /* ELS command is being retried */
1724 goto out;
1725 }
1726 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001727 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1728 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1729 ndlp->nlp_DID, irsp->ulpStatus,
1730 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001731 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001732 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001733 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001734 else
James Smart2e0fef82007-06-17 19:56:36 -05001735 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001736 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001737 } else
dea31012005-04-17 16:05:31 -05001738 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001739 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001740 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001741out:
1742 lpfc_els_free_iocb(phba, cmdiocb);
1743 return;
1744}
1745
James Smarte59058c2008-08-24 21:49:00 -04001746/**
James Smart3621a712009-04-06 18:47:14 -04001747 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001748 * @vport: pointer to a host virtual N_Port data structure.
1749 * @ndlp: pointer to a node-list data structure.
1750 * @retry: number of retries to the command IOCB.
1751 *
1752 * This routine issues a Process Login (PRLI) ELS command for the
1753 * @vport. The PRLI service parameters are set up in the payload of the
1754 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1755 * is put to the IOCB completion callback func field before invoking the
1756 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1757 *
1758 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1759 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1760 * will be stored into the context1 field of the IOCB for the completion
1761 * callback function to the PRLI ELS command.
1762 *
1763 * Return code
1764 * 0 - successfully issued prli iocb command for @vport
1765 * 1 - failed to issue prli iocb command for @vport
1766 **/
dea31012005-04-17 16:05:31 -05001767int
James Smart2e0fef82007-06-17 19:56:36 -05001768lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001769 uint8_t retry)
1770{
James Smart2e0fef82007-06-17 19:56:36 -05001771 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1772 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001773 PRLI *npr;
1774 IOCB_t *icmd;
1775 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001776 uint8_t *pcmd;
1777 uint16_t cmdsize;
1778
James Smart92d7f7b2007-06-17 19:56:38 -05001779 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001780 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1781 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001782 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001783 return 1;
dea31012005-04-17 16:05:31 -05001784
1785 icmd = &elsiocb->iocb;
1786 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1787
1788 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001789 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001790 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001791 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001792
1793 /* For PRLI, remainder of payload is PRLI parameter page */
1794 npr = (PRLI *) pcmd;
1795 /*
1796 * If our firmware version is 3.20 or later,
1797 * set the following bits for FC-TAPE support.
1798 */
1799 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1800 npr->ConfmComplAllowed = 1;
1801 npr->Retry = 1;
1802 npr->TaskRetryIdReq = 1;
1803 }
1804 npr->estabImagePair = 1;
1805 npr->readXferRdyDis = 1;
1806
1807 /* For FCP support */
1808 npr->prliType = PRLI_FCP_TYPE;
1809 npr->initiatorFunc = 1;
1810
James Smart858c9f62007-06-17 19:56:39 -05001811 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1812 "Issue PRLI: did:x%x",
1813 ndlp->nlp_DID, 0, 0);
1814
dea31012005-04-17 16:05:31 -05001815 phba->fc_stat.elsXmitPRLI++;
1816 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001817 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001818 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001819 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001820 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1821 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001822 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001823 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001824 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001825 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001826 return 1;
dea31012005-04-17 16:05:31 -05001827 }
James Smart2e0fef82007-06-17 19:56:36 -05001828 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001829 return 0;
dea31012005-04-17 16:05:31 -05001830}
1831
James Smarte59058c2008-08-24 21:49:00 -04001832/**
James Smart3621a712009-04-06 18:47:14 -04001833 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001834 * @vport: pointer to a host virtual N_Port data structure.
1835 *
1836 * This routine performs Registration State Change Notification (RSCN)
1837 * discovery for a @vport. If the @vport's node port recovery count is not
1838 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1839 * the nodes that need recovery. If none of the PLOGI were needed through
1840 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1841 * invoked to check and handle possible more RSCN came in during the period
1842 * of processing the current ones.
1843 **/
1844static void
1845lpfc_rscn_disc(struct lpfc_vport *vport)
1846{
1847 lpfc_can_disctmo(vport);
1848
1849 /* RSCN discovery */
1850 /* go thru NPR nodes and issue ELS PLOGIs */
1851 if (vport->fc_npr_cnt)
1852 if (lpfc_els_disc_plogi(vport))
1853 return;
1854
1855 lpfc_end_rscn(vport);
1856}
1857
1858/**
James Smart3621a712009-04-06 18:47:14 -04001859 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001860 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1861 *
1862 * This function is called when the final ADISC is completed during discovery.
1863 * This function handles clearing link attention or issuing reg_vpi depending
1864 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1865 * discovery.
1866 * This function is called with no locks held.
1867 **/
1868static void
1869lpfc_adisc_done(struct lpfc_vport *vport)
1870{
1871 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1872 struct lpfc_hba *phba = vport->phba;
1873
1874 /*
1875 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1876 * and continue discovery.
1877 */
1878 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04001879 !(vport->fc_flag & FC_RSCN_MODE) &&
1880 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04001881 lpfc_issue_reg_vpi(phba, vport);
1882 return;
1883 }
1884 /*
1885 * For SLI2, we need to set port_state to READY
1886 * and continue discovery.
1887 */
1888 if (vport->port_state < LPFC_VPORT_READY) {
1889 /* If we get here, there is nothing to ADISC */
1890 if (vport->port_type == LPFC_PHYSICAL_PORT)
1891 lpfc_issue_clear_la(phba, vport);
1892 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1893 vport->num_disc_nodes = 0;
1894 /* go thru NPR list, issue ELS PLOGIs */
1895 if (vport->fc_npr_cnt)
1896 lpfc_els_disc_plogi(vport);
1897 if (!vport->num_disc_nodes) {
1898 spin_lock_irq(shost->host_lock);
1899 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1900 spin_unlock_irq(shost->host_lock);
1901 lpfc_can_disctmo(vport);
1902 lpfc_end_rscn(vport);
1903 }
1904 }
1905 vport->port_state = LPFC_VPORT_READY;
1906 } else
1907 lpfc_rscn_disc(vport);
1908}
1909
1910/**
James Smart3621a712009-04-06 18:47:14 -04001911 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001912 * @vport: pointer to a host virtual N_Port data structure.
1913 *
1914 * This routine determines whether there are more ndlps on a @vport
1915 * node list need to have Address Discover (ADISC) issued. If so, it will
1916 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1917 * remaining nodes which need to have ADISC sent.
1918 **/
James Smart0ff10d42008-01-11 01:52:36 -05001919void
James Smart2e0fef82007-06-17 19:56:36 -05001920lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001921{
1922 int sentadisc;
1923
James Smart2e0fef82007-06-17 19:56:36 -05001924 if (vport->num_disc_nodes)
1925 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001926 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001927 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1928 "0210 Continue discovery with %d ADISCs to go "
1929 "Data: x%x x%x x%x\n",
1930 vport->num_disc_nodes, vport->fc_adisc_cnt,
1931 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001932 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001933 if (vport->fc_flag & FC_NLP_MORE) {
1934 lpfc_set_disctmo(vport);
1935 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1936 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001937 }
James Smart90160e02008-08-24 21:49:45 -04001938 if (!vport->num_disc_nodes)
1939 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001940 return;
1941}
1942
James Smarte59058c2008-08-24 21:49:00 -04001943/**
James Smart3621a712009-04-06 18:47:14 -04001944 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04001945 * @phba: pointer to lpfc hba data structure.
1946 * @cmdiocb: pointer to lpfc command iocb data structure.
1947 * @rspiocb: pointer to lpfc response iocb data structure.
1948 *
1949 * This routine is the completion function for issuing the Address Discover
1950 * (ADISC) command. It first checks to see whether link went down during
1951 * the discovery process. If so, the node will be marked as node port
1952 * recovery for issuing discover IOCB by the link attention handler and
1953 * exit. Otherwise, the response status is checked. If error was reported
1954 * in the response status, the ADISC command shall be retried by invoking
1955 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1956 * the response status, the state machine is invoked to set transition
1957 * with respect to NLP_EVT_CMPL_ADISC event.
1958 **/
dea31012005-04-17 16:05:31 -05001959static void
James Smart2e0fef82007-06-17 19:56:36 -05001960lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1961 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001962{
James Smart2e0fef82007-06-17 19:56:36 -05001963 struct lpfc_vport *vport = cmdiocb->vport;
1964 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001965 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001966 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001967 int disc;
dea31012005-04-17 16:05:31 -05001968
1969 /* we pass cmdiocb to state machine which needs rspiocb as well */
1970 cmdiocb->context_un.rsp_iocb = rspiocb;
1971
1972 irsp = &(rspiocb->iocb);
1973 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001974
James Smart858c9f62007-06-17 19:56:39 -05001975 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1976 "ADISC cmpl: status:x%x/x%x did:x%x",
1977 irsp->ulpStatus, irsp->un.ulpWord[4],
1978 ndlp->nlp_DID);
1979
dea31012005-04-17 16:05:31 -05001980 /* Since ndlp can be freed in the disc state machine, note if this node
1981 * is being used during discovery.
1982 */
James Smart2e0fef82007-06-17 19:56:36 -05001983 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001984 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001985 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001986 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001987 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001988 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1989 "0104 ADISC completes to NPort x%x "
1990 "Data: x%x x%x x%x x%x x%x\n",
1991 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1992 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001993 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001994 if (lpfc_els_chk_latt(vport)) {
1995 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001996 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001997 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001998 goto out;
1999 }
2000
2001 if (irsp->ulpStatus) {
2002 /* Check for retry */
2003 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2004 /* ELS command is being retried */
2005 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002006 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002007 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002008 spin_unlock_irq(shost->host_lock);
2009 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002010 }
2011 goto out;
2012 }
2013 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002014 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2015 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2016 ndlp->nlp_DID, irsp->ulpStatus,
2017 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002018 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002019 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002020 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002021 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002022 } else
dea31012005-04-17 16:05:31 -05002023 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002024 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002025 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002026
James Smart90160e02008-08-24 21:49:45 -04002027 /* Check to see if there are more ADISCs to be sent */
2028 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002029 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002030out:
2031 lpfc_els_free_iocb(phba, cmdiocb);
2032 return;
2033}
2034
James Smarte59058c2008-08-24 21:49:00 -04002035/**
James Smart3621a712009-04-06 18:47:14 -04002036 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002037 * @vport: pointer to a virtual N_Port data structure.
2038 * @ndlp: pointer to a node-list data structure.
2039 * @retry: number of retries to the command IOCB.
2040 *
2041 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2042 * @vport. It prepares the payload of the ADISC ELS command, updates the
2043 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2044 * to issue the ADISC ELS command.
2045 *
2046 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2047 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2048 * will be stored into the context1 field of the IOCB for the completion
2049 * callback function to the ADISC ELS command.
2050 *
2051 * Return code
2052 * 0 - successfully issued adisc
2053 * 1 - failed to issue adisc
2054 **/
dea31012005-04-17 16:05:31 -05002055int
James Smart2e0fef82007-06-17 19:56:36 -05002056lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002057 uint8_t retry)
2058{
James Smart2e0fef82007-06-17 19:56:36 -05002059 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2060 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002061 ADISC *ap;
2062 IOCB_t *icmd;
2063 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002064 uint8_t *pcmd;
2065 uint16_t cmdsize;
2066
James Smart92d7f7b2007-06-17 19:56:38 -05002067 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002068 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2069 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002070 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002071 return 1;
dea31012005-04-17 16:05:31 -05002072
2073 icmd = &elsiocb->iocb;
2074 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2075
2076 /* For ADISC request, remainder of payload is service parameters */
2077 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002078 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002079
2080 /* Fill in ADISC payload */
2081 ap = (ADISC *) pcmd;
2082 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002083 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2084 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002085 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002086
James Smart858c9f62007-06-17 19:56:39 -05002087 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2088 "Issue ADISC: did:x%x",
2089 ndlp->nlp_DID, 0, 0);
2090
dea31012005-04-17 16:05:31 -05002091 phba->fc_stat.elsXmitADISC++;
2092 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002093 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002094 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002095 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002096 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2097 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002098 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002099 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002100 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002101 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002102 return 1;
dea31012005-04-17 16:05:31 -05002103 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002104 return 0;
dea31012005-04-17 16:05:31 -05002105}
2106
James Smarte59058c2008-08-24 21:49:00 -04002107/**
James Smart3621a712009-04-06 18:47:14 -04002108 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002109 * @phba: pointer to lpfc hba data structure.
2110 * @cmdiocb: pointer to lpfc command iocb data structure.
2111 * @rspiocb: pointer to lpfc response iocb data structure.
2112 *
2113 * This routine is the completion function for issuing the ELS Logout (LOGO)
2114 * command. If no error status was reported from the LOGO response, the
2115 * state machine of the associated ndlp shall be invoked for transition with
2116 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2117 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2118 **/
dea31012005-04-17 16:05:31 -05002119static void
James Smart2e0fef82007-06-17 19:56:36 -05002120lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2121 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002122{
James Smart2e0fef82007-06-17 19:56:36 -05002123 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2124 struct lpfc_vport *vport = ndlp->vport;
2125 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002126 IOCB_t *irsp;
2127 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002128
2129 psli = &phba->sli;
2130 /* we pass cmdiocb to state machine which needs rspiocb as well */
2131 cmdiocb->context_un.rsp_iocb = rspiocb;
2132
2133 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002134 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002135 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002136 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002137
James Smart858c9f62007-06-17 19:56:39 -05002138 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2139 "LOGO cmpl: status:x%x/x%x did:x%x",
2140 irsp->ulpStatus, irsp->un.ulpWord[4],
2141 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002142 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002143 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2144 "0105 LOGO completes to NPort x%x "
2145 "Data: x%x x%x x%x x%x\n",
2146 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2147 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002148 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002149 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002150 goto out;
2151
James Smart92d7f7b2007-06-17 19:56:38 -05002152 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2153 /* NLP_EVT_DEVICE_RM should unregister the RPI
2154 * which should abort all outstanding IOs.
2155 */
2156 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2157 NLP_EVT_DEVICE_RM);
2158 goto out;
2159 }
2160
dea31012005-04-17 16:05:31 -05002161 if (irsp->ulpStatus) {
2162 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002163 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002164 /* ELS command is being retried */
2165 goto out;
dea31012005-04-17 16:05:31 -05002166 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002167 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2168 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2169 ndlp->nlp_DID, irsp->ulpStatus,
2170 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002171 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002172 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002173 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002174 else
James Smart2e0fef82007-06-17 19:56:36 -05002175 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002176 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002177 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002178 /* Good status, call state machine.
2179 * This will unregister the rpi if needed.
2180 */
James Smart2e0fef82007-06-17 19:56:36 -05002181 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002182 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002183out:
2184 lpfc_els_free_iocb(phba, cmdiocb);
2185 return;
2186}
2187
James Smarte59058c2008-08-24 21:49:00 -04002188/**
James Smart3621a712009-04-06 18:47:14 -04002189 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002190 * @vport: pointer to a virtual N_Port data structure.
2191 * @ndlp: pointer to a node-list data structure.
2192 * @retry: number of retries to the command IOCB.
2193 *
2194 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2195 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2196 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2197 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2198 *
2199 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2200 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2201 * will be stored into the context1 field of the IOCB for the completion
2202 * callback function to the LOGO ELS command.
2203 *
2204 * Return code
2205 * 0 - successfully issued logo
2206 * 1 - failed to issue logo
2207 **/
dea31012005-04-17 16:05:31 -05002208int
James Smart2e0fef82007-06-17 19:56:36 -05002209lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002210 uint8_t retry)
2211{
James Smart2e0fef82007-06-17 19:56:36 -05002212 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2213 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002214 IOCB_t *icmd;
2215 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002216 uint8_t *pcmd;
2217 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002218 int rc;
dea31012005-04-17 16:05:31 -05002219
James Smart98c9ea52007-10-27 13:37:33 -04002220 spin_lock_irq(shost->host_lock);
2221 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2222 spin_unlock_irq(shost->host_lock);
2223 return 0;
2224 }
2225 spin_unlock_irq(shost->host_lock);
2226
James Smart92d7f7b2007-06-17 19:56:38 -05002227 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002228 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2229 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002230 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002231 return 1;
dea31012005-04-17 16:05:31 -05002232
2233 icmd = &elsiocb->iocb;
2234 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2235 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002236 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002237
2238 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002239 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002240 pcmd += sizeof(uint32_t);
2241 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002242
James Smart858c9f62007-06-17 19:56:39 -05002243 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2244 "Issue LOGO: did:x%x",
2245 ndlp->nlp_DID, 0, 0);
2246
dea31012005-04-17 16:05:31 -05002247 phba->fc_stat.elsXmitLOGO++;
2248 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002249 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002250 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002251 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002252 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002253
2254 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002255 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002256 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002257 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002258 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002259 return 1;
dea31012005-04-17 16:05:31 -05002260 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002261 return 0;
dea31012005-04-17 16:05:31 -05002262}
2263
James Smarte59058c2008-08-24 21:49:00 -04002264/**
James Smart3621a712009-04-06 18:47:14 -04002265 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002266 * @phba: pointer to lpfc hba data structure.
2267 * @cmdiocb: pointer to lpfc command iocb data structure.
2268 * @rspiocb: pointer to lpfc response iocb data structure.
2269 *
2270 * This routine is a generic completion callback function for ELS commands.
2271 * Specifically, it is the callback function which does not need to perform
2272 * any command specific operations. It is currently used by the ELS command
2273 * issuing routines for the ELS State Change Request (SCR),
2274 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2275 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2276 * certain debug loggings, this callback function simply invokes the
2277 * lpfc_els_chk_latt() routine to check whether link went down during the
2278 * discovery process.
2279 **/
dea31012005-04-17 16:05:31 -05002280static void
James Smart2e0fef82007-06-17 19:56:36 -05002281lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2282 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002283{
James Smart2e0fef82007-06-17 19:56:36 -05002284 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002285 IOCB_t *irsp;
2286
2287 irsp = &rspiocb->iocb;
2288
James Smart858c9f62007-06-17 19:56:39 -05002289 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2290 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2291 irsp->ulpStatus, irsp->un.ulpWord[4],
2292 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002293 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002294 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2295 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2296 irsp->ulpIoTag, irsp->ulpStatus,
2297 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002298 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002299 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002300 lpfc_els_free_iocb(phba, cmdiocb);
2301 return;
2302}
2303
James Smarte59058c2008-08-24 21:49:00 -04002304/**
James Smart3621a712009-04-06 18:47:14 -04002305 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002306 * @vport: pointer to a host virtual N_Port data structure.
2307 * @nportid: N_Port identifier to the remote node.
2308 * @retry: number of retries to the command IOCB.
2309 *
2310 * This routine issues a State Change Request (SCR) to a fabric node
2311 * on a @vport. The remote node @nportid is passed into the function. It
2312 * first search the @vport node list to find the matching ndlp. If no such
2313 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2314 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2315 * routine is invoked to send the SCR IOCB.
2316 *
2317 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2318 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2319 * will be stored into the context1 field of the IOCB for the completion
2320 * callback function to the SCR ELS command.
2321 *
2322 * Return code
2323 * 0 - Successfully issued scr command
2324 * 1 - Failed to issue scr command
2325 **/
dea31012005-04-17 16:05:31 -05002326int
James Smart2e0fef82007-06-17 19:56:36 -05002327lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002328{
James Smart2e0fef82007-06-17 19:56:36 -05002329 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002330 IOCB_t *icmd;
2331 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002332 struct lpfc_sli *psli;
2333 uint8_t *pcmd;
2334 uint16_t cmdsize;
2335 struct lpfc_nodelist *ndlp;
2336
2337 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002338 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002339
James Smarte47c9092008-02-08 18:49:26 -05002340 ndlp = lpfc_findnode_did(vport, nportid);
2341 if (!ndlp) {
2342 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2343 if (!ndlp)
2344 return 1;
2345 lpfc_nlp_init(vport, ndlp, nportid);
2346 lpfc_enqueue_node(vport, ndlp);
2347 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2348 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2349 if (!ndlp)
2350 return 1;
2351 }
dea31012005-04-17 16:05:31 -05002352
James Smart2e0fef82007-06-17 19:56:36 -05002353 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2354 ndlp->nlp_DID, ELS_CMD_SCR);
2355
James Smart488d1462006-03-07 15:02:37 -05002356 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002357 /* This will trigger the release of the node just
2358 * allocated
2359 */
James Smart329f9bc2007-04-25 09:53:01 -04002360 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002361 return 1;
dea31012005-04-17 16:05:31 -05002362 }
2363
2364 icmd = &elsiocb->iocb;
2365 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2366
2367 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002368 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002369
2370 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002371 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002372 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2373
James Smart858c9f62007-06-17 19:56:39 -05002374 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2375 "Issue SCR: did:x%x",
2376 ndlp->nlp_DID, 0, 0);
2377
dea31012005-04-17 16:05:31 -05002378 phba->fc_stat.elsXmitSCR++;
2379 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002380 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2381 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002382 /* The additional lpfc_nlp_put will cause the following
2383 * lpfc_els_free_iocb routine to trigger the rlease of
2384 * the node.
2385 */
James Smart329f9bc2007-04-25 09:53:01 -04002386 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002387 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002388 return 1;
dea31012005-04-17 16:05:31 -05002389 }
James Smartfa4066b2008-01-11 01:53:27 -05002390 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2391 * trigger the release of node.
2392 */
James Smart329f9bc2007-04-25 09:53:01 -04002393 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002394 return 0;
dea31012005-04-17 16:05:31 -05002395}
2396
James Smarte59058c2008-08-24 21:49:00 -04002397/**
James Smart3621a712009-04-06 18:47:14 -04002398 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002399 * @vport: pointer to a host virtual N_Port data structure.
2400 * @nportid: N_Port identifier to the remote node.
2401 * @retry: number of retries to the command IOCB.
2402 *
2403 * This routine issues a Fibre Channel Address Resolution Response
2404 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2405 * is passed into the function. It first search the @vport node list to find
2406 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2407 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2408 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2409 *
2410 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2411 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2412 * will be stored into the context1 field of the IOCB for the completion
2413 * callback function to the PARPR ELS command.
2414 *
2415 * Return code
2416 * 0 - Successfully issued farpr command
2417 * 1 - Failed to issue farpr command
2418 **/
dea31012005-04-17 16:05:31 -05002419static int
James Smart2e0fef82007-06-17 19:56:36 -05002420lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002421{
James Smart2e0fef82007-06-17 19:56:36 -05002422 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002423 IOCB_t *icmd;
2424 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002425 struct lpfc_sli *psli;
2426 FARP *fp;
2427 uint8_t *pcmd;
2428 uint32_t *lp;
2429 uint16_t cmdsize;
2430 struct lpfc_nodelist *ondlp;
2431 struct lpfc_nodelist *ndlp;
2432
2433 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002434 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002435
James Smarte47c9092008-02-08 18:49:26 -05002436 ndlp = lpfc_findnode_did(vport, nportid);
2437 if (!ndlp) {
2438 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2439 if (!ndlp)
2440 return 1;
2441 lpfc_nlp_init(vport, ndlp, nportid);
2442 lpfc_enqueue_node(vport, ndlp);
2443 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2444 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2445 if (!ndlp)
2446 return 1;
2447 }
James Smart2e0fef82007-06-17 19:56:36 -05002448
2449 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2450 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002451 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002452 /* This will trigger the release of the node just
2453 * allocated
2454 */
James Smart329f9bc2007-04-25 09:53:01 -04002455 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002456 return 1;
dea31012005-04-17 16:05:31 -05002457 }
2458
2459 icmd = &elsiocb->iocb;
2460 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2461
2462 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002463 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002464
2465 /* Fill in FARPR payload */
2466 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002467 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002468 lp = (uint32_t *) pcmd;
2469 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002470 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002471 fp->Rflags = 0;
2472 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2473
James Smart92d7f7b2007-06-17 19:56:38 -05002474 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2475 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002476 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002477 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002478 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002479 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002480 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002481 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002482 }
2483
James Smart858c9f62007-06-17 19:56:39 -05002484 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2485 "Issue FARPR: did:x%x",
2486 ndlp->nlp_DID, 0, 0);
2487
dea31012005-04-17 16:05:31 -05002488 phba->fc_stat.elsXmitFARPR++;
2489 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002490 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2491 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002492 /* The additional lpfc_nlp_put will cause the following
2493 * lpfc_els_free_iocb routine to trigger the release of
2494 * the node.
2495 */
James Smart329f9bc2007-04-25 09:53:01 -04002496 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002497 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002498 return 1;
dea31012005-04-17 16:05:31 -05002499 }
James Smartfa4066b2008-01-11 01:53:27 -05002500 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2501 * trigger the release of the node.
2502 */
James Smart329f9bc2007-04-25 09:53:01 -04002503 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002504 return 0;
dea31012005-04-17 16:05:31 -05002505}
2506
James Smarte59058c2008-08-24 21:49:00 -04002507/**
James Smart3621a712009-04-06 18:47:14 -04002508 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002509 * @vport: pointer to a host virtual N_Port data structure.
2510 * @nlp: pointer to a node-list data structure.
2511 *
2512 * This routine cancels the timer with a delayed IOCB-command retry for
2513 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2514 * removes the ELS retry event if it presents. In addition, if the
2515 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2516 * commands are sent for the @vport's nodes that require issuing discovery
2517 * ADISC.
2518 **/
dea31012005-04-17 16:05:31 -05002519void
James Smart2e0fef82007-06-17 19:56:36 -05002520lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002521{
James Smart2e0fef82007-06-17 19:56:36 -05002522 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002523 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002524
James Smart0d2b6b82008-06-14 22:52:47 -04002525 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2526 return;
James Smart2e0fef82007-06-17 19:56:36 -05002527 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002528 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002529 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002530 del_timer_sync(&nlp->nlp_delayfunc);
2531 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002532 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002533 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002534 /* Decrement nlp reference count held for the delayed retry */
2535 evtp = &nlp->els_retry_evt;
2536 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2537 }
James Smartfdcebe22006-03-07 15:04:01 -05002538 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002539 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002540 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002541 spin_unlock_irq(shost->host_lock);
2542 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002543 if (vport->port_state < LPFC_VPORT_READY) {
2544 /* Check if there are more ADISCs to be sent */
2545 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002546 } else {
2547 /* Check if there are more PLOGIs to be sent */
2548 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002549 if (vport->num_disc_nodes == 0) {
2550 spin_lock_irq(shost->host_lock);
2551 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2552 spin_unlock_irq(shost->host_lock);
2553 lpfc_can_disctmo(vport);
2554 lpfc_end_rscn(vport);
2555 }
James Smartfdcebe22006-03-07 15:04:01 -05002556 }
2557 }
2558 }
2559 return;
2560}
2561
James Smarte59058c2008-08-24 21:49:00 -04002562/**
James Smart3621a712009-04-06 18:47:14 -04002563 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002564 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2565 *
2566 * This routine is invoked by the ndlp delayed-function timer to check
2567 * whether there is any pending ELS retry event(s) with the node. If not, it
2568 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2569 * adds the delayed events to the HBA work list and invokes the
2570 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2571 * event. Note that lpfc_nlp_get() is called before posting the event to
2572 * the work list to hold reference count of ndlp so that it guarantees the
2573 * reference to ndlp will still be available when the worker thread gets
2574 * to the event associated with the ndlp.
2575 **/
James Smartfdcebe22006-03-07 15:04:01 -05002576void
dea31012005-04-17 16:05:31 -05002577lpfc_els_retry_delay(unsigned long ptr)
2578{
James Smart2e0fef82007-06-17 19:56:36 -05002579 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2580 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002581 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002582 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002583 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002584
James Smart92d7f7b2007-06-17 19:56:38 -05002585 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002586 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002587 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002588 return;
2589 }
2590
James Smartfa4066b2008-01-11 01:53:27 -05002591 /* We need to hold the node by incrementing the reference
2592 * count until the queued work is done
2593 */
2594 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002595 if (evtp->evt_arg1) {
2596 evtp->evt = LPFC_EVT_ELS_RETRY;
2597 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002598 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002599 }
James Smart92d7f7b2007-06-17 19:56:38 -05002600 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002601 return;
2602}
2603
James Smarte59058c2008-08-24 21:49:00 -04002604/**
James Smart3621a712009-04-06 18:47:14 -04002605 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002606 * @ndlp: pointer to a node-list data structure.
2607 *
2608 * This routine is the worker-thread handler for processing the @ndlp delayed
2609 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2610 * the last ELS command from the associated ndlp and invokes the proper ELS
2611 * function according to the delayed ELS command to retry the command.
2612 **/
dea31012005-04-17 16:05:31 -05002613void
2614lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2615{
James Smart2e0fef82007-06-17 19:56:36 -05002616 struct lpfc_vport *vport = ndlp->vport;
2617 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2618 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002619
James Smart2e0fef82007-06-17 19:56:36 -05002620 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002621 did = ndlp->nlp_DID;
2622 cmd = ndlp->nlp_last_elscmd;
2623 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002624
2625 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002626 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002627 return;
2628 }
2629
2630 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002631 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002632 /*
2633 * If a discovery event readded nlp_delayfunc after timer
2634 * firing and before processing the timer, cancel the
2635 * nlp_delayfunc.
2636 */
2637 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002638 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002639 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002640
2641 switch (cmd) {
2642 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002643 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002644 break;
2645 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002646 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002647 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002648 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002649 }
dea31012005-04-17 16:05:31 -05002650 break;
2651 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002652 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002653 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002654 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002655 }
dea31012005-04-17 16:05:31 -05002656 break;
2657 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002658 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002659 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002660 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002661 }
dea31012005-04-17 16:05:31 -05002662 break;
2663 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002664 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002665 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002666 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002667 }
dea31012005-04-17 16:05:31 -05002668 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002669 case ELS_CMD_FDISC:
2670 lpfc_issue_els_fdisc(vport, ndlp, retry);
2671 break;
dea31012005-04-17 16:05:31 -05002672 }
2673 return;
2674}
2675
James Smarte59058c2008-08-24 21:49:00 -04002676/**
James Smart3621a712009-04-06 18:47:14 -04002677 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002678 * @phba: pointer to lpfc hba data structure.
2679 * @cmdiocb: pointer to lpfc command iocb data structure.
2680 * @rspiocb: pointer to lpfc response iocb data structure.
2681 *
2682 * This routine makes a retry decision on an ELS command IOCB, which has
2683 * failed. The following ELS IOCBs use this function for retrying the command
2684 * when previously issued command responsed with error status: FLOGI, PLOGI,
2685 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2686 * returned error status, it makes the decision whether a retry shall be
2687 * issued for the command, and whether a retry shall be made immediately or
2688 * delayed. In the former case, the corresponding ELS command issuing-function
2689 * is called to retry the command. In the later case, the ELS command shall
2690 * be posted to the ndlp delayed event and delayed function timer set to the
2691 * ndlp for the delayed command issusing.
2692 *
2693 * Return code
2694 * 0 - No retry of els command is made
2695 * 1 - Immediate or delayed retry of els command is made
2696 **/
dea31012005-04-17 16:05:31 -05002697static int
James Smart2e0fef82007-06-17 19:56:36 -05002698lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2699 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002700{
James Smart2e0fef82007-06-17 19:56:36 -05002701 struct lpfc_vport *vport = cmdiocb->vport;
2702 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2703 IOCB_t *irsp = &rspiocb->iocb;
2704 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2705 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002706 uint32_t *elscmd;
2707 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002708 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002709 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002710 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002711 uint32_t did;
dea31012005-04-17 16:05:31 -05002712
James Smart488d1462006-03-07 15:02:37 -05002713
dea31012005-04-17 16:05:31 -05002714 /* Note: context2 may be 0 for internal driver abort
2715 * of delays ELS command.
2716 */
2717
2718 if (pcmd && pcmd->virt) {
2719 elscmd = (uint32_t *) (pcmd->virt);
2720 cmd = *elscmd++;
2721 }
2722
James Smarte47c9092008-02-08 18:49:26 -05002723 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002724 did = ndlp->nlp_DID;
2725 else {
2726 /* We should only hit this case for retrying PLOGI */
2727 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002728 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002729 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2730 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002731 return 1;
2732 }
2733
James Smart858c9f62007-06-17 19:56:39 -05002734 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2735 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2736 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2737
dea31012005-04-17 16:05:31 -05002738 switch (irsp->ulpStatus) {
2739 case IOSTAT_FCP_RSP_ERROR:
2740 case IOSTAT_REMOTE_STOP:
2741 break;
2742
2743 case IOSTAT_LOCAL_REJECT:
2744 switch ((irsp->un.ulpWord[4] & 0xff)) {
2745 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002746 if (cmd == ELS_CMD_FLOGI) {
2747 if (PCI_DEVICE_ID_HORNET ==
2748 phba->pcidev->device) {
2749 phba->fc_topology = TOPOLOGY_LOOP;
2750 phba->pport->fc_myDID = 0;
2751 phba->alpa_map[0] = 0;
2752 phba->alpa_map[1] = 0;
2753 }
2754 }
James Smart2e0fef82007-06-17 19:56:36 -05002755 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002756 delay = 1000;
dea31012005-04-17 16:05:31 -05002757 retry = 1;
2758 break;
2759
James Smart92d7f7b2007-06-17 19:56:38 -05002760 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002761 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2762 "0124 Retry illegal cmd x%x "
2763 "retry:x%x delay:x%x\n",
2764 cmd, cmdiocb->retry, delay);
2765 retry = 1;
2766 /* All command's retry policy */
2767 maxretry = 8;
2768 if (cmdiocb->retry > 2)
2769 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002770 break;
2771
dea31012005-04-17 16:05:31 -05002772 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002773 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002774 retry = 1;
2775 if (cmdiocb->retry > 100)
2776 delay = 100;
2777 maxretry = 250;
2778 break;
2779
2780 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002781 delay = 100;
dea31012005-04-17 16:05:31 -05002782 retry = 1;
2783 break;
2784
James Smart858c9f62007-06-17 19:56:39 -05002785 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002786 case IOERR_INVALID_RPI:
2787 retry = 1;
2788 break;
2789 }
2790 break;
2791
2792 case IOSTAT_NPORT_RJT:
2793 case IOSTAT_FABRIC_RJT:
2794 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2795 retry = 1;
2796 break;
2797 }
2798 break;
2799
2800 case IOSTAT_NPORT_BSY:
2801 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002802 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002803 retry = 1;
2804 break;
2805
2806 case IOSTAT_LS_RJT:
2807 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2808 /* Added for Vendor specifc support
2809 * Just keep retrying for these Rsn / Exp codes
2810 */
2811 switch (stat.un.b.lsRjtRsnCode) {
2812 case LSRJT_UNABLE_TPC:
2813 if (stat.un.b.lsRjtRsnCodeExp ==
2814 LSEXP_CMD_IN_PROGRESS) {
2815 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002816 delay = 1000;
dea31012005-04-17 16:05:31 -05002817 maxretry = 48;
2818 }
2819 retry = 1;
2820 break;
2821 }
James Smartffc95492010-06-07 15:23:17 -04002822 if (stat.un.b.lsRjtRsnCodeExp ==
2823 LSEXP_CANT_GIVE_DATA) {
2824 if (cmd == ELS_CMD_PLOGI) {
2825 delay = 1000;
2826 maxretry = 48;
2827 }
2828 retry = 1;
2829 break;
2830 }
dea31012005-04-17 16:05:31 -05002831 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002832 delay = 1000;
dea31012005-04-17 16:05:31 -05002833 maxretry = lpfc_max_els_tries + 1;
2834 retry = 1;
2835 break;
2836 }
James Smart92d7f7b2007-06-17 19:56:38 -05002837 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2838 (cmd == ELS_CMD_FDISC) &&
2839 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002840 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2841 "0125 FDISC Failed (x%x). "
2842 "Fabric out of resources\n",
2843 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002844 lpfc_vport_set_state(vport,
2845 FC_VPORT_NO_FABRIC_RSCS);
2846 }
dea31012005-04-17 16:05:31 -05002847 break;
2848
2849 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002850 if ((cmd == ELS_CMD_PLOGI) ||
2851 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002852 delay = 1000;
dea31012005-04-17 16:05:31 -05002853 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002854 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002855 /* FDISC retry policy */
2856 maxretry = 48;
2857 if (cmdiocb->retry >= 32)
2858 delay = 1000;
dea31012005-04-17 16:05:31 -05002859 }
2860 retry = 1;
2861 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002862
2863 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002864 /* There are some cases where switches return this
2865 * error when they are not ready and should be returning
2866 * Logical Busy. We should delay every time.
2867 */
2868 if (cmd == ELS_CMD_FDISC &&
2869 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2870 maxretry = 3;
2871 delay = 1000;
2872 retry = 1;
2873 break;
2874 }
James Smart92d7f7b2007-06-17 19:56:38 -05002875 case LSRJT_PROTOCOL_ERR:
2876 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2877 (cmd == ELS_CMD_FDISC) &&
2878 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2879 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2880 ) {
James Smarte8b62012007-08-02 11:10:09 -04002881 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002882 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002883 "Fabric Detected Bad WWN\n",
2884 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002885 lpfc_vport_set_state(vport,
2886 FC_VPORT_FABRIC_REJ_WWN);
2887 }
2888 break;
dea31012005-04-17 16:05:31 -05002889 }
2890 break;
2891
2892 case IOSTAT_INTERMED_RSP:
2893 case IOSTAT_BA_RJT:
2894 break;
2895
2896 default:
2897 break;
2898 }
2899
James Smart488d1462006-03-07 15:02:37 -05002900 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002901 retry = 1;
dea31012005-04-17 16:05:31 -05002902
James Smart695a8142010-01-26 23:08:03 -05002903 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002904 (phba->fc_topology != TOPOLOGY_LOOP) &&
2905 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002906 /* FLOGI retry policy */
2907 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04002908 /* retry forever */
2909 maxretry = 0;
2910 if (cmdiocb->retry >= 100)
2911 delay = 5000;
2912 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04002913 delay = 1000;
2914 }
2915
James Smart6669f9b2009-10-02 15:16:45 -04002916 cmdiocb->retry++;
2917 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05002918 phba->fc_stat.elsRetryExceeded++;
2919 retry = 0;
2920 }
2921
James Smarted957682007-06-17 19:56:37 -05002922 if ((vport->load_flag & FC_UNLOADING) != 0)
2923 retry = 0;
2924
dea31012005-04-17 16:05:31 -05002925 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04002926 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
2927 /* Stop retrying PLOGI and FDISC if in FCF discovery */
2928 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
2929 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2930 "2849 Stop retry ELS command "
2931 "x%x to remote NPORT x%x, "
2932 "Data: x%x x%x\n", cmd, did,
2933 cmdiocb->retry, delay);
2934 return 0;
2935 }
2936 }
dea31012005-04-17 16:05:31 -05002937
2938 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002939 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2940 "0107 Retry ELS command x%x to remote "
2941 "NPORT x%x Data: x%x x%x\n",
2942 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002943
James Smart858c9f62007-06-17 19:56:39 -05002944 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2945 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2946 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2947 /* Don't reset timer for no resources */
2948
dea31012005-04-17 16:05:31 -05002949 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002950 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002951 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002952 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002953 }
2954
2955 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002956 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002957 phba->fc_stat.elsDelayRetry++;
2958 ndlp->nlp_retry = cmdiocb->retry;
2959
James Smart92d7f7b2007-06-17 19:56:38 -05002960 /* delay is specified in milliseconds */
2961 mod_timer(&ndlp->nlp_delayfunc,
2962 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002963 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002964 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002965 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002966
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002967 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002968 if (cmd == ELS_CMD_PRLI)
2969 lpfc_nlp_set_state(vport, ndlp,
2970 NLP_STE_REG_LOGIN_ISSUE);
2971 else
2972 lpfc_nlp_set_state(vport, ndlp,
2973 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002974 ndlp->nlp_last_elscmd = cmd;
2975
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002976 return 1;
dea31012005-04-17 16:05:31 -05002977 }
2978 switch (cmd) {
2979 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002980 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002981 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002982 case ELS_CMD_FDISC:
2983 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2984 return 1;
dea31012005-04-17 16:05:31 -05002985 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002986 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002987 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002988 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002989 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002990 }
James Smart2e0fef82007-06-17 19:56:36 -05002991 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002992 return 1;
dea31012005-04-17 16:05:31 -05002993 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002994 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002995 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2996 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002997 return 1;
dea31012005-04-17 16:05:31 -05002998 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002999 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003000 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3001 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003002 return 1;
dea31012005-04-17 16:05:31 -05003003 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003004 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003005 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3006 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003007 return 1;
dea31012005-04-17 16:05:31 -05003008 }
3009 }
dea31012005-04-17 16:05:31 -05003010 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003011 if (logerr) {
3012 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3013 "0137 No retry ELS command x%x to remote "
3014 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3015 cmd, did, irsp->ulpStatus,
3016 irsp->un.ulpWord[4]);
3017 }
3018 else {
3019 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003020 "0108 No retry ELS command x%x to remote "
3021 "NPORT x%x Retried:%d Error:x%x/%x\n",
3022 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3023 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003024 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003025 return 0;
dea31012005-04-17 16:05:31 -05003026}
3027
James Smarte59058c2008-08-24 21:49:00 -04003028/**
James Smart3621a712009-04-06 18:47:14 -04003029 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003030 * @phba: pointer to lpfc hba data structure.
3031 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3032 *
3033 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3034 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3035 * checks to see whether there is a lpfc DMA buffer associated with the
3036 * response of the command IOCB. If so, it will be released before releasing
3037 * the lpfc DMA buffer associated with the IOCB itself.
3038 *
3039 * Return code
3040 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3041 **/
James Smart09372822008-01-11 01:52:54 -05003042static int
James Smart87af33f2007-10-27 13:37:43 -04003043lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3044{
3045 struct lpfc_dmabuf *buf_ptr;
3046
James Smarte59058c2008-08-24 21:49:00 -04003047 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003048 if (!list_empty(&buf_ptr1->list)) {
3049 list_remove_head(&buf_ptr1->list, buf_ptr,
3050 struct lpfc_dmabuf,
3051 list);
3052 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3053 kfree(buf_ptr);
3054 }
3055 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3056 kfree(buf_ptr1);
3057 return 0;
3058}
3059
James Smarte59058c2008-08-24 21:49:00 -04003060/**
James Smart3621a712009-04-06 18:47:14 -04003061 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003062 * @phba: pointer to lpfc hba data structure.
3063 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3064 *
3065 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3066 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3067 * pool.
3068 *
3069 * Return code
3070 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3071 **/
James Smart09372822008-01-11 01:52:54 -05003072static int
James Smart87af33f2007-10-27 13:37:43 -04003073lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3074{
3075 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3076 kfree(buf_ptr);
3077 return 0;
3078}
3079
James Smarte59058c2008-08-24 21:49:00 -04003080/**
James Smart3621a712009-04-06 18:47:14 -04003081 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003082 * @phba: pointer to lpfc hba data structure.
3083 * @elsiocb: pointer to lpfc els command iocb data structure.
3084 *
3085 * This routine frees a command IOCB and its associated resources. The
3086 * command IOCB data structure contains the reference to various associated
3087 * resources, these fields must be set to NULL if the associated reference
3088 * not present:
3089 * context1 - reference to ndlp
3090 * context2 - reference to cmd
3091 * context2->next - reference to rsp
3092 * context3 - reference to bpl
3093 *
3094 * It first properly decrements the reference count held on ndlp for the
3095 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3096 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3097 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3098 * adds the DMA buffer the @phba data structure for the delayed release.
3099 * If reference to the Buffer Pointer List (BPL) is present, the
3100 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3101 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3102 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3103 *
3104 * Return code
3105 * 0 - Success (currently, always return 0)
3106 **/
James Smart87af33f2007-10-27 13:37:43 -04003107int
James Smart329f9bc2007-04-25 09:53:01 -04003108lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003109{
3110 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003111 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003112
James Smarta8adb832007-10-27 13:37:53 -04003113 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3114 if (ndlp) {
3115 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3116 lpfc_nlp_put(ndlp);
3117
3118 /* If the ndlp is not being used by another discovery
3119 * thread, free it.
3120 */
3121 if (!lpfc_nlp_not_used(ndlp)) {
3122 /* If ndlp is being used by another discovery
3123 * thread, just clear NLP_DEFER_RM
3124 */
3125 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3126 }
3127 }
3128 else
3129 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003130 elsiocb->context1 = NULL;
3131 }
dea31012005-04-17 16:05:31 -05003132 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3133 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003134 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3135 /* Firmware could still be in progress of DMAing
3136 * payload, so don't free data buffer till after
3137 * a hbeat.
3138 */
3139 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3140 buf_ptr = elsiocb->context2;
3141 elsiocb->context2 = NULL;
3142 if (buf_ptr) {
3143 buf_ptr1 = NULL;
3144 spin_lock_irq(&phba->hbalock);
3145 if (!list_empty(&buf_ptr->list)) {
3146 list_remove_head(&buf_ptr->list,
3147 buf_ptr1, struct lpfc_dmabuf,
3148 list);
3149 INIT_LIST_HEAD(&buf_ptr1->list);
3150 list_add_tail(&buf_ptr1->list,
3151 &phba->elsbuf);
3152 phba->elsbuf_cnt++;
3153 }
3154 INIT_LIST_HEAD(&buf_ptr->list);
3155 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3156 phba->elsbuf_cnt++;
3157 spin_unlock_irq(&phba->hbalock);
3158 }
3159 } else {
3160 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3161 lpfc_els_free_data(phba, buf_ptr1);
3162 }
dea31012005-04-17 16:05:31 -05003163 }
3164
3165 if (elsiocb->context3) {
3166 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003167 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003168 }
James Bottomley604a3e32005-10-29 10:28:33 -05003169 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003170 return 0;
3171}
3172
James Smarte59058c2008-08-24 21:49:00 -04003173/**
James Smart3621a712009-04-06 18:47:14 -04003174 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003175 * @phba: pointer to lpfc hba data structure.
3176 * @cmdiocb: pointer to lpfc command iocb data structure.
3177 * @rspiocb: pointer to lpfc response iocb data structure.
3178 *
3179 * This routine is the completion callback function to the Logout (LOGO)
3180 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3181 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3182 * release the ndlp if it has the last reference remaining (reference count
3183 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3184 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3185 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3186 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3187 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3188 * IOCB data structure.
3189 **/
dea31012005-04-17 16:05:31 -05003190static void
James Smart2e0fef82007-06-17 19:56:36 -05003191lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3192 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003193{
James Smart2e0fef82007-06-17 19:56:36 -05003194 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3195 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003196 IOCB_t *irsp;
3197
3198 irsp = &rspiocb->iocb;
3199 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3200 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3201 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003202 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003203 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3204 "0109 ACC to LOGO completes to NPort x%x "
3205 "Data: x%x x%x x%x\n",
3206 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3207 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003208
3209 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3210 /* NPort Recovery mode or node is just allocated */
3211 if (!lpfc_nlp_not_used(ndlp)) {
3212 /* If the ndlp is being used by another discovery
3213 * thread, just unregister the RPI.
3214 */
3215 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003216 } else {
3217 /* Indicate the node has already released, should
3218 * not reference to it from within lpfc_els_free_iocb.
3219 */
3220 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003221 }
dea31012005-04-17 16:05:31 -05003222 }
3223 lpfc_els_free_iocb(phba, cmdiocb);
3224 return;
3225}
3226
James Smarte59058c2008-08-24 21:49:00 -04003227/**
James Smart3621a712009-04-06 18:47:14 -04003228 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003229 * @phba: pointer to lpfc hba data structure.
3230 * @pmb: pointer to the driver internal queue element for mailbox command.
3231 *
3232 * This routine is the completion callback function for unregister default
3233 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3234 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3235 * decrements the ndlp reference count held for this completion callback
3236 * function. After that, it invokes the lpfc_nlp_not_used() to check
3237 * whether there is only one reference left on the ndlp. If so, it will
3238 * perform one more decrement and trigger the release of the ndlp.
3239 **/
James Smart858c9f62007-06-17 19:56:39 -05003240void
3241lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3242{
3243 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3244 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3245
James Smart6fb120a2009-05-22 14:52:59 -04003246 /*
3247 * This routine is used to register and unregister in previous SLI
3248 * modes.
3249 */
3250 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3251 (phba->sli_rev == LPFC_SLI_REV4))
3252 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3253
James Smart858c9f62007-06-17 19:56:39 -05003254 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003255 pmb->context2 = NULL;
3256
James Smart858c9f62007-06-17 19:56:39 -05003257 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3258 kfree(mp);
3259 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003260 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003261 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003262 /* This is the end of the default RPI cleanup logic for this
3263 * ndlp. If no other discovery threads are using this ndlp.
3264 * we should free all resources associated with it.
3265 */
3266 lpfc_nlp_not_used(ndlp);
3267 }
James Smart3772a992009-05-22 14:50:54 -04003268
James Smart858c9f62007-06-17 19:56:39 -05003269 return;
3270}
3271
James Smarte59058c2008-08-24 21:49:00 -04003272/**
James Smart3621a712009-04-06 18:47:14 -04003273 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003274 * @phba: pointer to lpfc hba data structure.
3275 * @cmdiocb: pointer to lpfc command iocb data structure.
3276 * @rspiocb: pointer to lpfc response iocb data structure.
3277 *
3278 * This routine is the completion callback function for ELS Response IOCB
3279 * command. In normal case, this callback function just properly sets the
3280 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3281 * field in the command IOCB is not NULL, the referred mailbox command will
3282 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3283 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3284 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3285 * routine shall be invoked trying to release the ndlp if no other threads
3286 * are currently referring it.
3287 **/
dea31012005-04-17 16:05:31 -05003288static void
James Smart858c9f62007-06-17 19:56:39 -05003289lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003290 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003291{
James Smart2e0fef82007-06-17 19:56:36 -05003292 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3293 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3294 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003295 IOCB_t *irsp;
3296 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003297 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003298 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003299 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003300
James Smart33ccf8d2006-08-17 11:57:58 -04003301 irsp = &rspiocb->iocb;
3302
dea31012005-04-17 16:05:31 -05003303 if (cmdiocb->context_un.mbox)
3304 mbox = cmdiocb->context_un.mbox;
3305
James Smartfa4066b2008-01-11 01:53:27 -05003306 /* First determine if this is a LS_RJT cmpl. Note, this callback
3307 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3308 */
James Smart87af33f2007-10-27 13:37:43 -04003309 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003310 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3311 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003312 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003313 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003314 */
3315 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3316 ls_rjt = 1;
3317 }
3318
dea31012005-04-17 16:05:31 -05003319 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003320 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003321 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003322 mp = (struct lpfc_dmabuf *) mbox->context1;
3323 if (mp) {
3324 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3325 kfree(mp);
3326 }
James Smart329f9bc2007-04-25 09:53:01 -04003327 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003328 }
James Smart58da1ff2008-04-07 10:15:56 -04003329 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3330 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003331 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003332 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003333 /* Indicate the node has already released,
3334 * should not reference to it from within
3335 * the routine lpfc_els_free_iocb.
3336 */
3337 cmdiocb->context1 = NULL;
3338 }
dea31012005-04-17 16:05:31 -05003339 goto out;
3340 }
3341
James Smart858c9f62007-06-17 19:56:39 -05003342 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003343 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003344 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003345 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003346 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003347 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3348 "0110 ELS response tag x%x completes "
3349 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3350 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3351 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3352 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3353 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003354 if (mbox) {
3355 if ((rspiocb->iocb.ulpStatus == 0)
3356 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003357 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003358 /* Increment reference count to ndlp to hold the
3359 * reference to ndlp for the callback function.
3360 */
James Smart329f9bc2007-04-25 09:53:01 -04003361 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003362 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003363 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3364 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3365 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3366 }
3367 else {
3368 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3369 ndlp->nlp_prev_state = ndlp->nlp_state;
3370 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003371 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003372 }
James Smart0b727fe2007-10-27 13:37:25 -04003373 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003374 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003375 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003376 else
3377 /* Decrement the ndlp reference count we
3378 * set for this failed mailbox command.
3379 */
3380 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003381
3382 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3383 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3384 "0138 ELS rsp: Cannot issue reg_login for x%x "
3385 "Data: x%x x%x x%x\n",
3386 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3387 ndlp->nlp_rpi);
3388
James Smartfa4066b2008-01-11 01:53:27 -05003389 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003390 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003391 /* Indicate node has already been released,
3392 * should not reference to it from within
3393 * the routine lpfc_els_free_iocb.
3394 */
3395 cmdiocb->context1 = NULL;
3396 }
dea31012005-04-17 16:05:31 -05003397 } else {
James Smart858c9f62007-06-17 19:56:39 -05003398 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3399 if (!lpfc_error_lost_link(irsp) &&
3400 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003401 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003402 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003403 /* Indicate node has already been
3404 * released, should not reference
3405 * to it from within the routine
3406 * lpfc_els_free_iocb.
3407 */
3408 cmdiocb->context1 = NULL;
3409 }
dea31012005-04-17 16:05:31 -05003410 }
3411 }
James Smart14691152006-12-02 13:34:28 -05003412 mp = (struct lpfc_dmabuf *) mbox->context1;
3413 if (mp) {
3414 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3415 kfree(mp);
3416 }
3417 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003418 }
3419out:
James Smart58da1ff2008-04-07 10:15:56 -04003420 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003421 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003422 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003423 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003424
3425 /* If the node is not being used by another discovery thread,
3426 * and we are sending a reject, we are done with it.
3427 * Release driver reference count here and free associated
3428 * resources.
3429 */
3430 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003431 if (lpfc_nlp_not_used(ndlp))
3432 /* Indicate node has already been released,
3433 * should not reference to it from within
3434 * the routine lpfc_els_free_iocb.
3435 */
3436 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003437 }
James Smart87af33f2007-10-27 13:37:43 -04003438
dea31012005-04-17 16:05:31 -05003439 lpfc_els_free_iocb(phba, cmdiocb);
3440 return;
3441}
3442
James Smarte59058c2008-08-24 21:49:00 -04003443/**
James Smart3621a712009-04-06 18:47:14 -04003444 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003445 * @vport: pointer to a host virtual N_Port data structure.
3446 * @flag: the els command code to be accepted.
3447 * @oldiocb: pointer to the original lpfc command iocb data structure.
3448 * @ndlp: pointer to a node-list data structure.
3449 * @mbox: pointer to the driver internal queue element for mailbox command.
3450 *
3451 * This routine prepares and issues an Accept (ACC) response IOCB
3452 * command. It uses the @flag to properly set up the IOCB field for the
3453 * specific ACC response command to be issued and invokes the
3454 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3455 * @mbox pointer is passed in, it will be put into the context_un.mbox
3456 * field of the IOCB for the completion callback function to issue the
3457 * mailbox command to the HBA later when callback is invoked.
3458 *
3459 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3460 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3461 * will be stored into the context1 field of the IOCB for the completion
3462 * callback function to the corresponding response ELS IOCB command.
3463 *
3464 * Return code
3465 * 0 - Successfully issued acc response
3466 * 1 - Failed to issue acc response
3467 **/
dea31012005-04-17 16:05:31 -05003468int
James Smart2e0fef82007-06-17 19:56:36 -05003469lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3470 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003471 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003472{
James Smart2e0fef82007-06-17 19:56:36 -05003473 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3474 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003475 IOCB_t *icmd;
3476 IOCB_t *oldcmd;
3477 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003478 struct lpfc_sli *psli;
3479 uint8_t *pcmd;
3480 uint16_t cmdsize;
3481 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003482 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003483
3484 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003485 oldcmd = &oldiocb->iocb;
3486
3487 switch (flag) {
3488 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003489 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003490 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3491 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003492 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003493 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003494 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003495 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003496 return 1;
dea31012005-04-17 16:05:31 -05003497 }
James Smart2e0fef82007-06-17 19:56:36 -05003498
dea31012005-04-17 16:05:31 -05003499 icmd = &elsiocb->iocb;
3500 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3501 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3502 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003503 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003504
3505 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3506 "Issue ACC: did:x%x flg:x%x",
3507 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003508 break;
3509 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003510 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003511 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3512 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003513 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003514 return 1;
James Smart488d1462006-03-07 15:02:37 -05003515
dea31012005-04-17 16:05:31 -05003516 icmd = &elsiocb->iocb;
3517 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3518 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3519
3520 if (mbox)
3521 elsiocb->context_un.mbox = mbox;
3522
3523 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003524 pcmd += sizeof(uint32_t);
3525 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003526
3527 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3528 "Issue ACC PLOGI: did:x%x flg:x%x",
3529 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003530 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003531 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003532 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003533 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003534 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3535 if (!elsiocb)
3536 return 1;
3537
3538 icmd = &elsiocb->iocb;
3539 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3540 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3541
3542 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003543 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003544 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3545 els_pkt_ptr = (ELS_PKT *) pcmd;
3546 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003547
3548 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3549 "Issue ACC PRLO: did:x%x flg:x%x",
3550 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003551 break;
dea31012005-04-17 16:05:31 -05003552 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003553 return 1;
dea31012005-04-17 16:05:31 -05003554 }
dea31012005-04-17 16:05:31 -05003555 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003556 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3557 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3558 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3559 elsiocb->iotag, elsiocb->iocb.ulpContext,
3560 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3561 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003562 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003563 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003564 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003565 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003566 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3567 } else {
James Smart858c9f62007-06-17 19:56:39 -05003568 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003569 }
3570
3571 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003572 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003573 if (rc == IOCB_ERROR) {
3574 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003575 return 1;
dea31012005-04-17 16:05:31 -05003576 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003577 return 0;
dea31012005-04-17 16:05:31 -05003578}
3579
James Smarte59058c2008-08-24 21:49:00 -04003580/**
James Smart3621a712009-04-06 18:47:14 -04003581 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003582 * @vport: pointer to a virtual N_Port data structure.
3583 * @rejectError:
3584 * @oldiocb: pointer to the original lpfc command iocb data structure.
3585 * @ndlp: pointer to a node-list data structure.
3586 * @mbox: pointer to the driver internal queue element for mailbox command.
3587 *
3588 * This routine prepares and issue an Reject (RJT) response IOCB
3589 * command. If a @mbox pointer is passed in, it will be put into the
3590 * context_un.mbox field of the IOCB for the completion callback function
3591 * to issue to the HBA later.
3592 *
3593 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3594 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3595 * will be stored into the context1 field of the IOCB for the completion
3596 * callback function to the reject response ELS IOCB command.
3597 *
3598 * Return code
3599 * 0 - Successfully issued reject response
3600 * 1 - Failed to issue reject response
3601 **/
dea31012005-04-17 16:05:31 -05003602int
James Smart2e0fef82007-06-17 19:56:36 -05003603lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003604 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3605 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003606{
James Smart2e0fef82007-06-17 19:56:36 -05003607 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003608 IOCB_t *icmd;
3609 IOCB_t *oldcmd;
3610 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003611 struct lpfc_sli *psli;
3612 uint8_t *pcmd;
3613 uint16_t cmdsize;
3614 int rc;
3615
3616 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003617 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003618 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3619 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003620 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003621 return 1;
dea31012005-04-17 16:05:31 -05003622
3623 icmd = &elsiocb->iocb;
3624 oldcmd = &oldiocb->iocb;
3625 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3626 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3627
3628 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003629 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003630 *((uint32_t *) (pcmd)) = rejectError;
3631
James Smart51ef4c22007-08-02 11:10:31 -04003632 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003633 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003634
dea31012005-04-17 16:05:31 -05003635 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003636 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3637 "0129 Xmit ELS RJT x%x response tag x%x "
3638 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3639 "rpi x%x\n",
3640 rejectError, elsiocb->iotag,
3641 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3642 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003643 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3644 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3645 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3646
dea31012005-04-17 16:05:31 -05003647 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003648 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003649 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003650
dea31012005-04-17 16:05:31 -05003651 if (rc == IOCB_ERROR) {
3652 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003653 return 1;
dea31012005-04-17 16:05:31 -05003654 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003655 return 0;
dea31012005-04-17 16:05:31 -05003656}
3657
James Smarte59058c2008-08-24 21:49:00 -04003658/**
James Smart3621a712009-04-06 18:47:14 -04003659 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003660 * @vport: pointer to a virtual N_Port data structure.
3661 * @oldiocb: pointer to the original lpfc command iocb data structure.
3662 * @ndlp: pointer to a node-list data structure.
3663 *
3664 * This routine prepares and issues an Accept (ACC) response to Address
3665 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3666 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3667 *
3668 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3669 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3670 * will be stored into the context1 field of the IOCB for the completion
3671 * callback function to the ADISC Accept response ELS IOCB command.
3672 *
3673 * Return code
3674 * 0 - Successfully issued acc adisc response
3675 * 1 - Failed to issue adisc acc response
3676 **/
dea31012005-04-17 16:05:31 -05003677int
James Smart2e0fef82007-06-17 19:56:36 -05003678lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3679 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003680{
James Smart2e0fef82007-06-17 19:56:36 -05003681 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003682 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003683 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003684 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003685 uint8_t *pcmd;
3686 uint16_t cmdsize;
3687 int rc;
3688
James Smart92d7f7b2007-06-17 19:56:38 -05003689 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003690 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3691 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003692 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003693 return 1;
dea31012005-04-17 16:05:31 -05003694
dea31012005-04-17 16:05:31 -05003695 icmd = &elsiocb->iocb;
3696 oldcmd = &oldiocb->iocb;
3697 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003698
3699 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003700 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3701 "0130 Xmit ADISC ACC response iotag x%x xri: "
3702 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3703 elsiocb->iotag, elsiocb->iocb.ulpContext,
3704 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3705 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003706 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3707
3708 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003709 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003710
3711 ap = (ADISC *) (pcmd);
3712 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003713 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3714 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003715 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003716
James Smart858c9f62007-06-17 19:56:39 -05003717 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3718 "Issue ACC ADISC: did:x%x flg:x%x",
3719 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3720
dea31012005-04-17 16:05:31 -05003721 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003722 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003723 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003724 if (rc == IOCB_ERROR) {
3725 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003726 return 1;
dea31012005-04-17 16:05:31 -05003727 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003728 return 0;
dea31012005-04-17 16:05:31 -05003729}
3730
James Smarte59058c2008-08-24 21:49:00 -04003731/**
James Smart3621a712009-04-06 18:47:14 -04003732 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003733 * @vport: pointer to a virtual N_Port data structure.
3734 * @oldiocb: pointer to the original lpfc command iocb data structure.
3735 * @ndlp: pointer to a node-list data structure.
3736 *
3737 * This routine prepares and issues an Accept (ACC) response to Process
3738 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3739 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3740 *
3741 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3742 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3743 * will be stored into the context1 field of the IOCB for the completion
3744 * callback function to the PRLI Accept response ELS IOCB command.
3745 *
3746 * Return code
3747 * 0 - Successfully issued acc prli response
3748 * 1 - Failed to issue acc prli response
3749 **/
dea31012005-04-17 16:05:31 -05003750int
James Smart2e0fef82007-06-17 19:56:36 -05003751lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003752 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003753{
James Smart2e0fef82007-06-17 19:56:36 -05003754 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003755 PRLI *npr;
3756 lpfc_vpd_t *vpd;
3757 IOCB_t *icmd;
3758 IOCB_t *oldcmd;
3759 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003760 struct lpfc_sli *psli;
3761 uint8_t *pcmd;
3762 uint16_t cmdsize;
3763 int rc;
3764
3765 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003766
James Smart92d7f7b2007-06-17 19:56:38 -05003767 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003768 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003769 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003770 if (!elsiocb)
3771 return 1;
dea31012005-04-17 16:05:31 -05003772
dea31012005-04-17 16:05:31 -05003773 icmd = &elsiocb->iocb;
3774 oldcmd = &oldiocb->iocb;
3775 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003776 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003777 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3778 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3779 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3780 elsiocb->iotag, elsiocb->iocb.ulpContext,
3781 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3782 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003783 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3784
3785 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003786 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003787
3788 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003789 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003790
3791 npr = (PRLI *) pcmd;
3792 vpd = &phba->vpd;
3793 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003794 * If the remote port is a target and our firmware version is 3.20 or
3795 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003796 */
James Smart0d2b6b82008-06-14 22:52:47 -04003797 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3798 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003799 npr->ConfmComplAllowed = 1;
3800 npr->Retry = 1;
3801 npr->TaskRetryIdReq = 1;
3802 }
3803
3804 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3805 npr->estabImagePair = 1;
3806 npr->readXferRdyDis = 1;
3807 npr->ConfmComplAllowed = 1;
3808
3809 npr->prliType = PRLI_FCP_TYPE;
3810 npr->initiatorFunc = 1;
3811
James Smart858c9f62007-06-17 19:56:39 -05003812 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3813 "Issue ACC PRLI: did:x%x flg:x%x",
3814 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3815
dea31012005-04-17 16:05:31 -05003816 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003817 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003818
James Smart3772a992009-05-22 14:50:54 -04003819 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003820 if (rc == IOCB_ERROR) {
3821 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003822 return 1;
dea31012005-04-17 16:05:31 -05003823 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003824 return 0;
dea31012005-04-17 16:05:31 -05003825}
3826
James Smarte59058c2008-08-24 21:49:00 -04003827/**
James Smart3621a712009-04-06 18:47:14 -04003828 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003829 * @vport: pointer to a virtual N_Port data structure.
3830 * @format: rnid command format.
3831 * @oldiocb: pointer to the original lpfc command iocb data structure.
3832 * @ndlp: pointer to a node-list data structure.
3833 *
3834 * This routine issues a Request Node Identification Data (RNID) Accept
3835 * (ACC) response. It constructs the RNID ACC response command according to
3836 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3837 * issue the response. Note that this command does not need to hold the ndlp
3838 * reference count for the callback. So, the ndlp reference count taken by
3839 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3840 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3841 * there is no ndlp reference available.
3842 *
3843 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3844 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3845 * will be stored into the context1 field of the IOCB for the completion
3846 * callback function. However, for the RNID Accept Response ELS command,
3847 * this is undone later by this routine after the IOCB is allocated.
3848 *
3849 * Return code
3850 * 0 - Successfully issued acc rnid response
3851 * 1 - Failed to issue acc rnid response
3852 **/
dea31012005-04-17 16:05:31 -05003853static int
James Smart2e0fef82007-06-17 19:56:36 -05003854lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003855 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003856{
James Smart2e0fef82007-06-17 19:56:36 -05003857 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003858 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003859 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003860 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003861 struct lpfc_sli *psli;
3862 uint8_t *pcmd;
3863 uint16_t cmdsize;
3864 int rc;
3865
3866 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003867 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3868 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003869 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003870 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003871
James Smart2e0fef82007-06-17 19:56:36 -05003872 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3873 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003874 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003875 return 1;
dea31012005-04-17 16:05:31 -05003876
dea31012005-04-17 16:05:31 -05003877 icmd = &elsiocb->iocb;
3878 oldcmd = &oldiocb->iocb;
3879 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003880 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003881 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3882 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3883 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003884 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003885 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003886 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003887
James Smart92d7f7b2007-06-17 19:56:38 -05003888 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003889 rn = (RNID *) (pcmd);
3890 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003891 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3892 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3893 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003894 switch (format) {
3895 case 0:
3896 rn->SpecificLen = 0;
3897 break;
3898 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003899 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003900 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003901 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003902 rn->un.topologyDisc.unitType = RNID_HBA;
3903 rn->un.topologyDisc.physPort = 0;
3904 rn->un.topologyDisc.attachedNodes = 0;
3905 break;
3906 default:
3907 rn->CommonLen = 0;
3908 rn->SpecificLen = 0;
3909 break;
3910 }
3911
James Smart858c9f62007-06-17 19:56:39 -05003912 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3913 "Issue ACC RNID: did:x%x flg:x%x",
3914 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3915
dea31012005-04-17 16:05:31 -05003916 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003917 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003918 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003919 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3920 * it could be freed */
3921
James Smart3772a992009-05-22 14:50:54 -04003922 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003923 if (rc == IOCB_ERROR) {
3924 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003925 return 1;
dea31012005-04-17 16:05:31 -05003926 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003927 return 0;
dea31012005-04-17 16:05:31 -05003928}
3929
James Smarte59058c2008-08-24 21:49:00 -04003930/**
James Smart3621a712009-04-06 18:47:14 -04003931 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04003932 * @vport: pointer to a host virtual N_Port data structure.
3933 *
3934 * This routine issues Address Discover (ADISC) ELS commands to those
3935 * N_Ports which are in node port recovery state and ADISC has not been issued
3936 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3937 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3938 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3939 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3940 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3941 * IOCBs quit for later pick up. On the other hand, after walking through
3942 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3943 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3944 * no more ADISC need to be sent.
3945 *
3946 * Return code
3947 * The number of N_Ports with adisc issued.
3948 **/
dea31012005-04-17 16:05:31 -05003949int
James Smart2e0fef82007-06-17 19:56:36 -05003950lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003951{
James Smart2e0fef82007-06-17 19:56:36 -05003952 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003953 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003954 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003955
James Smart685f0bf2007-04-25 09:53:08 -04003956 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05003957 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003958 if (!NLP_CHK_NODE_ACT(ndlp))
3959 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003960 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3961 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3962 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003963 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003964 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05003965 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003966 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003967 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3968 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003969 sentadisc++;
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 }
3980 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003981 spin_lock_irq(shost->host_lock);
3982 vport->fc_flag &= ~FC_NLP_MORE;
3983 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003984 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003985 return sentadisc;
dea31012005-04-17 16:05:31 -05003986}
3987
James Smarte59058c2008-08-24 21:49:00 -04003988/**
James Smart3621a712009-04-06 18:47:14 -04003989 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04003990 * @vport: pointer to a host virtual N_Port data structure.
3991 *
3992 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3993 * which are in node port recovery state, with a @vport. Each time an ELS
3994 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3995 * the per @vport number of discover count (num_disc_nodes) shall be
3996 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3997 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3998 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3999 * later pick up. On the other hand, after walking through all the ndlps with
4000 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4001 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4002 * PLOGI need to be sent.
4003 *
4004 * Return code
4005 * The number of N_Ports with plogi issued.
4006 **/
dea31012005-04-17 16:05:31 -05004007int
James Smart2e0fef82007-06-17 19:56:36 -05004008lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004009{
James Smart2e0fef82007-06-17 19:56:36 -05004010 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004011 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004012 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004013
James Smart2e0fef82007-06-17 19:56:36 -05004014 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4015 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004016 if (!NLP_CHK_NODE_ACT(ndlp))
4017 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004018 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4019 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4020 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4021 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4022 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004023 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4024 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004025 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004026 vport->num_disc_nodes++;
4027 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004028 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004029 spin_lock_irq(shost->host_lock);
4030 vport->fc_flag |= FC_NLP_MORE;
4031 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004032 break;
dea31012005-04-17 16:05:31 -05004033 }
4034 }
4035 }
James Smart87af33f2007-10-27 13:37:43 -04004036 if (sentplogi) {
4037 lpfc_set_disctmo(vport);
4038 }
4039 else {
James Smart2e0fef82007-06-17 19:56:36 -05004040 spin_lock_irq(shost->host_lock);
4041 vport->fc_flag &= ~FC_NLP_MORE;
4042 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004043 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004044 return sentplogi;
dea31012005-04-17 16:05:31 -05004045}
4046
James Smarte59058c2008-08-24 21:49:00 -04004047/**
James Smart3621a712009-04-06 18:47:14 -04004048 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004049 * @vport: pointer to a host virtual N_Port data structure.
4050 *
4051 * This routine cleans up any Registration State Change Notification
4052 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4053 * @vport together with the host_lock is used to prevent multiple thread
4054 * trying to access the RSCN array on a same @vport at the same time.
4055 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004056void
James Smart2e0fef82007-06-17 19:56:36 -05004057lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004058{
James Smart2e0fef82007-06-17 19:56:36 -05004059 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4060 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004061 int i;
4062
James Smart7f5f3d02008-02-08 18:50:14 -05004063 spin_lock_irq(shost->host_lock);
4064 if (vport->fc_rscn_flush) {
4065 /* Another thread is walking fc_rscn_id_list on this vport */
4066 spin_unlock_irq(shost->host_lock);
4067 return;
4068 }
4069 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4070 vport->fc_rscn_flush = 1;
4071 spin_unlock_irq(shost->host_lock);
4072
James Smart2e0fef82007-06-17 19:56:36 -05004073 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004074 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004075 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004076 }
James Smart2e0fef82007-06-17 19:56:36 -05004077 spin_lock_irq(shost->host_lock);
4078 vport->fc_rscn_id_cnt = 0;
4079 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4080 spin_unlock_irq(shost->host_lock);
4081 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004082 /* Indicate we are done walking this fc_rscn_id_list */
4083 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004084}
4085
James Smarte59058c2008-08-24 21:49:00 -04004086/**
James Smart3621a712009-04-06 18:47:14 -04004087 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004088 * @vport: pointer to a host virtual N_Port data structure.
4089 * @did: remote destination port identifier.
4090 *
4091 * This routine checks whether there is any pending Registration State
4092 * Configuration Notification (RSCN) to a @did on @vport.
4093 *
4094 * Return code
4095 * None zero - The @did matched with a pending rscn
4096 * 0 - not able to match @did with a pending rscn
4097 **/
dea31012005-04-17 16:05:31 -05004098int
James Smart2e0fef82007-06-17 19:56:36 -05004099lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004100{
4101 D_ID ns_did;
4102 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004103 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004104 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004105 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004106
4107 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004108
4109 /* Never match fabric nodes for RSCNs */
4110 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004111 return 0;
dea31012005-04-17 16:05:31 -05004112
4113 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004114 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004115 return did;
dea31012005-04-17 16:05:31 -05004116
James Smart7f5f3d02008-02-08 18:50:14 -05004117 spin_lock_irq(shost->host_lock);
4118 if (vport->fc_rscn_flush) {
4119 /* Another thread is walking fc_rscn_id_list on this vport */
4120 spin_unlock_irq(shost->host_lock);
4121 return 0;
4122 }
4123 /* Indicate we are walking fc_rscn_id_list on this vport */
4124 vport->fc_rscn_flush = 1;
4125 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004126 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004127 lp = vport->fc_rscn_id_list[i]->virt;
4128 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4129 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004130 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004131 rscn_did.un.word = be32_to_cpu(*lp++);
4132 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004133 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4134 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004135 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4136 && (ns_did.un.b.area == rscn_did.un.b.area)
4137 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004138 goto return_did_out;
dea31012005-04-17 16:05:31 -05004139 break;
James Smarteaf15d52008-12-04 22:39:29 -05004140 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004141 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4142 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004143 goto return_did_out;
dea31012005-04-17 16:05:31 -05004144 break;
James Smarteaf15d52008-12-04 22:39:29 -05004145 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004146 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004147 goto return_did_out;
dea31012005-04-17 16:05:31 -05004148 break;
James Smarteaf15d52008-12-04 22:39:29 -05004149 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004150 goto return_did_out;
dea31012005-04-17 16:05:31 -05004151 }
4152 }
James Smart92d7f7b2007-06-17 19:56:38 -05004153 }
James Smart7f5f3d02008-02-08 18:50:14 -05004154 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4155 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004156 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004157return_did_out:
4158 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4159 vport->fc_rscn_flush = 0;
4160 return did;
dea31012005-04-17 16:05:31 -05004161}
4162
James Smarte59058c2008-08-24 21:49:00 -04004163/**
James Smart3621a712009-04-06 18:47:14 -04004164 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004165 * @vport: pointer to a host virtual N_Port data structure.
4166 *
4167 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4168 * state machine for a @vport's nodes that are with pending RSCN (Registration
4169 * State Change Notification).
4170 *
4171 * Return code
4172 * 0 - Successful (currently alway return 0)
4173 **/
dea31012005-04-17 16:05:31 -05004174static int
James Smart2e0fef82007-06-17 19:56:36 -05004175lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004176{
James Smart685f0bf2007-04-25 09:53:08 -04004177 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004178
James Smart0d2b6b82008-06-14 22:52:47 -04004179 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004180 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004181 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004182 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4183 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004184 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004185 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004186 NLP_EVT_DEVICE_RECOVERY);
4187 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004188 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004189 return 0;
dea31012005-04-17 16:05:31 -05004190}
4191
James Smarte59058c2008-08-24 21:49:00 -04004192/**
James Smart3621a712009-04-06 18:47:14 -04004193 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004194 * @vport: pointer to a host virtual N_Port data structure.
4195 * @cmdiocb: pointer to lpfc command iocb data structure.
4196 *
4197 * lpfc_send_rscn_event sends an RSCN netlink event to management
4198 * applications.
4199 */
4200static void
4201lpfc_send_rscn_event(struct lpfc_vport *vport,
4202 struct lpfc_iocbq *cmdiocb)
4203{
4204 struct lpfc_dmabuf *pcmd;
4205 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4206 uint32_t *payload_ptr;
4207 uint32_t payload_len;
4208 struct lpfc_rscn_event_header *rscn_event_data;
4209
4210 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4211 payload_ptr = (uint32_t *) pcmd->virt;
4212 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4213
4214 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4215 payload_len, GFP_KERNEL);
4216 if (!rscn_event_data) {
4217 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4218 "0147 Failed to allocate memory for RSCN event\n");
4219 return;
4220 }
4221 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4222 rscn_event_data->payload_length = payload_len;
4223 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4224 payload_len);
4225
4226 fc_host_post_vendor_event(shost,
4227 fc_get_event_number(),
4228 sizeof(struct lpfc_els_event_header) + payload_len,
4229 (char *)rscn_event_data,
4230 LPFC_NL_VENDOR_ID);
4231
4232 kfree(rscn_event_data);
4233}
4234
4235/**
James Smart3621a712009-04-06 18:47:14 -04004236 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004237 * @vport: pointer to a host virtual N_Port data structure.
4238 * @cmdiocb: pointer to lpfc command iocb data structure.
4239 * @ndlp: pointer to a node-list data structure.
4240 *
4241 * This routine processes an unsolicited RSCN (Registration State Change
4242 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4243 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4244 * discover state machine is about to begin discovery, it just accepts the
4245 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4246 * contains N_Port IDs for other vports on this HBA, it just accepts the
4247 * RSCN and ignore processing it. If the state machine is in the recovery
4248 * state, the fc_rscn_id_list of this @vport is walked and the
4249 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4250 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4251 * routine is invoked to handle the RSCN event.
4252 *
4253 * Return code
4254 * 0 - Just sent the acc response
4255 * 1 - Sent the acc response and waited for name server completion
4256 **/
dea31012005-04-17 16:05:31 -05004257static int
James Smart2e0fef82007-06-17 19:56:36 -05004258lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004259 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004260{
James Smart2e0fef82007-06-17 19:56:36 -05004261 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4262 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004263 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004264 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004265 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004266 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004267 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004268 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004269 int i;
dea31012005-04-17 16:05:31 -05004270
4271 icmd = &cmdiocb->iocb;
4272 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4273 lp = (uint32_t *) pcmd->virt;
4274
James Smart92d7f7b2007-06-17 19:56:38 -05004275 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4276 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004277 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004278 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4279 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004280 vport->fc_flag, payload_len, *lp,
4281 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004282
4283 /* Send an RSCN event to the management application */
4284 lpfc_send_rscn_event(vport, cmdiocb);
4285
James Smartd2873e42006-08-18 17:46:43 -04004286 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004287 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004288 FCH_EVT_RSCN, lp[i]);
4289
dea31012005-04-17 16:05:31 -05004290 /* If we are about to begin discovery, just ACC the RSCN.
4291 * Discovery processing will satisfy it.
4292 */
James Smart2e0fef82007-06-17 19:56:36 -05004293 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004294 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4295 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4296 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4297
James Smart51ef4c22007-08-02 11:10:31 -04004298 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004299 return 0;
dea31012005-04-17 16:05:31 -05004300 }
4301
James Smart92d7f7b2007-06-17 19:56:38 -05004302 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4303 * just ACC and ignore it.
4304 */
4305 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004306 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004307 i = payload_len;
4308 datap = lp;
4309 while (i > 0) {
4310 nportid = *datap++;
4311 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4312 i -= sizeof(uint32_t);
4313 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004314 if (lpfc_find_vport_by_did(phba, nportid))
4315 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004316 }
4317 if (rscn_id == hba_id) {
4318 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004319 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004320 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004321 "Data: x%x x%x x%x x%x\n",
4322 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004323 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004324 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4325 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4326 ndlp->nlp_DID, vport->port_state,
4327 ndlp->nlp_flag);
4328
James Smart92d7f7b2007-06-17 19:56:38 -05004329 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004330 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004331 return 0;
4332 }
4333 }
4334
James Smart7f5f3d02008-02-08 18:50:14 -05004335 spin_lock_irq(shost->host_lock);
4336 if (vport->fc_rscn_flush) {
4337 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004338 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004339 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004340 /* Send back ACC */
4341 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004342 return 0;
4343 }
4344 /* Indicate we are walking fc_rscn_id_list on this vport */
4345 vport->fc_rscn_flush = 1;
4346 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004347 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004348 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004349 /* If we are already processing an RSCN, save the received
4350 * RSCN payload buffer, cmdiocb->context2 to process later.
4351 */
James Smart2e0fef82007-06-17 19:56:36 -05004352 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004353 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4354 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4355 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4356
James Smart09372822008-01-11 01:52:54 -05004357 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004358 vport->fc_flag |= FC_RSCN_DEFERRED;
4359 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004360 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004361 vport->fc_flag |= FC_RSCN_MODE;
4362 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004363 if (rscn_cnt) {
4364 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4365 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4366 }
4367 if ((rscn_cnt) &&
4368 (payload_len + length <= LPFC_BPL_SIZE)) {
4369 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004370 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004371 memcpy(((uint8_t *)cmd) + length, lp,
4372 payload_len);
4373 } else {
4374 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4375 vport->fc_rscn_id_cnt++;
4376 /* If we zero, cmdiocb->context2, the calling
4377 * routine will not try to free it.
4378 */
4379 cmdiocb->context2 = NULL;
4380 }
dea31012005-04-17 16:05:31 -05004381 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004382 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4383 "0235 Deferred RSCN "
4384 "Data: x%x x%x x%x\n",
4385 vport->fc_rscn_id_cnt, vport->fc_flag,
4386 vport->port_state);
dea31012005-04-17 16:05:31 -05004387 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004388 vport->fc_flag |= FC_RSCN_DISCOVERY;
4389 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004390 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004391 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4392 "0234 ReDiscovery RSCN "
4393 "Data: x%x x%x x%x\n",
4394 vport->fc_rscn_id_cnt, vport->fc_flag,
4395 vport->port_state);
dea31012005-04-17 16:05:31 -05004396 }
James Smart7f5f3d02008-02-08 18:50:14 -05004397 /* Indicate we are done walking fc_rscn_id_list on this vport */
4398 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004399 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004400 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004401 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004402 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004403 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004404 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004405 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004406 return 0;
dea31012005-04-17 16:05:31 -05004407 }
James Smart858c9f62007-06-17 19:56:39 -05004408 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4409 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4410 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4411
James Smart2e0fef82007-06-17 19:56:36 -05004412 spin_lock_irq(shost->host_lock);
4413 vport->fc_flag |= FC_RSCN_MODE;
4414 spin_unlock_irq(shost->host_lock);
4415 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004416 /* Indicate we are done walking fc_rscn_id_list on this vport */
4417 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004418 /*
4419 * If we zero, cmdiocb->context2, the calling routine will
4420 * not try to free it.
4421 */
4422 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004423 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004424 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004425 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004426 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004427 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004428 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004429}
4430
James Smarte59058c2008-08-24 21:49:00 -04004431/**
James Smart3621a712009-04-06 18:47:14 -04004432 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004433 * @vport: pointer to a host virtual N_Port data structure.
4434 *
4435 * This routine handles the Registration State Configuration Notification
4436 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4437 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4438 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4439 * NameServer shall be issued. If CT command to the NameServer fails to be
4440 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4441 * RSCN activities with the @vport.
4442 *
4443 * Return code
4444 * 0 - Cleaned up rscn on the @vport
4445 * 1 - Wait for plogi to name server before proceed
4446 **/
dea31012005-04-17 16:05:31 -05004447int
James Smart2e0fef82007-06-17 19:56:36 -05004448lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004449{
4450 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004451 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004452
James Smart92d7f7b2007-06-17 19:56:38 -05004453 /* Ignore RSCN if the port is being torn down. */
4454 if (vport->load_flag & FC_UNLOADING) {
4455 lpfc_els_flush_rscn(vport);
4456 return 0;
4457 }
4458
dea31012005-04-17 16:05:31 -05004459 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004460 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004461
4462 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004463 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4464 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4465 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4466 vport->port_state);
dea31012005-04-17 16:05:31 -05004467
4468 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004469 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004470 vport->num_disc_nodes = 0;
4471
James Smart2e0fef82007-06-17 19:56:36 -05004472 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004473 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4474 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004475 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004476 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004477 /* Wait for NameServer query cmpl before we can
4478 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004479 return 1;
dea31012005-04-17 16:05:31 -05004480 } else {
4481 /* If login to NameServer does not exist, issue one */
4482 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004483 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004484 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004485 /* Wait for NameServer login cmpl before we can
4486 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004487 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004488
James Smarte47c9092008-02-08 18:49:26 -05004489 if (ndlp) {
4490 ndlp = lpfc_enable_node(vport, ndlp,
4491 NLP_STE_PLOGI_ISSUE);
4492 if (!ndlp) {
4493 lpfc_els_flush_rscn(vport);
4494 return 0;
4495 }
4496 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004497 } else {
James Smarte47c9092008-02-08 18:49:26 -05004498 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4499 if (!ndlp) {
4500 lpfc_els_flush_rscn(vport);
4501 return 0;
4502 }
James Smart2e0fef82007-06-17 19:56:36 -05004503 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004504 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004505 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004506 }
James Smarte47c9092008-02-08 18:49:26 -05004507 ndlp->nlp_type |= NLP_FABRIC;
4508 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4509 /* Wait for NameServer login cmpl before we can
4510 * continue
4511 */
4512 return 1;
dea31012005-04-17 16:05:31 -05004513 }
4514
James Smart2e0fef82007-06-17 19:56:36 -05004515 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004516 return 0;
dea31012005-04-17 16:05:31 -05004517}
4518
James Smarte59058c2008-08-24 21:49:00 -04004519/**
James Smart3621a712009-04-06 18:47:14 -04004520 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004521 * @vport: pointer to a host virtual N_Port data structure.
4522 * @cmdiocb: pointer to lpfc command iocb data structure.
4523 * @ndlp: pointer to a node-list data structure.
4524 *
4525 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4526 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4527 * point topology. As an unsolicited FLOGI should not be received in a loop
4528 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4529 * lpfc_check_sparm() routine is invoked to check the parameters in the
4530 * unsolicited FLOGI. If parameters validation failed, the routine
4531 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4532 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4533 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4534 * will initiate PLOGI. The higher lexicographical value party shall has
4535 * higher priority (as the winning port) and will initiate PLOGI and
4536 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4537 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4538 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4539 *
4540 * Return code
4541 * 0 - Successfully processed the unsolicited flogi
4542 * 1 - Failed to process the unsolicited flogi
4543 **/
dea31012005-04-17 16:05:31 -05004544static int
James Smart2e0fef82007-06-17 19:56:36 -05004545lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004546 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004547{
James Smart2e0fef82007-06-17 19:56:36 -05004548 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4549 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004550 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4551 uint32_t *lp = (uint32_t *) pcmd->virt;
4552 IOCB_t *icmd = &cmdiocb->iocb;
4553 struct serv_parm *sp;
4554 LPFC_MBOXQ_t *mbox;
4555 struct ls_rjt stat;
4556 uint32_t cmd, did;
4557 int rc;
4558
4559 cmd = *lp++;
4560 sp = (struct serv_parm *) lp;
4561
4562 /* FLOGI received */
4563
James Smart2e0fef82007-06-17 19:56:36 -05004564 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004565
4566 if (phba->fc_topology == TOPOLOGY_LOOP) {
4567 /* We should never receive a FLOGI in loop mode, ignore it */
4568 did = icmd->un.elsreq64.remoteID;
4569
4570 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4571 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004572 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4573 "0113 An FLOGI ELS command x%x was "
4574 "received from DID x%x in Loop Mode\n",
4575 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004576 return 1;
dea31012005-04-17 16:05:31 -05004577 }
4578
4579 did = Fabric_DID;
4580
James Smart341af102010-01-26 23:07:37 -05004581 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004582 /* For a FLOGI we accept, then if our portname is greater
4583 * then the remote portname we initiate Nport login.
4584 */
4585
James Smart2e0fef82007-06-17 19:56:36 -05004586 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004587 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004588
4589 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004590 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4591 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004592 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004593
dea31012005-04-17 16:05:31 -05004594 lpfc_linkdown(phba);
4595 lpfc_init_link(phba, mbox,
4596 phba->cfg_topology,
4597 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004598 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004599 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004600 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004601 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004602 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004603 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004604 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004605 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004606 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004607 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004608 spin_lock_irq(shost->host_lock);
4609 vport->fc_flag |= FC_PT2PT_PLOGI;
4610 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004611 }
James Smart2e0fef82007-06-17 19:56:36 -05004612 spin_lock_irq(shost->host_lock);
4613 vport->fc_flag |= FC_PT2PT;
4614 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4615 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004616 } else {
4617 /* Reject this request because invalid parameters */
4618 stat.un.b.lsRjtRsvd0 = 0;
4619 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4620 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4621 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004622 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4623 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004624 return 1;
dea31012005-04-17 16:05:31 -05004625 }
4626
4627 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004628 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004629
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004630 return 0;
dea31012005-04-17 16:05:31 -05004631}
4632
James Smarte59058c2008-08-24 21:49:00 -04004633/**
James Smart3621a712009-04-06 18:47:14 -04004634 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004635 * @vport: pointer to a host virtual N_Port data structure.
4636 * @cmdiocb: pointer to lpfc command iocb data structure.
4637 * @ndlp: pointer to a node-list data structure.
4638 *
4639 * This routine processes Request Node Identification Data (RNID) IOCB
4640 * received as an ELS unsolicited event. Only when the RNID specified format
4641 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4642 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4643 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4644 * rejected by invoking the lpfc_els_rsp_reject() routine.
4645 *
4646 * Return code
4647 * 0 - Successfully processed rnid iocb (currently always return 0)
4648 **/
dea31012005-04-17 16:05:31 -05004649static int
James Smart2e0fef82007-06-17 19:56:36 -05004650lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4651 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004652{
4653 struct lpfc_dmabuf *pcmd;
4654 uint32_t *lp;
4655 IOCB_t *icmd;
4656 RNID *rn;
4657 struct ls_rjt stat;
4658 uint32_t cmd, did;
4659
4660 icmd = &cmdiocb->iocb;
4661 did = icmd->un.elsreq64.remoteID;
4662 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4663 lp = (uint32_t *) pcmd->virt;
4664
4665 cmd = *lp++;
4666 rn = (RNID *) lp;
4667
4668 /* RNID received */
4669
4670 switch (rn->Format) {
4671 case 0:
4672 case RNID_TOPOLOGY_DISC:
4673 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004674 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004675 break;
4676 default:
4677 /* Reject this request because format not supported */
4678 stat.un.b.lsRjtRsvd0 = 0;
4679 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4680 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4681 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004682 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4683 NULL);
dea31012005-04-17 16:05:31 -05004684 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004685 return 0;
dea31012005-04-17 16:05:31 -05004686}
4687
James Smarte59058c2008-08-24 21:49:00 -04004688/**
James Smart3621a712009-04-06 18:47:14 -04004689 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004690 * @vport: pointer to a host virtual N_Port data structure.
4691 * @cmdiocb: pointer to lpfc command iocb data structure.
4692 * @ndlp: pointer to a node-list data structure.
4693 *
4694 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4695 * received as an ELS unsolicited event. Currently, this function just invokes
4696 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4697 *
4698 * Return code
4699 * 0 - Successfully processed lirr iocb (currently always return 0)
4700 **/
dea31012005-04-17 16:05:31 -05004701static int
James Smart2e0fef82007-06-17 19:56:36 -05004702lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4703 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004704{
4705 struct ls_rjt stat;
4706
4707 /* For now, unconditionally reject this command */
4708 stat.un.b.lsRjtRsvd0 = 0;
4709 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4710 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4711 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004712 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004713 return 0;
4714}
4715
James Smarte59058c2008-08-24 21:49:00 -04004716/**
James Smart5ffc2662009-11-18 15:39:44 -05004717 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4718 * @vport: pointer to a host virtual N_Port data structure.
4719 * @cmdiocb: pointer to lpfc command iocb data structure.
4720 * @ndlp: pointer to a node-list data structure.
4721 *
4722 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4723 * received as an ELS unsolicited event. A request to RRQ shall only
4724 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4725 * Nx_Port N_Port_ID of the target Exchange is the same as the
4726 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4727 * not accepted, an LS_RJT with reason code "Unable to perform
4728 * command request" and reason code explanation "Invalid Originator
4729 * S_ID" shall be returned. For now, we just unconditionally accept
4730 * RRQ from the target.
4731 **/
4732static void
4733lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4734 struct lpfc_nodelist *ndlp)
4735{
4736 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4737}
4738
4739/**
James Smart3621a712009-04-06 18:47:14 -04004740 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004741 * @phba: pointer to lpfc hba data structure.
4742 * @pmb: pointer to the driver internal queue element for mailbox command.
4743 *
4744 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4745 * mailbox command. This callback function is to actually send the Accept
4746 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4747 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4748 * mailbox command, constructs the RPS response with the link statistics
4749 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4750 * response to the RPS.
4751 *
4752 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4753 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4754 * will be stored into the context1 field of the IOCB for the completion
4755 * callback function to the RPS Accept Response ELS IOCB command.
4756 *
4757 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004758static void
James Smart329f9bc2007-04-25 09:53:01 -04004759lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004760{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004761 MAILBOX_t *mb;
4762 IOCB_t *icmd;
4763 RPS_RSP *rps_rsp;
4764 uint8_t *pcmd;
4765 struct lpfc_iocbq *elsiocb;
4766 struct lpfc_nodelist *ndlp;
4767 uint16_t xri, status;
4768 uint32_t cmdsize;
4769
James Smart04c68492009-05-22 14:52:52 -04004770 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004771
4772 ndlp = (struct lpfc_nodelist *) pmb->context2;
4773 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004774 pmb->context1 = NULL;
4775 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004776
4777 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004778 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004779 return;
4780 }
4781
4782 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004783 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004784 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4785 lpfc_max_els_tries, ndlp,
4786 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004787
4788 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004789 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004790
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004791 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004792 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004793
4794 icmd = &elsiocb->iocb;
4795 icmd->ulpContext = xri;
4796
4797 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4798 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004799 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004800 rps_rsp = (RPS_RSP *)pcmd;
4801
4802 if (phba->fc_topology != TOPOLOGY_LOOP)
4803 status = 0x10;
4804 else
4805 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004806 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004807 status |= 0x4;
4808
4809 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004810 rps_rsp->portStatus = cpu_to_be16(status);
4811 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4812 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4813 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4814 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4815 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4816 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004817 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004818 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4819 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4820 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4821 elsiocb->iotag, elsiocb->iocb.ulpContext,
4822 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4823 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004824 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004825 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004826 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004827 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004828 return;
4829}
4830
James Smarte59058c2008-08-24 21:49:00 -04004831/**
James Smart3621a712009-04-06 18:47:14 -04004832 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04004833 * @vport: pointer to a host virtual N_Port data structure.
4834 * @cmdiocb: pointer to lpfc command iocb data structure.
4835 * @ndlp: pointer to a node-list data structure.
4836 *
4837 * This routine processes Read Port Status (RPS) IOCB received as an
4838 * ELS unsolicited event. It first checks the remote port state. If the
4839 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4840 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4841 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4842 * for reading the HBA link statistics. It is for the callback function,
4843 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4844 * to actually sending out RPS Accept (ACC) response.
4845 *
4846 * Return codes
4847 * 0 - Successfully processed rps iocb (currently always return 0)
4848 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004849static int
James Smart2e0fef82007-06-17 19:56:36 -05004850lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4851 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004852{
James Smart2e0fef82007-06-17 19:56:36 -05004853 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004854 uint32_t *lp;
4855 uint8_t flag;
4856 LPFC_MBOXQ_t *mbox;
4857 struct lpfc_dmabuf *pcmd;
4858 RPS *rps;
4859 struct ls_rjt stat;
4860
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004861 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04004862 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4863 /* reject the unsolicited RPS request and done with it */
4864 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004865
4866 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4867 lp = (uint32_t *) pcmd->virt;
4868 flag = (be32_to_cpu(*lp++) & 0xf);
4869 rps = (RPS *) lp;
4870
4871 if ((flag == 0) ||
4872 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05004873 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004874 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05004875
James Smart92d7f7b2007-06-17 19:56:38 -05004876 printk("Fix me....\n");
4877 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05004878 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4879 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004880 lpfc_read_lnk_stat(phba, mbox);
4881 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05004882 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04004883 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004884 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004885 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05004886 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04004887 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004888 /* Mbox completion will send ELS Response */
4889 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05004890 /* Decrement reference count used for the failed mbox
4891 * command.
4892 */
James Smart329f9bc2007-04-25 09:53:01 -04004893 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004894 mempool_free(mbox, phba->mbox_mem_pool);
4895 }
4896 }
James Smart90160e02008-08-24 21:49:45 -04004897
4898reject_out:
4899 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004900 stat.un.b.lsRjtRsvd0 = 0;
4901 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4902 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4903 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004904 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004905 return 0;
4906}
4907
James Smarte59058c2008-08-24 21:49:00 -04004908/**
James Smart3621a712009-04-06 18:47:14 -04004909 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04004910 * @vport: pointer to a host virtual N_Port data structure.
4911 * @cmdsize: size of the ELS command.
4912 * @oldiocb: pointer to the original lpfc command iocb data structure.
4913 * @ndlp: pointer to a node-list data structure.
4914 *
4915 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4916 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4917 *
4918 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4919 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4920 * will be stored into the context1 field of the IOCB for the completion
4921 * callback function to the RPL Accept Response ELS command.
4922 *
4923 * Return code
4924 * 0 - Successfully issued ACC RPL ELS command
4925 * 1 - Failed to issue ACC RPL ELS command
4926 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004927static int
James Smart2e0fef82007-06-17 19:56:36 -05004928lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4929 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004930{
James Smart2e0fef82007-06-17 19:56:36 -05004931 struct lpfc_hba *phba = vport->phba;
4932 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004933 RPL_RSP rpl_rsp;
4934 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004935 uint8_t *pcmd;
4936
James Smart2e0fef82007-06-17 19:56:36 -05004937 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4938 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004939
James Smart488d1462006-03-07 15:02:37 -05004940 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004941 return 1;
James Smart488d1462006-03-07 15:02:37 -05004942
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004943 icmd = &elsiocb->iocb;
4944 oldcmd = &oldiocb->iocb;
4945 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4946
4947 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4948 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004949 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004950 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4951 pcmd += sizeof(uint16_t);
4952
4953 /* Setup the RPL ACC payload */
4954 rpl_rsp.listLen = be32_to_cpu(1);
4955 rpl_rsp.index = 0;
4956 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004957 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4958 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004959 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004960 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004961 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004962 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4963 "0120 Xmit ELS RPL ACC response tag x%x "
4964 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4965 "rpi x%x\n",
4966 elsiocb->iotag, elsiocb->iocb.ulpContext,
4967 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4968 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004969 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004970 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004971 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
4972 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004973 lpfc_els_free_iocb(phba, elsiocb);
4974 return 1;
4975 }
4976 return 0;
4977}
4978
James Smarte59058c2008-08-24 21:49:00 -04004979/**
James Smart3621a712009-04-06 18:47:14 -04004980 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04004981 * @vport: pointer to a host virtual N_Port data structure.
4982 * @cmdiocb: pointer to lpfc command iocb data structure.
4983 * @ndlp: pointer to a node-list data structure.
4984 *
4985 * This routine processes Read Port List (RPL) IOCB received as an ELS
4986 * unsolicited event. It first checks the remote port state. If the remote
4987 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4988 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4989 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4990 * to accept the RPL.
4991 *
4992 * Return code
4993 * 0 - Successfully processed rpl iocb (currently always return 0)
4994 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004995static int
James Smart2e0fef82007-06-17 19:56:36 -05004996lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4997 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004998{
4999 struct lpfc_dmabuf *pcmd;
5000 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005001 uint32_t maxsize;
5002 uint16_t cmdsize;
5003 RPL *rpl;
5004 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005005
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005006 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5007 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005008 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005009 stat.un.b.lsRjtRsvd0 = 0;
5010 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5011 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5012 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005013 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5014 NULL);
James Smart90160e02008-08-24 21:49:45 -04005015 /* rejected the unsolicited RPL request and done with it */
5016 return 0;
dea31012005-04-17 16:05:31 -05005017 }
5018
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005019 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5020 lp = (uint32_t *) pcmd->virt;
5021 rpl = (RPL *) (lp + 1);
5022
5023 maxsize = be32_to_cpu(rpl->maxsize);
5024
5025 /* We support only one port */
5026 if ((rpl->index == 0) &&
5027 ((maxsize == 0) ||
5028 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5029 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005030 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005031 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5032 }
James Smart2e0fef82007-06-17 19:56:36 -05005033 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005034
5035 return 0;
5036}
5037
James Smarte59058c2008-08-24 21:49:00 -04005038/**
James Smart3621a712009-04-06 18:47:14 -04005039 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005040 * @vport: pointer to a virtual N_Port data structure.
5041 * @cmdiocb: pointer to lpfc command iocb data structure.
5042 * @ndlp: pointer to a node-list data structure.
5043 *
5044 * This routine processes Fibre Channel Address Resolution Protocol
5045 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5046 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5047 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5048 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5049 * remote PortName is compared against the FC PortName stored in the @vport
5050 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5051 * compared against the FC NodeName stored in the @vport data structure.
5052 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5053 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5054 * invoked to send out FARP Response to the remote node. Before sending the
5055 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5056 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5057 * routine is invoked to log into the remote port first.
5058 *
5059 * Return code
5060 * 0 - Either the FARP Match Mode not supported or successfully processed
5061 **/
dea31012005-04-17 16:05:31 -05005062static int
James Smart2e0fef82007-06-17 19:56:36 -05005063lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5064 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005065{
5066 struct lpfc_dmabuf *pcmd;
5067 uint32_t *lp;
5068 IOCB_t *icmd;
5069 FARP *fp;
5070 uint32_t cmd, cnt, did;
5071
5072 icmd = &cmdiocb->iocb;
5073 did = icmd->un.elsreq64.remoteID;
5074 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5075 lp = (uint32_t *) pcmd->virt;
5076
5077 cmd = *lp++;
5078 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005079 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005080 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5081 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005082 /* We will only support match on WWPN or WWNN */
5083 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005084 return 0;
dea31012005-04-17 16:05:31 -05005085 }
5086
5087 cnt = 0;
5088 /* If this FARP command is searching for my portname */
5089 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005090 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005091 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005092 cnt = 1;
5093 }
5094
5095 /* If this FARP command is searching for my nodename */
5096 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005097 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005098 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005099 cnt = 1;
5100 }
5101
5102 if (cnt) {
5103 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5104 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5105 /* Log back into the node before sending the FARP. */
5106 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005107 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005108 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005109 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005110 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005111 }
5112
5113 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005114 if (fp->Rflags & FARP_REQUEST_FARPR)
5115 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005116 }
5117 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005118 return 0;
dea31012005-04-17 16:05:31 -05005119}
5120
James Smarte59058c2008-08-24 21:49:00 -04005121/**
James Smart3621a712009-04-06 18:47:14 -04005122 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005123 * @vport: pointer to a host virtual N_Port data structure.
5124 * @cmdiocb: pointer to lpfc command iocb data structure.
5125 * @ndlp: pointer to a node-list data structure.
5126 *
5127 * This routine processes Fibre Channel Address Resolution Protocol
5128 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5129 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5130 * the FARP response request.
5131 *
5132 * Return code
5133 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5134 **/
dea31012005-04-17 16:05:31 -05005135static int
James Smart2e0fef82007-06-17 19:56:36 -05005136lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5137 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005138{
5139 struct lpfc_dmabuf *pcmd;
5140 uint32_t *lp;
5141 IOCB_t *icmd;
5142 uint32_t cmd, did;
5143
5144 icmd = &cmdiocb->iocb;
5145 did = icmd->un.elsreq64.remoteID;
5146 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5147 lp = (uint32_t *) pcmd->virt;
5148
5149 cmd = *lp++;
5150 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005151 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5152 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005153 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005154 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005155
5156 return 0;
5157}
5158
James Smarte59058c2008-08-24 21:49:00 -04005159/**
James Smart3621a712009-04-06 18:47:14 -04005160 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005161 * @vport: pointer to a host virtual N_Port data structure.
5162 * @cmdiocb: pointer to lpfc command iocb data structure.
5163 * @fan_ndlp: pointer to a node-list data structure.
5164 *
5165 * This routine processes a Fabric Address Notification (FAN) IOCB
5166 * command received as an ELS unsolicited event. The FAN ELS command will
5167 * only be processed on a physical port (i.e., the @vport represents the
5168 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5169 * compared against those in the phba data structure. If any of those is
5170 * different, the lpfc_initial_flogi() routine is invoked to initialize
5171 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5172 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5173 * is invoked to register login to the fabric.
5174 *
5175 * Return code
5176 * 0 - Successfully processed fan iocb (currently always return 0).
5177 **/
dea31012005-04-17 16:05:31 -05005178static int
James Smart2e0fef82007-06-17 19:56:36 -05005179lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5180 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005181{
James Smart2e0fef82007-06-17 19:56:36 -05005182 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005183 uint32_t *lp;
5184 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005185
James Smart0d2b6b82008-06-14 22:52:47 -04005186 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5187 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5188 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005189 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005190 if ((vport == phba->pport) &&
5191 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005192 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005193 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005194 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005195 sizeof(struct lpfc_name)))) {
5196 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05005197 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005198 } else {
5199 /* FAN verified - skip FLOGI */
5200 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005201 if (phba->sli_rev < LPFC_SLI_REV4)
5202 lpfc_issue_fabric_reglogin(vport);
5203 else
5204 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005205 }
dea31012005-04-17 16:05:31 -05005206 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005207 return 0;
dea31012005-04-17 16:05:31 -05005208}
5209
James Smarte59058c2008-08-24 21:49:00 -04005210/**
James Smart3621a712009-04-06 18:47:14 -04005211 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005212 * @ptr: holder for the timer function associated data.
5213 *
5214 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5215 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5216 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5217 * up the worker thread. It is for the worker thread to invoke the routine
5218 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5219 **/
dea31012005-04-17 16:05:31 -05005220void
5221lpfc_els_timeout(unsigned long ptr)
5222{
James Smart2e0fef82007-06-17 19:56:36 -05005223 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5224 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005225 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005226 unsigned long iflag;
5227
James Smart2e0fef82007-06-17 19:56:36 -05005228 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005229 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5230 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005231 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005232 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005233
James Smart5e9d9b82008-06-14 22:52:53 -04005234 if (!tmo_posted)
5235 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005236 return;
5237}
5238
James Smart2a9bf3d2010-06-07 15:24:45 -04005239
James Smarte59058c2008-08-24 21:49:00 -04005240/**
James Smart3621a712009-04-06 18:47:14 -04005241 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005242 * @vport: pointer to a virtual N_Port data structure.
5243 *
5244 * This routine is the actual handler function that processes an ELS timeout
5245 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5246 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5247 * invoking the lpfc_sli_issue_abort_iotag() routine.
5248 **/
dea31012005-04-17 16:05:31 -05005249void
James Smart2e0fef82007-06-17 19:56:36 -05005250lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005251{
James Smart2e0fef82007-06-17 19:56:36 -05005252 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005253 struct lpfc_sli_ring *pring;
5254 struct lpfc_iocbq *tmp_iocb, *piocb;
5255 IOCB_t *cmd = NULL;
5256 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005257 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005258 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005259 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005260 LIST_HEAD(txcmplq_completions);
5261 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005262
James Smart2a9bf3d2010-06-07 15:24:45 -04005263
dea31012005-04-17 16:05:31 -05005264 timeout = (uint32_t)(phba->fc_ratov << 1);
5265
5266 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005267
James Smart2a9bf3d2010-06-07 15:24:45 -04005268 spin_lock_irq(&phba->hbalock);
5269 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5270 spin_unlock_irq(&phba->hbalock);
5271
5272 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005273 cmd = &piocb->iocb;
5274
James Smart2e0fef82007-06-17 19:56:36 -05005275 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5276 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5277 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005278 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005279
5280 if (piocb->vport != vport)
5281 continue;
5282
dea31012005-04-17 16:05:31 -05005283 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005284 if (pcmd)
5285 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005286
James Smart92d7f7b2007-06-17 19:56:38 -05005287 if (els_command == ELS_CMD_FARP ||
5288 els_command == ELS_CMD_FARPR ||
5289 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005290 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005291
dea31012005-04-17 16:05:31 -05005292 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005293 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005294 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005295 else
dea31012005-04-17 16:05:31 -05005296 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005297 continue;
5298 }
5299
James Smart2e0fef82007-06-17 19:56:36 -05005300 remote_ID = 0xffffffff;
5301 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005302 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005303 else {
5304 struct lpfc_nodelist *ndlp;
5305 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005306 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005307 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005308 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005309 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05005310 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005311 spin_lock_irq(&phba->hbalock);
5312 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05005313 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005314
James Smart2a9bf3d2010-06-07 15:24:45 -04005315 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5316 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5317 "0127 ELS timeout Data: x%x x%x x%x "
5318 "x%x\n", els_command,
5319 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5320 spin_lock_irq(&phba->hbalock);
5321 list_del_init(&piocb->dlist);
5322 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5323 spin_unlock_irq(&phba->hbalock);
5324 }
5325
James Smart2e0fef82007-06-17 19:56:36 -05005326 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5327 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005328}
5329
James Smarte59058c2008-08-24 21:49:00 -04005330/**
James Smart3621a712009-04-06 18:47:14 -04005331 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005332 * @vport: pointer to a host virtual N_Port data structure.
5333 *
5334 * This routine is used to clean up all the outstanding ELS commands on a
5335 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5336 * routine. After that, it walks the ELS transmit queue to remove all the
5337 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5338 * the IOCBs with a non-NULL completion callback function, the callback
5339 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5340 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5341 * callback function, the IOCB will simply be released. Finally, it walks
5342 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5343 * completion queue IOCB that is associated with the @vport and is not
5344 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5345 * part of the discovery state machine) out to HBA by invoking the
5346 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5347 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5348 * the IOCBs are aborted when this function returns.
5349 **/
dea31012005-04-17 16:05:31 -05005350void
James Smart2e0fef82007-06-17 19:56:36 -05005351lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005352{
James Smart2534ba72007-04-25 09:52:20 -04005353 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005354 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005355 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005356 struct lpfc_iocbq *tmp_iocb, *piocb;
5357 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005358
5359 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005360
James Smart2e0fef82007-06-17 19:56:36 -05005361 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005362 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5363 cmd = &piocb->iocb;
5364
5365 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5366 continue;
5367 }
5368
5369 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005370 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5371 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5372 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5373 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005374 continue;
dea31012005-04-17 16:05:31 -05005375
James Smart2e0fef82007-06-17 19:56:36 -05005376 if (piocb->vport != vport)
5377 continue;
5378
James Smart2534ba72007-04-25 09:52:20 -04005379 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005380 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005381 }
5382
5383 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005384 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5385 continue;
5386 }
dea31012005-04-17 16:05:31 -05005387
James Smart2e0fef82007-06-17 19:56:36 -05005388 if (piocb->vport != vport)
5389 continue;
5390
James Smart07951072007-04-25 09:51:38 -04005391 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005392 }
James Smart2e0fef82007-06-17 19:56:36 -05005393 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005394
James Smarta257bf92009-04-06 18:48:10 -04005395 /* Cancell all the IOCBs from the completions list */
5396 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5397 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005398
dea31012005-04-17 16:05:31 -05005399 return;
5400}
5401
James Smarte59058c2008-08-24 21:49:00 -04005402/**
James Smart3621a712009-04-06 18:47:14 -04005403 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005404 * @phba: pointer to lpfc hba data structure.
5405 *
5406 * This routine is used to clean up all the outstanding ELS commands on a
5407 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5408 * routine. After that, it walks the ELS transmit queue to remove all the
5409 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5410 * the IOCBs with the completion callback function associated, the callback
5411 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5412 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5413 * callback function associated, the IOCB will simply be released. Finally,
5414 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5415 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5416 * management plane IOCBs that are not part of the discovery state machine)
5417 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5418 **/
James Smart549e55c2007-08-02 11:09:51 -04005419void
5420lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5421{
5422 LIST_HEAD(completions);
5423 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5424 struct lpfc_iocbq *tmp_iocb, *piocb;
5425 IOCB_t *cmd = NULL;
5426
5427 lpfc_fabric_abort_hba(phba);
5428 spin_lock_irq(&phba->hbalock);
5429 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5430 cmd = &piocb->iocb;
5431 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5432 continue;
5433 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5434 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5435 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5436 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5437 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5438 continue;
5439 list_move_tail(&piocb->list, &completions);
5440 pring->txq_cnt--;
5441 }
5442 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5443 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5444 continue;
5445 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5446 }
5447 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005448
5449 /* Cancel all the IOCBs from the completions list */
5450 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5451 IOERR_SLI_ABORTED);
5452
James Smart549e55c2007-08-02 11:09:51 -04005453 return;
5454}
5455
James Smarte59058c2008-08-24 21:49:00 -04005456/**
James Smart3621a712009-04-06 18:47:14 -04005457 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005458 * @phba: Pointer to hba context object.
5459 * @cmdiocbp: Pointer to command iocb which reported error.
5460 * @rspiocbp: Pointer to response iocb which reported error.
5461 *
5462 * This function sends an event when there is an ELS command
5463 * failure.
5464 **/
5465void
5466lpfc_send_els_failure_event(struct lpfc_hba *phba,
5467 struct lpfc_iocbq *cmdiocbp,
5468 struct lpfc_iocbq *rspiocbp)
5469{
5470 struct lpfc_vport *vport = cmdiocbp->vport;
5471 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5472 struct lpfc_lsrjt_event lsrjt_event;
5473 struct lpfc_fabric_event_header fabric_event;
5474 struct ls_rjt stat;
5475 struct lpfc_nodelist *ndlp;
5476 uint32_t *pcmd;
5477
5478 ndlp = cmdiocbp->context1;
5479 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5480 return;
5481
5482 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5483 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5484 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5485 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5486 sizeof(struct lpfc_name));
5487 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5488 sizeof(struct lpfc_name));
5489 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5490 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04005491 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04005492 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5493 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5494 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5495 fc_host_post_vendor_event(shost,
5496 fc_get_event_number(),
5497 sizeof(lsrjt_event),
5498 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005499 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005500 return;
5501 }
5502 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5503 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5504 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5505 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5506 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5507 else
5508 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5509 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5510 sizeof(struct lpfc_name));
5511 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5512 sizeof(struct lpfc_name));
5513 fc_host_post_vendor_event(shost,
5514 fc_get_event_number(),
5515 sizeof(fabric_event),
5516 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005517 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005518 return;
5519 }
5520
5521}
5522
5523/**
James Smart3621a712009-04-06 18:47:14 -04005524 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04005525 * @vport: Pointer to vport object.
5526 * @ndlp: Pointer FC node object.
5527 * @cmd: ELS command code.
5528 *
5529 * This function posts an event when there is an incoming
5530 * unsolicited ELS command.
5531 **/
5532static void
5533lpfc_send_els_event(struct lpfc_vport *vport,
5534 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005535 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005536{
James Smartddcc50f2008-12-04 22:38:46 -05005537 struct lpfc_els_event_header *els_data = NULL;
5538 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005539 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5540
James Smartddcc50f2008-12-04 22:38:46 -05005541 if (*payload == ELS_CMD_LOGO) {
5542 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5543 if (!logo_data) {
5544 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5545 "0148 Failed to allocate memory "
5546 "for LOGO event\n");
5547 return;
5548 }
5549 els_data = &logo_data->header;
5550 } else {
5551 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5552 GFP_KERNEL);
5553 if (!els_data) {
5554 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5555 "0149 Failed to allocate memory "
5556 "for ELS event\n");
5557 return;
5558 }
5559 }
5560 els_data->event_type = FC_REG_ELS_EVENT;
5561 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005562 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005563 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005564 break;
5565 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005566 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005567 break;
5568 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005569 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5570 break;
5571 case ELS_CMD_LOGO:
5572 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5573 /* Copy the WWPN in the LOGO payload */
5574 memcpy(logo_data->logo_wwpn, &payload[2],
5575 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005576 break;
5577 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005578 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005579 return;
5580 }
James Smartddcc50f2008-12-04 22:38:46 -05005581 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5582 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5583 if (*payload == ELS_CMD_LOGO) {
5584 fc_host_post_vendor_event(shost,
5585 fc_get_event_number(),
5586 sizeof(struct lpfc_logo_event),
5587 (char *)logo_data,
5588 LPFC_NL_VENDOR_ID);
5589 kfree(logo_data);
5590 } else {
5591 fc_host_post_vendor_event(shost,
5592 fc_get_event_number(),
5593 sizeof(struct lpfc_els_event_header),
5594 (char *)els_data,
5595 LPFC_NL_VENDOR_ID);
5596 kfree(els_data);
5597 }
James Smartea2151b2008-09-07 11:52:10 -04005598
5599 return;
5600}
5601
5602
5603/**
James Smart3621a712009-04-06 18:47:14 -04005604 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04005605 * @phba: pointer to lpfc hba data structure.
5606 * @pring: pointer to a SLI ring.
5607 * @vport: pointer to a host virtual N_Port data structure.
5608 * @elsiocb: pointer to lpfc els command iocb data structure.
5609 *
5610 * This routine is used for processing the IOCB associated with a unsolicited
5611 * event. It first determines whether there is an existing ndlp that matches
5612 * the DID from the unsolicited IOCB. If not, it will create a new one with
5613 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5614 * IOCB is then used to invoke the proper routine and to set up proper state
5615 * of the discovery state machine.
5616 **/
James Smarted957682007-06-17 19:56:37 -05005617static void
5618lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005619 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005620{
James Smart87af33f2007-10-27 13:37:43 -04005621 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005622 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005623 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005624 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005625 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005626 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005627
James Smarte47c9092008-02-08 18:49:26 -05005628 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005629 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005630
dea31012005-04-17 16:05:31 -05005631 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005632 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5633 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005634 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005635 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005636
James Smart858c9f62007-06-17 19:56:39 -05005637 did = icmd->un.rcvels.remoteID;
5638 if (icmd->ulpStatus) {
5639 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5640 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5641 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005642 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005643 }
dea31012005-04-17 16:05:31 -05005644
5645 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005646 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005647 goto dropit;
dea31012005-04-17 16:05:31 -05005648
James Smartc8685952009-11-18 15:39:16 -05005649 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05005650 if (vport->load_flag & FC_UNLOADING)
5651 goto dropit;
5652
James Smart2e0fef82007-06-17 19:56:36 -05005653 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005654 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005655 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005656 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005657 if (!ndlp)
dea31012005-04-17 16:05:31 -05005658 goto dropit;
dea31012005-04-17 16:05:31 -05005659
James Smart2e0fef82007-06-17 19:56:36 -05005660 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005661 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005662 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005663 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005664 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005665 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5666 ndlp = lpfc_enable_node(vport, ndlp,
5667 NLP_STE_UNUSED_NODE);
5668 if (!ndlp)
5669 goto dropit;
5670 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5671 newnode = 1;
5672 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5673 ndlp->nlp_type |= NLP_FABRIC;
5674 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5675 /* This is similar to the new node path */
5676 ndlp = lpfc_nlp_get(ndlp);
5677 if (!ndlp)
5678 goto dropit;
5679 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5680 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005681 }
dea31012005-04-17 16:05:31 -05005682
5683 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005684
James Smart329f9bc2007-04-25 09:53:01 -04005685 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005686 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005687
5688 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5689 cmd &= ELS_CMD_MASK;
5690 }
5691 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005692 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5693 "0112 ELS command x%x received from NPORT x%x "
5694 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005695 switch (cmd) {
5696 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005697 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5698 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5699 did, vport->port_state, ndlp->nlp_flag);
5700
dea31012005-04-17 16:05:31 -05005701 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005702 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5703
James Smartddcc50f2008-12-04 22:38:46 -05005704 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05005705 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05005706 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5707 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5708 rjt_err = LSRJT_UNABLE_TPC;
5709 break;
5710 }
5711 /* We get here, and drop thru, if we are PT2PT with
5712 * another NPort and the other side has initiated
5713 * the PLOGI before responding to our FLOGI.
5714 */
dea31012005-04-17 16:05:31 -05005715 }
James Smart87af33f2007-10-27 13:37:43 -04005716
5717 shost = lpfc_shost_from_vport(vport);
5718 spin_lock_irq(shost->host_lock);
5719 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5720 spin_unlock_irq(shost->host_lock);
5721
James Smart2e0fef82007-06-17 19:56:36 -05005722 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5723 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05005724
dea31012005-04-17 16:05:31 -05005725 break;
5726 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005727 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5728 "RCV FLOGI: 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.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04005732 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005733 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005734 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005735 break;
5736 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05005737 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5738 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5739 did, vport->port_state, ndlp->nlp_flag);
5740
dea31012005-04-17 16:05:31 -05005741 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05005742 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005743 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005744 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005745 break;
5746 }
James Smart2e0fef82007-06-17 19:56:36 -05005747 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05005748 break;
5749 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05005750 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5751 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5752 did, vport->port_state, ndlp->nlp_flag);
5753
dea31012005-04-17 16:05:31 -05005754 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05005755 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005756 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005757 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005758 break;
5759 }
James Smart2e0fef82007-06-17 19:56:36 -05005760 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05005761 break;
5762 case ELS_CMD_RSCN:
5763 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04005764 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005765 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005766 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005767 break;
5768 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05005769 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5770 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5771 did, vport->port_state, ndlp->nlp_flag);
5772
James Smartddcc50f2008-12-04 22:38:46 -05005773 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05005774 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005775 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005776 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005777 break;
5778 }
James Smart2e0fef82007-06-17 19:56:36 -05005779 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5780 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05005781 break;
5782 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05005783 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5784 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5785 did, vport->port_state, ndlp->nlp_flag);
5786
dea31012005-04-17 16:05:31 -05005787 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005788 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005789 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005790 break;
5791 }
James Smart2e0fef82007-06-17 19:56:36 -05005792 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5793 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05005794 break;
5795 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05005796 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5797 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5798 did, vport->port_state, ndlp->nlp_flag);
5799
dea31012005-04-17 16:05:31 -05005800 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05005801 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005802 break;
5803 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05005804 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5805 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5806 did, vport->port_state, ndlp->nlp_flag);
5807
dea31012005-04-17 16:05:31 -05005808 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05005809 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005810 break;
5811 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05005812 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5813 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5814 did, vport->port_state, ndlp->nlp_flag);
5815
dea31012005-04-17 16:05:31 -05005816 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05005817 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005818 break;
dea31012005-04-17 16:05:31 -05005819 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05005820 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5821 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5822 did, vport->port_state, ndlp->nlp_flag);
5823
dea31012005-04-17 16:05:31 -05005824 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05005825 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005826 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005827 break;
5828 }
James Smart2e0fef82007-06-17 19:56:36 -05005829 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05005830 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005831 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05005832 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5833 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5834 did, vport->port_state, ndlp->nlp_flag);
5835
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005836 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05005837 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005838 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005839 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005840 break;
5841 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05005842 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5843 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5844 did, vport->port_state, ndlp->nlp_flag);
5845
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005846 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05005847 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005848 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005849 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005850 break;
5851 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05005852 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5853 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5854 did, vport->port_state, ndlp->nlp_flag);
5855
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005856 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05005857 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005858 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005859 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005860 break;
dea31012005-04-17 16:05:31 -05005861 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05005862 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5863 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5864 did, vport->port_state, ndlp->nlp_flag);
5865
dea31012005-04-17 16:05:31 -05005866 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05005867 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005868 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005869 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005870 break;
James Smart5ffc2662009-11-18 15:39:44 -05005871 case ELS_CMD_RRQ:
5872 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5873 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
5874 did, vport->port_state, ndlp->nlp_flag);
5875
5876 phba->fc_stat.elsRcvRRQ++;
5877 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
5878 if (newnode)
5879 lpfc_nlp_put(ndlp);
5880 break;
dea31012005-04-17 16:05:31 -05005881 default:
James Smart858c9f62007-06-17 19:56:39 -05005882 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5883 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5884 cmd, did, vport->port_state);
5885
dea31012005-04-17 16:05:31 -05005886 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05005887 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05005888
5889 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005890 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5891 "0115 Unknown ELS command x%x "
5892 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04005893 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005894 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005895 break;
5896 }
5897
5898 /* check if need to LS_RJT received ELS cmd */
5899 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05005900 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05005901 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04005902 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05005903 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5904 NULL);
dea31012005-04-17 16:05:31 -05005905 }
5906
James Smartd7c255b2008-08-24 21:50:00 -04005907 lpfc_nlp_put(elsiocb->context1);
5908 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05005909 return;
5910
5911dropit:
James Smart98c9ea52007-10-27 13:37:33 -04005912 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04005913 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5914 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05005915 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04005916 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05005917 phba->fc_stat.elsRcvDrop++;
5918}
5919
James Smarte59058c2008-08-24 21:49:00 -04005920/**
James Smart3621a712009-04-06 18:47:14 -04005921 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04005922 * @phba: pointer to lpfc hba data structure.
5923 * @vpi: host virtual N_Port identifier.
5924 *
5925 * This routine finds a vport on a HBA (referred by @phba) through a
5926 * @vpi. The function walks the HBA's vport list and returns the address
5927 * of the vport with the matching @vpi.
5928 *
5929 * Return code
5930 * NULL - No vport with the matching @vpi found
5931 * Otherwise - Address to the vport with the matching @vpi.
5932 **/
James Smart6669f9b2009-10-02 15:16:45 -04005933struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05005934lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5935{
5936 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04005937 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05005938
James Smart549e55c2007-08-02 11:09:51 -04005939 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005940 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04005941 if (vport->vpi == vpi) {
5942 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005943 return vport;
James Smart549e55c2007-08-02 11:09:51 -04005944 }
James Smart92d7f7b2007-06-17 19:56:38 -05005945 }
James Smart549e55c2007-08-02 11:09:51 -04005946 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005947 return NULL;
5948}
James Smarted957682007-06-17 19:56:37 -05005949
James Smarte59058c2008-08-24 21:49:00 -04005950/**
James Smart3621a712009-04-06 18:47:14 -04005951 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04005952 * @phba: pointer to lpfc hba data structure.
5953 * @pring: pointer to a SLI ring.
5954 * @elsiocb: pointer to lpfc els iocb data structure.
5955 *
5956 * This routine is used to process an unsolicited event received from a SLI
5957 * (Service Level Interface) ring. The actual processing of the data buffer
5958 * associated with the unsolicited event is done by invoking the routine
5959 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5960 * SLI ring on which the unsolicited event was received.
5961 **/
James Smarted957682007-06-17 19:56:37 -05005962void
5963lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5964 struct lpfc_iocbq *elsiocb)
5965{
5966 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05005967 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05005968 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05005969 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5970 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05005971
James Smartd7c255b2008-08-24 21:50:00 -04005972 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005973 elsiocb->context2 = NULL;
5974 elsiocb->context3 = NULL;
5975
5976 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5977 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5978 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5979 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05005980 phba->fc_stat.NoRcvBuf++;
5981 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05005982 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04005983 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05005984 return;
5985 }
5986
James Smart92d7f7b2007-06-17 19:56:38 -05005987 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5988 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5989 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5990 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5991 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04005992 else
5993 vport = lpfc_find_vport_by_vpid(phba,
5994 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05005995 }
James Smart7f5f3d02008-02-08 18:50:14 -05005996 /* If there are no BDEs associated
5997 * with this IOCB, there is nothing to do.
5998 */
James Smarted957682007-06-17 19:56:37 -05005999 if (icmd->ulpBdeCount == 0)
6000 return;
6001
James Smart7f5f3d02008-02-08 18:50:14 -05006002 /* type of ELS cmd is first 32bit word
6003 * in packet
6004 */
James Smarted957682007-06-17 19:56:37 -05006005 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006006 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006007 } else {
6008 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6009 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006010 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6011 paddr);
James Smarted957682007-06-17 19:56:37 -05006012 }
6013
James Smart92d7f7b2007-06-17 19:56:38 -05006014 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6015 /*
6016 * The different unsolicited event handlers would tell us
6017 * if they are done with "mp" by setting context2 to NULL.
6018 */
dea31012005-04-17 16:05:31 -05006019 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006020 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6021 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006022 }
James Smarted957682007-06-17 19:56:37 -05006023
6024 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006025 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006026 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006027 elsiocb->context2 = bdeBuf2;
6028 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006029 /* free mp if we are done with it */
6030 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006031 lpfc_in_buf_free(phba, elsiocb->context2);
6032 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006033 }
dea31012005-04-17 16:05:31 -05006034 }
dea31012005-04-17 16:05:31 -05006035}
James Smart92d7f7b2007-06-17 19:56:38 -05006036
James Smarte59058c2008-08-24 21:49:00 -04006037/**
James Smart3621a712009-04-06 18:47:14 -04006038 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006039 * @phba: pointer to lpfc hba data structure.
6040 * @vport: pointer to a virtual N_Port data structure.
6041 *
6042 * This routine issues a Port Login (PLOGI) to the Name Server with
6043 * State Change Request (SCR) for a @vport. This routine will create an
6044 * ndlp for the Name Server associated to the @vport if such node does
6045 * not already exist. The PLOGI to Name Server is issued by invoking the
6046 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6047 * (FDMI) is configured to the @vport, a FDMI node will be created and
6048 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6049 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006050void
6051lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6052{
6053 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
6054
6055 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6056 if (!ndlp) {
6057 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6058 if (!ndlp) {
6059 if (phba->fc_topology == TOPOLOGY_LOOP) {
6060 lpfc_disc_start(vport);
6061 return;
6062 }
6063 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006064 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6065 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006066 return;
6067 }
6068 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006069 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6070 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6071 if (!ndlp) {
6072 if (phba->fc_topology == TOPOLOGY_LOOP) {
6073 lpfc_disc_start(vport);
6074 return;
6075 }
6076 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6077 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6078 "0348 NameServer login: node freed\n");
6079 return;
6080 }
James Smart92d7f7b2007-06-17 19:56:38 -05006081 }
James Smart58da1ff2008-04-07 10:15:56 -04006082 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006083
6084 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6085
6086 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6087 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006088 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6089 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006090 return;
6091 }
6092
James Smart3de2a652007-08-02 11:09:59 -04006093 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05006094 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6095 GFP_KERNEL);
6096 if (ndlp_fdmi) {
6097 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6098 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006099 lpfc_nlp_set_state(vport, ndlp_fdmi,
6100 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05006101 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
6102 0);
6103 }
6104 }
6105 return;
6106}
6107
James Smarte59058c2008-08-24 21:49:00 -04006108/**
James Smart3621a712009-04-06 18:47:14 -04006109 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006110 * @phba: pointer to lpfc hba data structure.
6111 * @pmb: pointer to the driver internal queue element for mailbox command.
6112 *
6113 * This routine is the completion callback function to register new vport
6114 * mailbox command. If the new vport mailbox command completes successfully,
6115 * the fabric registration login shall be performed on physical port (the
6116 * new vport created is actually a physical port, with VPI 0) or the port
6117 * login to Name Server for State Change Request (SCR) will be performed
6118 * on virtual port (real virtual port, with VPI greater than 0).
6119 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006120static void
6121lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6122{
6123 struct lpfc_vport *vport = pmb->vport;
6124 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6125 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006126 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006127 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006128
James Smart09372822008-01-11 01:52:54 -05006129 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006130 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006131 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006132
6133 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006134 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006135 "0915 Register VPI failed : Status: x%x"
6136 " upd bit: x%x \n", mb->mbxStatus,
6137 mb->un.varRegVpi.upd);
6138 if (phba->sli_rev == LPFC_SLI_REV4 &&
6139 mb->un.varRegVpi.upd)
6140 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006141
6142 switch (mb->mbxStatus) {
6143 case 0x11: /* unsupported feature */
6144 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006145 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006146 /* giving up on vport registration */
6147 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6148 spin_lock_irq(shost->host_lock);
6149 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6150 spin_unlock_irq(shost->host_lock);
6151 lpfc_can_disctmo(vport);
6152 break;
James Smart695a8142010-01-26 23:08:03 -05006153 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6154 case 0x20:
6155 spin_lock_irq(shost->host_lock);
6156 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6157 spin_unlock_irq(shost->host_lock);
6158 lpfc_init_vpi(phba, pmb, vport->vpi);
6159 pmb->vport = vport;
6160 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6161 rc = lpfc_sli_issue_mbox(phba, pmb,
6162 MBX_NOWAIT);
6163 if (rc == MBX_NOT_FINISHED) {
6164 lpfc_printf_vlog(vport,
6165 KERN_ERR, LOG_MBOX,
6166 "2732 Failed to issue INIT_VPI"
6167 " mailbox command\n");
6168 } else {
6169 lpfc_nlp_put(ndlp);
6170 return;
6171 }
6172
James Smart92d7f7b2007-06-17 19:56:38 -05006173 default:
6174 /* Try to recover from this error */
6175 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006176 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006177 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006178 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006179 if (vport->port_type == LPFC_PHYSICAL_PORT
6180 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart7f5f3d02008-02-08 18:50:14 -05006181 lpfc_initial_flogi(vport);
6182 else
6183 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006184 break;
6185 }
James Smart92d7f7b2007-06-17 19:56:38 -05006186 } else {
James Smart695a8142010-01-26 23:08:03 -05006187 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006188 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006189 spin_unlock_irq(shost->host_lock);
6190 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006191 if (phba->sli_rev < LPFC_SLI_REV4)
6192 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006193 else {
James Smartfc2b9892010-02-26 14:15:29 -05006194 /*
6195 * If the physical port is instantiated using
6196 * FDISC, do not start vport discovery.
6197 */
6198 if (vport->port_state != LPFC_FDISC)
6199 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006200 lpfc_do_scr_ns_plogi(phba, vport);
6201 }
6202 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006203 lpfc_do_scr_ns_plogi(phba, vport);
6204 }
James Smart38b92ef2010-08-04 16:11:39 -04006205mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05006206 /* Now, we decrement the ndlp reference count held for this
6207 * callback function
6208 */
6209 lpfc_nlp_put(ndlp);
6210
James Smart92d7f7b2007-06-17 19:56:38 -05006211 mempool_free(pmb, phba->mbox_mem_pool);
6212 return;
6213}
6214
James Smarte59058c2008-08-24 21:49:00 -04006215/**
James Smart3621a712009-04-06 18:47:14 -04006216 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006217 * @phba: pointer to lpfc hba data structure.
6218 * @vport: pointer to a host virtual N_Port data structure.
6219 * @ndlp: pointer to a node-list data structure.
6220 *
6221 * This routine registers the @vport as a new virtual port with a HBA.
6222 * It is done through a registering vpi mailbox command.
6223 **/
James Smart695a8142010-01-26 23:08:03 -05006224void
James Smart92d7f7b2007-06-17 19:56:38 -05006225lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6226 struct lpfc_nodelist *ndlp)
6227{
James Smart09372822008-01-11 01:52:54 -05006228 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006229 LPFC_MBOXQ_t *mbox;
6230
6231 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6232 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006233 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006234 mbox->vport = vport;
6235 mbox->context2 = lpfc_nlp_get(ndlp);
6236 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006237 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006238 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006239 /* mailbox command not success, decrement ndlp
6240 * reference count for this command
6241 */
6242 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006243 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006244
James Smarte8b62012007-08-02 11:10:09 -04006245 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6246 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006247 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006248 }
6249 } else {
James Smarte8b62012007-08-02 11:10:09 -04006250 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6251 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006252 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006253 }
James Smartfa4066b2008-01-11 01:53:27 -05006254 return;
6255
6256mbox_err_exit:
6257 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6258 spin_lock_irq(shost->host_lock);
6259 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6260 spin_unlock_irq(shost->host_lock);
6261 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006262}
6263
James Smarte59058c2008-08-24 21:49:00 -04006264/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006265 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006266 * @phba: pointer to lpfc hba data structure.
6267 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006268 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006269 **/
6270void
James Smart0c9ab6f2010-02-26 14:15:57 -05006271lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006272{
6273 struct lpfc_vport **vports;
6274 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006275 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006276 int i;
James Smart695a8142010-01-26 23:08:03 -05006277
6278 /* Treat this failure as linkdown for all vports */
6279 link_state = phba->link_state;
6280 lpfc_linkdown(phba);
6281 phba->link_state = link_state;
6282
6283 vports = lpfc_create_vport_work_array(phba);
6284
6285 if (vports) {
6286 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6287 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6288 if (ndlp)
6289 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6290 lpfc_els_flush_cmd(vports[i]);
6291 }
6292 lpfc_destroy_vport_work_array(phba, vports);
6293 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006294}
6295
6296/**
6297 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6298 * @phba: pointer to lpfc hba data structure.
6299 *
6300 * This routine abort all pending discovery commands and
6301 * start a timer to retry FLOGI for the physical port
6302 * discovery.
6303 **/
6304void
6305lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6306{
6307 struct lpfc_nodelist *ndlp;
6308 struct Scsi_Host *shost;
6309
6310 /* Cancel the all vports retry delay retry timers */
6311 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05006312
6313 /* If fabric require FLOGI, then re-instantiate physical login */
6314 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6315 if (!ndlp)
6316 return;
6317
James Smart695a8142010-01-26 23:08:03 -05006318 shost = lpfc_shost_from_vport(phba->pport);
6319 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6320 spin_lock_irq(shost->host_lock);
6321 ndlp->nlp_flag |= NLP_DELAY_TMO;
6322 spin_unlock_irq(shost->host_lock);
6323 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6324 phba->pport->port_state = LPFC_FLOGI;
6325 return;
6326}
6327
6328/**
6329 * lpfc_fabric_login_reqd - Check if FLOGI required.
6330 * @phba: pointer to lpfc hba data structure.
6331 * @cmdiocb: pointer to FDISC command iocb.
6332 * @rspiocb: pointer to FDISC response iocb.
6333 *
6334 * This routine checks if a FLOGI is reguired for FDISC
6335 * to succeed.
6336 **/
6337static int
6338lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6339 struct lpfc_iocbq *cmdiocb,
6340 struct lpfc_iocbq *rspiocb)
6341{
6342
6343 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6344 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6345 return 0;
6346 else
6347 return 1;
6348}
6349
6350/**
James Smart3621a712009-04-06 18:47:14 -04006351 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006352 * @phba: pointer to lpfc hba data structure.
6353 * @cmdiocb: pointer to lpfc command iocb data structure.
6354 * @rspiocb: pointer to lpfc response iocb data structure.
6355 *
6356 * This routine is the completion callback function to a Fabric Discover
6357 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6358 * single threaded, each FDISC completion callback function will reset
6359 * the discovery timer for all vports such that the timers will not get
6360 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6361 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6362 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6363 * assigned to the vport has been changed with the completion of the FDISC
6364 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6365 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6366 * routine is invoked to register new vport with the HBA. Otherwise, the
6367 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6368 * Server for State Change Request (SCR).
6369 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006370static void
6371lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6372 struct lpfc_iocbq *rspiocb)
6373{
6374 struct lpfc_vport *vport = cmdiocb->vport;
6375 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6376 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6377 struct lpfc_nodelist *np;
6378 struct lpfc_nodelist *next_np;
6379 IOCB_t *irsp = &rspiocb->iocb;
6380 struct lpfc_iocbq *piocb;
6381
James Smarte8b62012007-08-02 11:10:09 -04006382 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6383 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6384 irsp->ulpStatus, irsp->un.ulpWord[4],
6385 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05006386 /* Since all FDISCs are being single threaded, we
6387 * must reset the discovery timer for ALL vports
6388 * waiting to send FDISC when one completes.
6389 */
6390 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6391 lpfc_set_disctmo(piocb->vport);
6392 }
6393
James Smart858c9f62007-06-17 19:56:39 -05006394 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6395 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6396 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6397
James Smart92d7f7b2007-06-17 19:56:38 -05006398 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05006399
6400 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6401 lpfc_retry_pport_discovery(phba);
6402 goto out;
6403 }
6404
James Smart92d7f7b2007-06-17 19:56:38 -05006405 /* Check for retry */
6406 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6407 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006408 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04006409 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04006410 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04006411 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04006412 goto fdisc_failed;
6413 }
James Smartd7c255b2008-08-24 21:50:00 -04006414 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05006415 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04006416 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04006417 vport->fc_flag |= FC_FABRIC;
6418 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6419 vport->fc_flag |= FC_PUBLIC_LOOP;
6420 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006421
James Smartd7c255b2008-08-24 21:50:00 -04006422 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6423 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6424 if ((vport->fc_prevDID != vport->fc_myDID) &&
6425 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6426 /* If our NportID changed, we need to ensure all
6427 * remaining NPORTs get unreg_login'ed so we can
6428 * issue unreg_vpi.
6429 */
6430 list_for_each_entry_safe(np, next_np,
6431 &vport->fc_nodes, nlp_listp) {
6432 if (!NLP_CHK_NODE_ACT(ndlp) ||
6433 (np->nlp_state != NLP_STE_NPR_NODE) ||
6434 !(np->nlp_flag & NLP_NPR_ADISC))
6435 continue;
James Smart09372822008-01-11 01:52:54 -05006436 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006437 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05006438 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006439 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05006440 }
James Smart78730cf2010-04-06 15:06:30 -04006441 lpfc_cleanup_pending_mbox(vport);
James Smartd7c255b2008-08-24 21:50:00 -04006442 lpfc_mbx_unreg_vpi(vport);
6443 spin_lock_irq(shost->host_lock);
6444 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05006445 if (phba->sli_rev == LPFC_SLI_REV4)
6446 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04006447 else
6448 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04006449 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04006450 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
6451 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6452 /*
6453 * Driver needs to re-reg VPI in order for f/w
6454 * to update the MAC address.
6455 */
6456 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04006457 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006458 }
6459
James Smartecfd03c2010-02-12 14:41:27 -05006460 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6461 lpfc_issue_init_vpi(vport);
6462 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04006463 lpfc_register_new_vport(phba, vport, ndlp);
6464 else
6465 lpfc_do_scr_ns_plogi(phba, vport);
6466 goto out;
6467fdisc_failed:
6468 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6469 /* Cancel discovery timer */
6470 lpfc_can_disctmo(vport);
6471 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006472out:
6473 lpfc_els_free_iocb(phba, cmdiocb);
6474}
6475
James Smarte59058c2008-08-24 21:49:00 -04006476/**
James Smart3621a712009-04-06 18:47:14 -04006477 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006478 * @vport: pointer to a virtual N_Port data structure.
6479 * @ndlp: pointer to a node-list data structure.
6480 * @retry: number of retries to the command IOCB.
6481 *
6482 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6483 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6484 * routine to issue the IOCB, which makes sure only one outstanding fabric
6485 * IOCB will be sent off HBA at any given time.
6486 *
6487 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6488 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6489 * will be stored into the context1 field of the IOCB for the completion
6490 * callback function to the FDISC ELS command.
6491 *
6492 * Return code
6493 * 0 - Successfully issued fdisc iocb command
6494 * 1 - Failed to issue fdisc iocb command
6495 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006496static int
James Smart92d7f7b2007-06-17 19:56:38 -05006497lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6498 uint8_t retry)
6499{
6500 struct lpfc_hba *phba = vport->phba;
6501 IOCB_t *icmd;
6502 struct lpfc_iocbq *elsiocb;
6503 struct serv_parm *sp;
6504 uint8_t *pcmd;
6505 uint16_t cmdsize;
6506 int did = ndlp->nlp_DID;
6507 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006508
James Smart5ffc2662009-11-18 15:39:44 -05006509 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05006510 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6511 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6512 ELS_CMD_FDISC);
6513 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006514 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006515 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6516 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006517 return 1;
6518 }
6519
6520 icmd = &elsiocb->iocb;
6521 icmd->un.elsreq64.myID = 0;
6522 icmd->un.elsreq64.fl = 1;
6523
James Smartf1126682009-06-10 17:22:44 -04006524 if (phba->sli_rev == LPFC_SLI_REV4) {
6525 /* FDISC needs to be 1 for WQE VPI */
6526 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6527 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6528 /* Set the ulpContext to the vpi */
6529 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6530 } else {
6531 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6532 icmd->ulpCt_h = 1;
6533 icmd->ulpCt_l = 0;
6534 }
James Smart92d7f7b2007-06-17 19:56:38 -05006535
6536 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6537 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6538 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6539 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6540 sp = (struct serv_parm *) pcmd;
6541 /* Setup CSPs accordingly for Fabric */
6542 sp->cmn.e_d_tov = 0;
6543 sp->cmn.w2.r_a_tov = 0;
6544 sp->cls1.classValid = 0;
6545 sp->cls2.seqDelivery = 1;
6546 sp->cls3.seqDelivery = 1;
6547
6548 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6549 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6550 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6551 pcmd += sizeof(uint32_t); /* Port Name */
6552 memcpy(pcmd, &vport->fc_portname, 8);
6553 pcmd += sizeof(uint32_t); /* Node Name */
6554 pcmd += sizeof(uint32_t); /* Node Name */
6555 memcpy(pcmd, &vport->fc_nodename, 8);
6556
6557 lpfc_set_disctmo(vport);
6558
6559 phba->fc_stat.elsXmitFDISC++;
6560 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6561
James Smart858c9f62007-06-17 19:56:39 -05006562 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6563 "Issue FDISC: did:x%x",
6564 did, 0, 0);
6565
James Smart92d7f7b2007-06-17 19:56:38 -05006566 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6567 if (rc == IOCB_ERROR) {
6568 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006569 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006570 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6571 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006572 return 1;
6573 }
6574 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05006575 return 0;
6576}
6577
James Smarte59058c2008-08-24 21:49:00 -04006578/**
James Smart3621a712009-04-06 18:47:14 -04006579 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04006580 * @phba: pointer to lpfc hba data structure.
6581 * @cmdiocb: pointer to lpfc command iocb data structure.
6582 * @rspiocb: pointer to lpfc response iocb data structure.
6583 *
6584 * This routine is the completion callback function to the issuing of a LOGO
6585 * ELS command off a vport. It frees the command IOCB and then decrement the
6586 * reference count held on ndlp for this completion function, indicating that
6587 * the reference to the ndlp is no long needed. Note that the
6588 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6589 * callback function and an additional explicit ndlp reference decrementation
6590 * will trigger the actual release of the ndlp.
6591 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006592static void
6593lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6594 struct lpfc_iocbq *rspiocb)
6595{
6596 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006597 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006598 struct lpfc_nodelist *ndlp;
6599 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006600
6601 irsp = &rspiocb->iocb;
6602 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6603 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6604 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006605
6606 lpfc_els_free_iocb(phba, cmdiocb);
6607 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006608
6609 /* Trigger the release of the ndlp after logo */
6610 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006611}
6612
James Smarte59058c2008-08-24 21:49:00 -04006613/**
James Smart3621a712009-04-06 18:47:14 -04006614 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04006615 * @vport: pointer to a virtual N_Port data structure.
6616 * @ndlp: pointer to a node-list data structure.
6617 *
6618 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6619 *
6620 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6621 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6622 * will be stored into the context1 field of the IOCB for the completion
6623 * callback function to the LOGO ELS command.
6624 *
6625 * Return codes
6626 * 0 - Successfully issued logo off the @vport
6627 * 1 - Failed to issue logo off the @vport
6628 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006629int
6630lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6631{
6632 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6633 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006634 IOCB_t *icmd;
6635 struct lpfc_iocbq *elsiocb;
6636 uint8_t *pcmd;
6637 uint16_t cmdsize;
6638
6639 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6640 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6641 ELS_CMD_LOGO);
6642 if (!elsiocb)
6643 return 1;
6644
6645 icmd = &elsiocb->iocb;
6646 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6647 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6648 pcmd += sizeof(uint32_t);
6649
6650 /* Fill in LOGO payload */
6651 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6652 pcmd += sizeof(uint32_t);
6653 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6654
James Smart858c9f62007-06-17 19:56:39 -05006655 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6656 "Issue LOGO npiv did:x%x flg:x%x",
6657 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6658
James Smart92d7f7b2007-06-17 19:56:38 -05006659 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6660 spin_lock_irq(shost->host_lock);
6661 ndlp->nlp_flag |= NLP_LOGO_SND;
6662 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04006663 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6664 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05006665 spin_lock_irq(shost->host_lock);
6666 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6667 spin_unlock_irq(shost->host_lock);
6668 lpfc_els_free_iocb(phba, elsiocb);
6669 return 1;
6670 }
6671 return 0;
6672}
6673
James Smarte59058c2008-08-24 21:49:00 -04006674/**
James Smart3621a712009-04-06 18:47:14 -04006675 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04006676 * @ptr: holder for the timer function associated data.
6677 *
6678 * This routine is invoked by the fabric iocb block timer after
6679 * timeout. It posts the fabric iocb block timeout event by setting the
6680 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6681 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6682 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6683 * posted event WORKER_FABRIC_BLOCK_TMO.
6684 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006685void
6686lpfc_fabric_block_timeout(unsigned long ptr)
6687{
6688 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6689 unsigned long iflags;
6690 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04006691
James Smart92d7f7b2007-06-17 19:56:38 -05006692 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6693 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6694 if (!tmo_posted)
6695 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6696 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6697
James Smart5e9d9b82008-06-14 22:52:53 -04006698 if (!tmo_posted)
6699 lpfc_worker_wake_up(phba);
6700 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006701}
6702
James Smarte59058c2008-08-24 21:49:00 -04006703/**
James Smart3621a712009-04-06 18:47:14 -04006704 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04006705 * @phba: pointer to lpfc hba data structure.
6706 *
6707 * This routine issues one fabric iocb from the driver internal list to
6708 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6709 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6710 * remove one pending fabric iocb from the driver internal list and invokes
6711 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6712 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006713static void
6714lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6715{
6716 struct lpfc_iocbq *iocb;
6717 unsigned long iflags;
6718 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05006719 IOCB_t *cmd;
6720
6721repeat:
6722 iocb = NULL;
6723 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05006724 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05006725 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6726 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6727 list);
6728 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05006729 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05006730 atomic_inc(&phba->fabric_iocb_count);
6731 }
6732 spin_unlock_irqrestore(&phba->hbalock, iflags);
6733 if (iocb) {
6734 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6735 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6736 iocb->iocb_flag |= LPFC_IO_FABRIC;
6737
James Smart858c9f62007-06-17 19:56:39 -05006738 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6739 "Fabric sched1: ste:x%x",
6740 iocb->vport->port_state, 0, 0);
6741
James Smart3772a992009-05-22 14:50:54 -04006742 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006743
6744 if (ret == IOCB_ERROR) {
6745 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6746 iocb->fabric_iocb_cmpl = NULL;
6747 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6748 cmd = &iocb->iocb;
6749 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6750 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6751 iocb->iocb_cmpl(phba, iocb, iocb);
6752
6753 atomic_dec(&phba->fabric_iocb_count);
6754 goto repeat;
6755 }
6756 }
6757
6758 return;
6759}
6760
James Smarte59058c2008-08-24 21:49:00 -04006761/**
James Smart3621a712009-04-06 18:47:14 -04006762 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006763 * @phba: pointer to lpfc hba data structure.
6764 *
6765 * This routine unblocks the issuing fabric iocb command. The function
6766 * will clear the fabric iocb block bit and then invoke the routine
6767 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6768 * from the driver internal fabric iocb list.
6769 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006770void
6771lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6772{
6773 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6774
6775 lpfc_resume_fabric_iocbs(phba);
6776 return;
6777}
6778
James Smarte59058c2008-08-24 21:49:00 -04006779/**
James Smart3621a712009-04-06 18:47:14 -04006780 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006781 * @phba: pointer to lpfc hba data structure.
6782 *
6783 * This routine blocks the issuing fabric iocb for a specified amount of
6784 * time (currently 100 ms). This is done by set the fabric iocb block bit
6785 * and set up a timeout timer for 100ms. When the block bit is set, no more
6786 * fabric iocb will be issued out of the HBA.
6787 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006788static void
6789lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6790{
6791 int blocked;
6792
6793 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05006794 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05006795 if (!blocked)
6796 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6797
6798 return;
6799}
6800
James Smarte59058c2008-08-24 21:49:00 -04006801/**
James Smart3621a712009-04-06 18:47:14 -04006802 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04006803 * @phba: pointer to lpfc hba data structure.
6804 * @cmdiocb: pointer to lpfc command iocb data structure.
6805 * @rspiocb: pointer to lpfc response iocb data structure.
6806 *
6807 * This routine is the callback function that is put to the fabric iocb's
6808 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6809 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6810 * function first restores and invokes the original iocb's callback function
6811 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6812 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6813 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006814static void
6815lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6816 struct lpfc_iocbq *rspiocb)
6817{
6818 struct ls_rjt stat;
6819
6820 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6821 BUG();
6822
6823 switch (rspiocb->iocb.ulpStatus) {
6824 case IOSTAT_NPORT_RJT:
6825 case IOSTAT_FABRIC_RJT:
6826 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6827 lpfc_block_fabric_iocbs(phba);
6828 }
6829 break;
6830
6831 case IOSTAT_NPORT_BSY:
6832 case IOSTAT_FABRIC_BSY:
6833 lpfc_block_fabric_iocbs(phba);
6834 break;
6835
6836 case IOSTAT_LS_RJT:
6837 stat.un.lsRjtError =
6838 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6839 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6840 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6841 lpfc_block_fabric_iocbs(phba);
6842 break;
6843 }
6844
6845 if (atomic_read(&phba->fabric_iocb_count) == 0)
6846 BUG();
6847
6848 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6849 cmdiocb->fabric_iocb_cmpl = NULL;
6850 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6851 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6852
6853 atomic_dec(&phba->fabric_iocb_count);
6854 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05006855 /* Post any pending iocbs to HBA */
6856 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05006857 }
6858}
6859
James Smarte59058c2008-08-24 21:49:00 -04006860/**
James Smart3621a712009-04-06 18:47:14 -04006861 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006862 * @phba: pointer to lpfc hba data structure.
6863 * @iocb: pointer to lpfc command iocb data structure.
6864 *
6865 * This routine is used as the top-level API for issuing a fabric iocb command
6866 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6867 * function makes sure that only one fabric bound iocb will be outstanding at
6868 * any given time. As such, this function will first check to see whether there
6869 * is already an outstanding fabric iocb on the wire. If so, it will put the
6870 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6871 * issued later. Otherwise, it will issue the iocb on the wire and update the
6872 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6873 *
6874 * Note, this implementation has a potential sending out fabric IOCBs out of
6875 * order. The problem is caused by the construction of the "ready" boolen does
6876 * not include the condition that the internal fabric IOCB list is empty. As
6877 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6878 * ahead of the fabric IOCBs in the internal list.
6879 *
6880 * Return code
6881 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6882 * IOCB_ERROR - failed to issue fabric iocb
6883 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006884static int
James Smart92d7f7b2007-06-17 19:56:38 -05006885lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6886{
6887 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05006888 int ready;
6889 int ret;
6890
6891 if (atomic_read(&phba->fabric_iocb_count) > 1)
6892 BUG();
6893
6894 spin_lock_irqsave(&phba->hbalock, iflags);
6895 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6896 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6897
James Smart7f5f3d02008-02-08 18:50:14 -05006898 if (ready)
6899 /* Increment fabric iocb count to hold the position */
6900 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05006901 spin_unlock_irqrestore(&phba->hbalock, iflags);
6902 if (ready) {
6903 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6904 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6905 iocb->iocb_flag |= LPFC_IO_FABRIC;
6906
James Smart858c9f62007-06-17 19:56:39 -05006907 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6908 "Fabric sched2: ste:x%x",
6909 iocb->vport->port_state, 0, 0);
6910
James Smart3772a992009-05-22 14:50:54 -04006911 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006912
6913 if (ret == IOCB_ERROR) {
6914 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6915 iocb->fabric_iocb_cmpl = NULL;
6916 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6917 atomic_dec(&phba->fabric_iocb_count);
6918 }
6919 } else {
6920 spin_lock_irqsave(&phba->hbalock, iflags);
6921 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6922 spin_unlock_irqrestore(&phba->hbalock, iflags);
6923 ret = IOCB_SUCCESS;
6924 }
6925 return ret;
6926}
6927
James Smarte59058c2008-08-24 21:49:00 -04006928/**
James Smart3621a712009-04-06 18:47:14 -04006929 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006930 * @vport: pointer to a virtual N_Port data structure.
6931 *
6932 * This routine aborts all the IOCBs associated with a @vport from the
6933 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6934 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6935 * list, removes each IOCB associated with the @vport off the list, set the
6936 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6937 * associated with the IOCB.
6938 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006939static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05006940{
6941 LIST_HEAD(completions);
6942 struct lpfc_hba *phba = vport->phba;
6943 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05006944
6945 spin_lock_irq(&phba->hbalock);
6946 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6947 list) {
6948
6949 if (piocb->vport != vport)
6950 continue;
6951
6952 list_move_tail(&piocb->list, &completions);
6953 }
6954 spin_unlock_irq(&phba->hbalock);
6955
James Smarta257bf92009-04-06 18:48:10 -04006956 /* Cancel all the IOCBs from the completions list */
6957 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6958 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006959}
6960
James Smarte59058c2008-08-24 21:49:00 -04006961/**
James Smart3621a712009-04-06 18:47:14 -04006962 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006963 * @ndlp: pointer to a node-list data structure.
6964 *
6965 * This routine aborts all the IOCBs associated with an @ndlp from the
6966 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6967 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6968 * list, removes each IOCB associated with the @ndlp off the list, set the
6969 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6970 * associated with the IOCB.
6971 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006972void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6973{
6974 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04006975 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006976 struct lpfc_iocbq *tmp_iocb, *piocb;
6977 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05006978
6979 spin_lock_irq(&phba->hbalock);
6980 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6981 list) {
6982 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6983
6984 list_move_tail(&piocb->list, &completions);
6985 }
6986 }
6987 spin_unlock_irq(&phba->hbalock);
6988
James Smarta257bf92009-04-06 18:48:10 -04006989 /* Cancel all the IOCBs from the completions list */
6990 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6991 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006992}
6993
James Smarte59058c2008-08-24 21:49:00 -04006994/**
James Smart3621a712009-04-06 18:47:14 -04006995 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006996 * @phba: pointer to lpfc hba data structure.
6997 *
6998 * This routine aborts all the IOCBs currently on the driver internal
6999 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7000 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7001 * list, removes IOCBs off the list, set the status feild to
7002 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7003 * the IOCB.
7004 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007005void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7006{
7007 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007008
7009 spin_lock_irq(&phba->hbalock);
7010 list_splice_init(&phba->fabric_iocb_list, &completions);
7011 spin_unlock_irq(&phba->hbalock);
7012
James Smarta257bf92009-04-06 18:48:10 -04007013 /* Cancel all the IOCBs from the completions list */
7014 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7015 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007016}
James Smart6fb120a2009-05-22 14:52:59 -04007017
7018/**
7019 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7020 * @phba: pointer to lpfc hba data structure.
7021 * @axri: pointer to the els xri abort wcqe structure.
7022 *
7023 * This routine is invoked by the worker thread to process a SLI4 slow-path
7024 * ELS aborted xri.
7025 **/
7026void
7027lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7028 struct sli4_wcqe_xri_aborted *axri)
7029{
7030 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
7031 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7032 unsigned long iflag = 0;
James Smart589a52d2010-07-14 15:30:54 -04007033 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007034
James Smart0f65ff62010-02-26 14:14:23 -05007035 spin_lock_irqsave(&phba->hbalock, iflag);
7036 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007037 list_for_each_entry_safe(sglq_entry, sglq_next,
7038 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7039 if (sglq_entry->sli4_xritag == xri) {
7040 list_del(&sglq_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04007041 list_add_tail(&sglq_entry->list,
7042 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007043 sglq_entry->state = SGL_FREED;
7044 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007045 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart589a52d2010-07-14 15:30:54 -04007046
7047 /* Check if TXQ queue needs to be serviced */
7048 if (pring->txq_cnt)
7049 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007050 return;
7051 }
7052 }
James Smart0f65ff62010-02-26 14:14:23 -05007053 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7054 sglq_entry = __lpfc_get_active_sglq(phba, xri);
7055 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7056 spin_unlock_irqrestore(&phba->hbalock, iflag);
7057 return;
7058 }
7059 sglq_entry->state = SGL_XRI_ABORTED;
7060 spin_unlock_irqrestore(&phba->hbalock, iflag);
7061 return;
James Smart6fb120a2009-05-22 14:52:59 -04007062}