blob: e6ca12f6c6cb5063857f30f7b3e01b6e5587f14d [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050021/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_transport_fc.h>
31
James Smartda0436e2009-05-22 14:51:39 -040032#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050033#include "lpfc_hw.h"
34#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040036#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_disc.h"
38#include "lpfc_scsi.h"
39#include "lpfc.h"
40#include "lpfc_logmsg.h"
41#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050042#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050043#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050044
45static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
46 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050047static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
48 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010049static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
50static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
51 struct lpfc_nodelist *ndlp, uint8_t retry);
52static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
53 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050054
dea31012005-04-17 16:05:31 -050055static int lpfc_max_els_tries = 3;
56
James Smarte59058c2008-08-24 21:49:00 -040057/**
James Smart3621a712009-04-06 18:47:14 -040058 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040059 * @vport: pointer to a host virtual N_Port data structure.
60 *
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
68 * had happened.
69 *
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
74 *
75 * Return codes
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
78 **/
James Smart858c9f62007-06-17 19:56:39 -050079int
James Smart2e0fef82007-06-17 19:56:36 -050080lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050081{
James Smart2e0fef82007-06-17 19:56:36 -050082 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
83 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050084 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050085
James Smart2e0fef82007-06-17 19:56:36 -050086 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040087 phba->link_state == LPFC_LINK_DOWN ||
88 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050089 return 0;
90
91 /* Read the HBA Host Attention Register */
dea31012005-04-17 16:05:31 -050092 ha_copy = readl(phba->HAregaddr);
dea31012005-04-17 16:05:31 -050093
94 if (!(ha_copy & HA_LATT))
95 return 0;
96
97 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040098 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
99 "0237 Pending Link Event during "
100 "Discovery: State x%x\n",
101 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500102
103 /* CLEAR_LA should re-enable link attention events and
104 * we should then imediately take a LATT event. The
105 * LATT processing should call lpfc_linkdown() which
106 * will cleanup any left over in-progress discovery
107 * events.
108 */
James Smart2e0fef82007-06-17 19:56:36 -0500109 spin_lock_irq(shost->host_lock);
110 vport->fc_flag |= FC_ABORT_DISCOVERY;
111 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500112
James Smart92d7f7b2007-06-17 19:56:38 -0500113 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500114 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500115
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500116 return 1;
dea31012005-04-17 16:05:31 -0500117}
118
James Smarte59058c2008-08-24 21:49:00 -0400119/**
James Smart3621a712009-04-06 18:47:14 -0400120 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400121 * @vport: pointer to a host virtual N_Port data structure.
122 * @expectRsp: flag indicating whether response is expected.
123 * @cmdSize: size of the ELS command.
124 * @retry: number of retries to the command IOCB when it fails.
125 * @ndlp: pointer to a node-list data structure.
126 * @did: destination identifier.
127 * @elscmd: the ELS command code.
128 *
129 * This routine is used for allocating a lpfc-IOCB data structure from
130 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
131 * passed into the routine for discovery state machine to issue an Extended
132 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
133 * and preparation routine that is used by all the discovery state machine
134 * routines and the ELS command-specific fields will be later set up by
135 * the individual discovery machine routines after calling this routine
136 * allocating and preparing a generic IOCB data structure. It fills in the
137 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
138 * payload and response payload (if expected). The reference count on the
139 * ndlp is incremented by 1 and the reference to the ndlp is put into
140 * context1 of the IOCB data structure for this IOCB to hold the ndlp
141 * reference for the command's callback function to access later.
142 *
143 * Return code
144 * Pointer to the newly allocated/prepared els iocb data structure
145 * NULL - when els iocb data structure allocation/preparation failed
146 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400147struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500148lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
149 uint16_t cmdSize, uint8_t retry,
150 struct lpfc_nodelist *ndlp, uint32_t did,
151 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500152{
James Smart2e0fef82007-06-17 19:56:36 -0500153 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400154 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500155 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
156 struct ulp_bde64 *bpl;
157 IOCB_t *icmd;
158
dea31012005-04-17 16:05:31 -0500159
James Smart2e0fef82007-06-17 19:56:36 -0500160 if (!lpfc_is_link_up(phba))
161 return NULL;
dea31012005-04-17 16:05:31 -0500162
dea31012005-04-17 16:05:31 -0500163 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400164 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500165
166 if (elsiocb == NULL)
167 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500168
James Smart0c287582009-06-10 17:22:56 -0400169 /*
170 * If this command is for fabric controller and HBA running
171 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
172 */
173 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400174 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400175 ((elscmd == ELS_CMD_FLOGI) ||
176 (elscmd == ELS_CMD_FDISC) ||
177 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500178 switch (elscmd) {
179 case ELS_CMD_FLOGI:
180 elsiocb->iocb_flag |= ((ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
181 & LPFC_FIP_ELS_ID_MASK);
182 break;
183 case ELS_CMD_FDISC:
184 elsiocb->iocb_flag |= ((ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
185 & LPFC_FIP_ELS_ID_MASK);
186 break;
187 case ELS_CMD_LOGO:
188 elsiocb->iocb_flag |= ((ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
189 & LPFC_FIP_ELS_ID_MASK);
190 break;
191 }
James Smart0c287582009-06-10 17:22:56 -0400192 else
James Smartc8685952009-11-18 15:39:16 -0500193 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400194
dea31012005-04-17 16:05:31 -0500195 icmd = &elsiocb->iocb;
196
197 /* fill in BDEs for command */
198 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400199 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
200 if (pcmd)
201 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500202 if (!pcmd || !pcmd->virt)
203 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500204
205 INIT_LIST_HEAD(&pcmd->list);
206
207 /* Allocate buffer for response payload */
208 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500209 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500210 if (prsp)
211 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
212 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500213 if (!prsp || !prsp->virt)
214 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500215 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500216 } else
dea31012005-04-17 16:05:31 -0500217 prsp = NULL;
dea31012005-04-17 16:05:31 -0500218
219 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500220 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500221 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500222 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
223 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500224 if (!pbuflist || !pbuflist->virt)
225 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500226
227 INIT_LIST_HEAD(&pbuflist->list);
228
229 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
230 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400231 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart2e0fef82007-06-17 19:56:36 -0500232 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500233 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500234 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500235 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400236 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500237 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500238 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500239 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
240 }
dea31012005-04-17 16:05:31 -0500241 icmd->ulpBdeCount = 1;
242 icmd->ulpLe = 1;
243 icmd->ulpClass = CLASS3;
244
James Smart92d7f7b2007-06-17 19:56:38 -0500245 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
246 icmd->un.elsreq64.myID = vport->fc_myDID;
247
248 /* For ELS_REQUEST64_CR, use the VPI by default */
James Smartda0436e2009-05-22 14:51:39 -0400249 icmd->ulpContext = vport->vpi + phba->vpi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500250 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500251 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
252 if (elscmd == ELS_CMD_ECHO)
253 icmd->ulpCt_l = 0; /* context = invalid RPI */
254 else
255 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500256 }
257
dea31012005-04-17 16:05:31 -0500258 bpl = (struct ulp_bde64 *) pbuflist->virt;
259 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
260 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
261 bpl->tus.f.bdeSize = cmdSize;
262 bpl->tus.f.bdeFlags = 0;
263 bpl->tus.w = le32_to_cpu(bpl->tus.w);
264
265 if (expectRsp) {
266 bpl++;
267 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
268 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
269 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400270 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500271 bpl->tus.w = le32_to_cpu(bpl->tus.w);
272 }
273
James Smartfa4066b2008-01-11 01:53:27 -0500274 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400275 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500276 if (!elsiocb->context1)
277 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400278 elsiocb->context2 = pcmd;
279 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500280 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500281 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500282 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
283
284 if (prsp) {
285 list_add(&prsp->list, &pcmd->list);
286 }
dea31012005-04-17 16:05:31 -0500287 if (expectRsp) {
288 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400289 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
290 "0116 Xmit ELS command x%x to remote "
291 "NPORT x%x I/O tag: x%x, port state: x%x\n",
292 elscmd, did, elsiocb->iotag,
293 vport->port_state);
dea31012005-04-17 16:05:31 -0500294 } else {
295 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400296 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
297 "0117 Xmit ELS response x%x to remote "
298 "NPORT x%x I/O tag: x%x, size: x%x\n",
299 elscmd, ndlp->nlp_DID, elsiocb->iotag,
300 cmdSize);
dea31012005-04-17 16:05:31 -0500301 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500302 return elsiocb;
dea31012005-04-17 16:05:31 -0500303
James Smartfa4066b2008-01-11 01:53:27 -0500304els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500305 if (expectRsp)
306 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500307 kfree(pbuflist);
308
309els_iocb_free_prsp_exit:
310 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
311 kfree(prsp);
312
313els_iocb_free_pcmb_exit:
314 kfree(pcmd);
315 lpfc_sli_release_iocbq(phba, elsiocb);
316 return NULL;
317}
dea31012005-04-17 16:05:31 -0500318
James Smarte59058c2008-08-24 21:49:00 -0400319/**
James Smart3621a712009-04-06 18:47:14 -0400320 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400321 * @vport: pointer to a host virtual N_Port data structure.
322 *
323 * This routine issues a fabric registration login for a @vport. An
324 * active ndlp node with Fabric_DID must already exist for this @vport.
325 * The routine invokes two mailbox commands to carry out fabric registration
326 * login through the HBA firmware: the first mailbox command requests the
327 * HBA to perform link configuration for the @vport; and the second mailbox
328 * command requests the HBA to perform the actual fabric registration login
329 * with the @vport.
330 *
331 * Return code
332 * 0 - successfully issued fabric registration login for @vport
333 * -ENXIO -- failed to issue fabric registration login for @vport
334 **/
James Smart3772a992009-05-22 14:50:54 -0400335int
James Smart92d7f7b2007-06-17 19:56:38 -0500336lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
337{
338 struct lpfc_hba *phba = vport->phba;
339 LPFC_MBOXQ_t *mbox;
340 struct lpfc_dmabuf *mp;
341 struct lpfc_nodelist *ndlp;
342 struct serv_parm *sp;
343 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400344 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500345
346 sp = &phba->fc_fabparam;
347 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500348 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400349 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500350 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400351 }
James Smart92d7f7b2007-06-17 19:56:38 -0500352
353 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400354 if (!mbox) {
355 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500356 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400357 }
James Smart92d7f7b2007-06-17 19:56:38 -0500358
359 vport->port_state = LPFC_FABRIC_CFG_LINK;
360 lpfc_config_link(phba, mbox);
361 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
362 mbox->vport = vport;
363
James Smart0b727fe2007-10-27 13:37:25 -0400364 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400365 if (rc == MBX_NOT_FINISHED) {
366 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500367 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400368 }
James Smart92d7f7b2007-06-17 19:56:38 -0500369
370 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400371 if (!mbox) {
372 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500373 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400374 }
James Smart3772a992009-05-22 14:50:54 -0400375 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0);
James Smart98c9ea52007-10-27 13:37:33 -0400376 if (rc) {
377 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500378 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400379 }
James Smart92d7f7b2007-06-17 19:56:38 -0500380
381 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
382 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500383 /* increment the reference count on ndlp to hold reference
384 * for the callback routine.
385 */
James Smart92d7f7b2007-06-17 19:56:38 -0500386 mbox->context2 = lpfc_nlp_get(ndlp);
387
James Smart0b727fe2007-10-27 13:37:25 -0400388 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400389 if (rc == MBX_NOT_FINISHED) {
390 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500391 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400392 }
James Smart92d7f7b2007-06-17 19:56:38 -0500393
394 return 0;
395
396fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500397 /* decrement the reference count on ndlp just incremented
398 * for the failed mbox command.
399 */
James Smart92d7f7b2007-06-17 19:56:38 -0500400 lpfc_nlp_put(ndlp);
401 mp = (struct lpfc_dmabuf *) mbox->context1;
402 lpfc_mbuf_free(phba, mp->virt, mp->phys);
403 kfree(mp);
404fail_free_mbox:
405 mempool_free(mbox, phba->mbox_mem_pool);
406
407fail:
408 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400409 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400410 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500411 return -ENXIO;
412}
413
James Smarte59058c2008-08-24 21:49:00 -0400414/**
James Smart6fb120a2009-05-22 14:52:59 -0400415 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
416 * @vport: pointer to a host virtual N_Port data structure.
417 *
418 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
419 * the @vport. This mailbox command is necessary for FCoE only.
420 *
421 * Return code
422 * 0 - successfully issued REG_VFI for @vport
423 * A failure code otherwise.
424 **/
425static int
426lpfc_issue_reg_vfi(struct lpfc_vport *vport)
427{
428 struct lpfc_hba *phba = vport->phba;
429 LPFC_MBOXQ_t *mboxq;
430 struct lpfc_nodelist *ndlp;
431 struct serv_parm *sp;
432 struct lpfc_dmabuf *dmabuf;
433 int rc = 0;
434
435 sp = &phba->fc_fabparam;
436 ndlp = lpfc_findnode_did(vport, Fabric_DID);
437 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
438 rc = -ENODEV;
439 goto fail;
440 }
441
442 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
443 if (!dmabuf) {
444 rc = -ENOMEM;
445 goto fail;
446 }
447 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
448 if (!dmabuf->virt) {
449 rc = -ENOMEM;
450 goto fail_free_dmabuf;
451 }
452 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
453 if (!mboxq) {
454 rc = -ENOMEM;
455 goto fail_free_coherent;
456 }
457 vport->port_state = LPFC_FABRIC_CFG_LINK;
458 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
459 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
460 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
461 mboxq->vport = vport;
462 mboxq->context1 = dmabuf;
463 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
464 if (rc == MBX_NOT_FINISHED) {
465 rc = -ENXIO;
466 goto fail_free_mbox;
467 }
468 return 0;
469
470fail_free_mbox:
471 mempool_free(mboxq, phba->mbox_mem_pool);
472fail_free_coherent:
473 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
474fail_free_dmabuf:
475 kfree(dmabuf);
476fail:
477 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
478 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
479 "0289 Issue Register VFI failed: Err %d\n", rc);
480 return rc;
481}
482
483/**
James Smart3621a712009-04-06 18:47:14 -0400484 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400485 * @vport: pointer to a host virtual N_Port data structure.
486 * @ndlp: pointer to a node-list data structure.
487 * @sp: pointer to service parameter data structure.
488 * @irsp: pointer to the IOCB within the lpfc response IOCB.
489 *
490 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
491 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
492 * port in a fabric topology. It properly sets up the parameters to the @ndlp
493 * from the IOCB response. It also check the newly assigned N_Port ID to the
494 * @vport against the previously assigned N_Port ID. If it is different from
495 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
496 * is invoked on all the remaining nodes with the @vport to unregister the
497 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
498 * is invoked to register login to the fabric.
499 *
500 * Return code
501 * 0 - Success (currently, always return 0)
502 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500503static int
James Smart2e0fef82007-06-17 19:56:36 -0500504lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
505 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500506{
James Smart2e0fef82007-06-17 19:56:36 -0500507 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
508 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500509 struct lpfc_nodelist *np;
510 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500511
James Smart2e0fef82007-06-17 19:56:36 -0500512 spin_lock_irq(shost->host_lock);
513 vport->fc_flag |= FC_FABRIC;
514 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500515
516 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
517 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
518 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
519
520 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
521
522 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500523 spin_lock_irq(shost->host_lock);
524 vport->fc_flag |= FC_PUBLIC_LOOP;
525 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500526 } else {
527 /*
528 * If we are a N-port connected to a Fabric, fixup sparam's so
529 * logins to devices on remote loops work.
530 */
James Smart2e0fef82007-06-17 19:56:36 -0500531 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500532 }
533
James Smart2e0fef82007-06-17 19:56:36 -0500534 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500535 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500536 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500537 ndlp->nlp_class_sup = 0;
538 if (sp->cls1.classValid)
539 ndlp->nlp_class_sup |= FC_COS_CLASS1;
540 if (sp->cls2.classValid)
541 ndlp->nlp_class_sup |= FC_COS_CLASS2;
542 if (sp->cls3.classValid)
543 ndlp->nlp_class_sup |= FC_COS_CLASS3;
544 if (sp->cls4.classValid)
545 ndlp->nlp_class_sup |= FC_COS_CLASS4;
546 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
547 sp->cmn.bbRcvSizeLsb;
548 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
549
James Smart92d7f7b2007-06-17 19:56:38 -0500550 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
551 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400552 lpfc_printf_vlog(vport, KERN_WARNING,
553 LOG_ELS | LOG_VPORT,
554 "1816 FLOGI NPIV supported, "
555 "response data 0x%x\n",
556 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500557 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500558 } else {
559 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400560 to call reg_vnpid atleast for the physcial host */
561 lpfc_printf_vlog(vport, KERN_WARNING,
562 LOG_ELS | LOG_VPORT,
563 "1817 Fabric does not support NPIV "
564 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500565 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
566 }
567 }
568
569 if ((vport->fc_prevDID != vport->fc_myDID) &&
570 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
571
572 /* If our NportID changed, we need to ensure all
573 * remaining NPORTs get unreg_login'ed.
574 */
575 list_for_each_entry_safe(np, next_np,
576 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400577 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500578 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500579 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
580 !(np->nlp_flag & NLP_NPR_ADISC))
581 continue;
582 spin_lock_irq(shost->host_lock);
583 np->nlp_flag &= ~NLP_NPR_ADISC;
584 spin_unlock_irq(shost->host_lock);
585 lpfc_unreg_rpi(vport, np);
586 }
James Smart78730cf2010-04-06 15:06:30 -0400587 lpfc_cleanup_pending_mbox(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500588 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
589 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500590 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500591 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500592 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500593 }
James Smartecfd03c2010-02-12 14:41:27 -0500594 /*
595 * If VPI is unreged, driver need to do INIT_VPI
596 * before re-registering
597 */
598 if (phba->sli_rev == LPFC_SLI_REV4) {
599 spin_lock_irq(shost->host_lock);
600 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
601 spin_unlock_irq(shost->host_lock);
602 }
James Smart38b92ef2010-08-04 16:11:39 -0400603 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
604 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
605 /*
606 * Driver needs to re-reg VPI in order for f/w
607 * to update the MAC address.
608 */
609 lpfc_register_new_vport(phba, vport, ndlp);
610 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500611 }
612
James Smart6fb120a2009-05-22 14:52:59 -0400613 if (phba->sli_rev < LPFC_SLI_REV4) {
614 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
615 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
616 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
617 lpfc_register_new_vport(phba, vport, ndlp);
618 else
619 lpfc_issue_fabric_reglogin(vport);
620 } else {
621 ndlp->nlp_type |= NLP_FABRIC;
622 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500623 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
624 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400625 lpfc_start_fdiscs(phba);
626 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500627 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500628 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500629 else
James Smart6fb120a2009-05-22 14:52:59 -0400630 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500631 }
dea31012005-04-17 16:05:31 -0500632 return 0;
dea31012005-04-17 16:05:31 -0500633}
James Smarte59058c2008-08-24 21:49:00 -0400634/**
James Smart3621a712009-04-06 18:47:14 -0400635 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400636 * @vport: pointer to a host virtual N_Port data structure.
637 * @ndlp: pointer to a node-list data structure.
638 * @sp: pointer to service parameter data structure.
639 *
640 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
641 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
642 * in a point-to-point topology. First, the @vport's N_Port Name is compared
643 * with the received N_Port Name: if the @vport's N_Port Name is greater than
644 * the received N_Port Name lexicographically, this node shall assign local
645 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
646 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
647 * this node shall just wait for the remote node to issue PLOGI and assign
648 * N_Port IDs.
649 *
650 * Return code
651 * 0 - Success
652 * -ENXIO - Fail
653 **/
dea31012005-04-17 16:05:31 -0500654static int
James Smart2e0fef82007-06-17 19:56:36 -0500655lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
656 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500657{
James Smart2e0fef82007-06-17 19:56:36 -0500658 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
659 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500660 LPFC_MBOXQ_t *mbox;
661 int rc;
662
James Smart2e0fef82007-06-17 19:56:36 -0500663 spin_lock_irq(shost->host_lock);
664 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
665 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500666
667 phba->fc_edtov = FF_DEF_EDTOV;
668 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500669 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500670 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500671 if (rc >= 0) {
672 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500673 spin_lock_irq(shost->host_lock);
674 vport->fc_flag |= FC_PT2PT_PLOGI;
675 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500676
677 /*
678 * N_Port ID cannot be 0, set our to LocalID the other
679 * side will be RemoteID.
680 */
681
682 /* not equal */
683 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500684 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500685
686 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
687 if (!mbox)
688 goto fail;
689
690 lpfc_config_link(phba, mbox);
691
692 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500693 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400694 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500695 if (rc == MBX_NOT_FINISHED) {
696 mempool_free(mbox, phba->mbox_mem_pool);
697 goto fail;
698 }
James Smarte47c9092008-02-08 18:49:26 -0500699 /* Decrement ndlp reference count indicating that ndlp can be
700 * safely released when other references to it are done.
701 */
James Smart329f9bc2007-04-25 09:53:01 -0400702 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500703
James Smart2e0fef82007-06-17 19:56:36 -0500704 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500705 if (!ndlp) {
706 /*
707 * Cannot find existing Fabric ndlp, so allocate a
708 * new one
709 */
710 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
711 if (!ndlp)
712 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500713 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500714 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
715 ndlp = lpfc_enable_node(vport, ndlp,
716 NLP_STE_UNUSED_NODE);
717 if(!ndlp)
718 goto fail;
dea31012005-04-17 16:05:31 -0500719 }
720
721 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500722 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500723 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500724 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500725 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500726 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
727 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500728 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500729 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500730 } else
731 /* This side will wait for the PLOGI, decrement ndlp reference
732 * count indicating that ndlp can be released when other
733 * references to it are done.
734 */
James Smart329f9bc2007-04-25 09:53:01 -0400735 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500736
James Smart09372822008-01-11 01:52:54 -0500737 /* If we are pt2pt with another NPort, force NPIV off! */
738 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
739
James Smart2e0fef82007-06-17 19:56:36 -0500740 spin_lock_irq(shost->host_lock);
741 vport->fc_flag |= FC_PT2PT;
742 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500743
744 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500745 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500746 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500747fail:
dea31012005-04-17 16:05:31 -0500748 return -ENXIO;
749}
750
James Smarte59058c2008-08-24 21:49:00 -0400751/**
James Smart3621a712009-04-06 18:47:14 -0400752 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400753 * @phba: pointer to lpfc hba data structure.
754 * @cmdiocb: pointer to lpfc command iocb data structure.
755 * @rspiocb: pointer to lpfc response iocb data structure.
756 *
757 * This routine is the top-level completion callback function for issuing
758 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
759 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
760 * retry has been made (either immediately or delayed with lpfc_els_retry()
761 * returning 1), the command IOCB will be released and function returned.
762 * If the retry attempt has been given up (possibly reach the maximum
763 * number of retries), one additional decrement of ndlp reference shall be
764 * invoked before going out after releasing the command IOCB. This will
765 * actually release the remote node (Note, lpfc_els_free_iocb() will also
766 * invoke one decrement of ndlp reference count). If no error reported in
767 * the IOCB status, the command Port ID field is used to determine whether
768 * this is a point-to-point topology or a fabric topology: if the Port ID
769 * field is assigned, it is a fabric topology; otherwise, it is a
770 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
771 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
772 * specific topology completion conditions.
773 **/
dea31012005-04-17 16:05:31 -0500774static void
James Smart329f9bc2007-04-25 09:53:01 -0400775lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
776 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500777{
James Smart2e0fef82007-06-17 19:56:36 -0500778 struct lpfc_vport *vport = cmdiocb->vport;
779 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500780 IOCB_t *irsp = &rspiocb->iocb;
781 struct lpfc_nodelist *ndlp = cmdiocb->context1;
782 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
783 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500784 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500785 int rc;
786
787 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500788 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500789 /* One additional decrement on node reference count to
790 * trigger the release of the node
791 */
James Smart329f9bc2007-04-25 09:53:01 -0400792 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500793 goto out;
794 }
795
James Smart858c9f62007-06-17 19:56:39 -0500796 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
797 "FLOGI cmpl: status:x%x/x%x state:x%x",
798 irsp->ulpStatus, irsp->un.ulpWord[4],
799 vport->port_state);
800
dea31012005-04-17 16:05:31 -0500801 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500802 /*
803 * In case of FIP mode, perform round robin FCF failover
804 * due to new FCF discovery
805 */
806 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smartdbb6b3a2010-06-08 18:31:37 -0400807 (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
808 (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) &&
809 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500810 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
811 "2611 FLOGI failed on registered "
James Smart38b92ef2010-08-04 16:11:39 -0400812 "FCF record fcf_index(%d), status: "
813 "x%x/x%x, tmo:x%x, trying to perform "
814 "round robin failover\n",
815 phba->fcf.current_rec.fcf_indx,
816 irsp->ulpStatus, irsp->un.ulpWord[4],
817 irsp->ulpTimeout);
James Smart0c9ab6f2010-02-26 14:15:57 -0500818 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
819 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
820 /*
821 * Exhausted the eligible FCF record list,
822 * fail through to retry FLOGI on current
823 * FCF record.
824 */
825 lpfc_printf_log(phba, KERN_WARNING,
826 LOG_FIP | LOG_ELS,
James Smart3804dc82010-07-14 15:31:37 -0400827 "2760 Completed one round "
828 "of FLOGI FCF round robin "
829 "failover list, retry FLOGI "
830 "on currently registered "
831 "FCF index:%d\n",
James Smart0c9ab6f2010-02-26 14:15:57 -0500832 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500833 } else {
James Smart3804dc82010-07-14 15:31:37 -0400834 lpfc_printf_log(phba, KERN_INFO,
835 LOG_FIP | LOG_ELS,
836 "2794 FLOGI FCF round robin "
837 "failover to FCF index x%x\n",
838 fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -0500839 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba,
840 fcf_index);
James Smart3804dc82010-07-14 15:31:37 -0400841 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -0500842 lpfc_printf_log(phba, KERN_WARNING,
843 LOG_FIP | LOG_ELS,
844 "2761 FLOGI round "
845 "robin FCF failover "
846 "read FCF failed "
847 "rc:x%x, fcf_index:"
848 "%d\n", rc,
849 phba->fcf.current_rec.fcf_indx);
James Smart3804dc82010-07-14 15:31:37 -0400850 else
James Smart0c9ab6f2010-02-26 14:15:57 -0500851 goto out;
852 }
853 }
854
James Smart38b92ef2010-08-04 16:11:39 -0400855 /* FLOGI failure */
856 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
857 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
858 irsp->ulpStatus, irsp->un.ulpWord[4],
859 irsp->ulpTimeout);
860
dea31012005-04-17 16:05:31 -0500861 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500862 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500863 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500864
dea31012005-04-17 16:05:31 -0500865 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500866 spin_lock_irq(shost->host_lock);
867 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
868 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500869
James Smart329f9bc2007-04-25 09:53:01 -0400870 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500871 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
872 * alpa map would take too long otherwise.
873 */
874 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400875 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500876 }
877
878 /* FLOGI failure */
James Smarte40a02c2010-02-26 14:13:54 -0500879 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
880 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400881 irsp->ulpStatus, irsp->un.ulpWord[4],
882 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500883 goto flogifail;
884 }
James Smart695a8142010-01-26 23:08:03 -0500885 spin_lock_irq(shost->host_lock);
886 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400887 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500888 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500889
890 /*
891 * The FLogI succeeded. Sync the data for the CPU before
892 * accessing it.
893 */
894 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
895
896 sp = prsp->virt + sizeof(uint32_t);
897
898 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400899 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200900 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400901 "Data: x%x x%x x%x x%x\n",
902 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
903 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500904
James Smart2e0fef82007-06-17 19:56:36 -0500905 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500906 /*
907 * If Common Service Parameters indicate Nport
908 * we are point to point, if Fport we are Fabric.
909 */
910 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500911 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400912 else if (!(phba->hba_flag & HBA_FCOE_SUPPORT))
James Smart2e0fef82007-06-17 19:56:36 -0500913 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400914 else {
915 lpfc_printf_vlog(vport, KERN_ERR,
916 LOG_FIP | LOG_ELS,
917 "2831 FLOGI response with cleared Fabric "
918 "bit fcf_index 0x%x "
919 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
920 "Fabric Name "
921 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
922 phba->fcf.current_rec.fcf_indx,
923 phba->fcf.current_rec.switch_name[0],
924 phba->fcf.current_rec.switch_name[1],
925 phba->fcf.current_rec.switch_name[2],
926 phba->fcf.current_rec.switch_name[3],
927 phba->fcf.current_rec.switch_name[4],
928 phba->fcf.current_rec.switch_name[5],
929 phba->fcf.current_rec.switch_name[6],
930 phba->fcf.current_rec.switch_name[7],
931 phba->fcf.current_rec.fabric_name[0],
932 phba->fcf.current_rec.fabric_name[1],
933 phba->fcf.current_rec.fabric_name[2],
934 phba->fcf.current_rec.fabric_name[3],
935 phba->fcf.current_rec.fabric_name[4],
936 phba->fcf.current_rec.fabric_name[5],
937 phba->fcf.current_rec.fabric_name[6],
938 phba->fcf.current_rec.fabric_name[7]);
939 lpfc_nlp_put(ndlp);
940 spin_lock_irq(&phba->hbalock);
941 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
942 spin_unlock_irq(&phba->hbalock);
943 goto out;
944 }
James Smart0c9ab6f2010-02-26 14:15:57 -0500945 if (!rc) {
946 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400947 if (phba->hba_flag & HBA_FIP_SUPPORT)
948 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
949 LOG_ELS,
950 "2769 FLOGI successful on FCF "
951 "record: current_fcf_index:"
952 "x%x, terminate FCF round "
953 "robin failover process\n",
954 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500955 spin_lock_irq(&phba->hbalock);
956 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
957 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500958 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500959 }
dea31012005-04-17 16:05:31 -0500960 }
961
962flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400963 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500964
James Smart858c9f62007-06-17 19:56:39 -0500965 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500966 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500967 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500968
969 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500970 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400971 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
972 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
973 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
974 (phba->link_state != LPFC_CLEAR_LA)) {
975 /* If FLOGI failed enable link interrupt. */
976 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500977 }
dea31012005-04-17 16:05:31 -0500978out:
979 lpfc_els_free_iocb(phba, cmdiocb);
980}
981
James Smarte59058c2008-08-24 21:49:00 -0400982/**
James Smart3621a712009-04-06 18:47:14 -0400983 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400984 * @vport: pointer to a host virtual N_Port data structure.
985 * @ndlp: pointer to a node-list data structure.
986 * @retry: number of retries to the command IOCB.
987 *
988 * This routine issues a Fabric Login (FLOGI) Request ELS command
989 * for a @vport. The initiator service parameters are put into the payload
990 * of the FLOGI Request IOCB and the top-level callback function pointer
991 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
992 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
993 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
994 *
995 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
996 * will be incremented by 1 for holding the ndlp and the reference to ndlp
997 * will be stored into the context1 field of the IOCB for the completion
998 * callback function to the FLOGI ELS command.
999 *
1000 * Return code
1001 * 0 - successfully issued flogi iocb for @vport
1002 * 1 - failed to issue flogi iocb for @vport
1003 **/
dea31012005-04-17 16:05:31 -05001004static int
James Smart2e0fef82007-06-17 19:56:36 -05001005lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001006 uint8_t retry)
1007{
James Smart2e0fef82007-06-17 19:56:36 -05001008 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001009 struct serv_parm *sp;
1010 IOCB_t *icmd;
1011 struct lpfc_iocbq *elsiocb;
1012 struct lpfc_sli_ring *pring;
1013 uint8_t *pcmd;
1014 uint16_t cmdsize;
1015 uint32_t tmo;
1016 int rc;
1017
1018 pring = &phba->sli.ring[LPFC_ELS_RING];
1019
James Smart92d7f7b2007-06-17 19:56:38 -05001020 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001021 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1022 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001023
James Smart488d1462006-03-07 15:02:37 -05001024 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001025 return 1;
dea31012005-04-17 16:05:31 -05001026
1027 icmd = &elsiocb->iocb;
1028 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1029
1030 /* For FLOGI request, remainder of payload is service parameters */
1031 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001032 pcmd += sizeof(uint32_t);
1033 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001034 sp = (struct serv_parm *) pcmd;
1035
1036 /* Setup CSPs accordingly for Fabric */
1037 sp->cmn.e_d_tov = 0;
1038 sp->cmn.w2.r_a_tov = 0;
1039 sp->cls1.classValid = 0;
1040 sp->cls2.seqDelivery = 1;
1041 sp->cls3.seqDelivery = 1;
1042 if (sp->cmn.fcphLow < FC_PH3)
1043 sp->cmn.fcphLow = FC_PH3;
1044 if (sp->cmn.fcphHigh < FC_PH3)
1045 sp->cmn.fcphHigh = FC_PH3;
1046
James Smart6fb120a2009-05-22 14:52:59 -04001047 if (phba->sli_rev == LPFC_SLI_REV4) {
1048 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1049 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1050 /* FLOGI needs to be 3 for WQE FCFI */
1051 /* Set the fcfi to the fcfi we registered with */
1052 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1053 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001054 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001055 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1056 icmd->ulpCt_h = 1;
1057 icmd->ulpCt_l = 0;
1058 }
1059
James Smart858c9f62007-06-17 19:56:39 -05001060 if (phba->fc_topology != TOPOLOGY_LOOP) {
1061 icmd->un.elsreq64.myID = 0;
1062 icmd->un.elsreq64.fl = 1;
1063 }
1064
dea31012005-04-17 16:05:31 -05001065 tmo = phba->fc_ratov;
1066 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001067 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001068 phba->fc_ratov = tmo;
1069
1070 phba->fc_stat.elsXmitFLOGI++;
1071 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001072
1073 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1074 "Issue FLOGI: opt:x%x",
1075 phba->sli3_options, 0, 0);
1076
James Smart92d7f7b2007-06-17 19:56:38 -05001077 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001078 if (rc == IOCB_ERROR) {
1079 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001080 return 1;
dea31012005-04-17 16:05:31 -05001081 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001082 return 0;
dea31012005-04-17 16:05:31 -05001083}
1084
James Smarte59058c2008-08-24 21:49:00 -04001085/**
James Smart3621a712009-04-06 18:47:14 -04001086 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001087 * @phba: pointer to lpfc hba data structure.
1088 *
1089 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1090 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1091 * list and issues an abort IOCB commond on each outstanding IOCB that
1092 * contains a active Fabric_DID ndlp. Note that this function is to issue
1093 * the abort IOCB command on all the outstanding IOCBs, thus when this
1094 * function returns, it does not guarantee all the IOCBs are actually aborted.
1095 *
1096 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001097 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001098 **/
dea31012005-04-17 16:05:31 -05001099int
James Smart2e0fef82007-06-17 19:56:36 -05001100lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001101{
1102 struct lpfc_sli_ring *pring;
1103 struct lpfc_iocbq *iocb, *next_iocb;
1104 struct lpfc_nodelist *ndlp;
1105 IOCB_t *icmd;
1106
1107 /* Abort outstanding I/O on NPort <nlp_DID> */
1108 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001109 "0201 Abort outstanding I/O on NPort x%x\n",
1110 Fabric_DID);
dea31012005-04-17 16:05:31 -05001111
1112 pring = &phba->sli.ring[LPFC_ELS_RING];
1113
1114 /*
1115 * Check the txcmplq for an iocb that matches the nport the driver is
1116 * searching for.
1117 */
James Smart2e0fef82007-06-17 19:56:36 -05001118 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001119 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1120 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001121 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1122 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001123 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001124 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1125 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001126 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001127 }
1128 }
James Smart2e0fef82007-06-17 19:56:36 -05001129 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001130
1131 return 0;
1132}
1133
James Smarte59058c2008-08-24 21:49:00 -04001134/**
James Smart3621a712009-04-06 18:47:14 -04001135 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001136 * @vport: pointer to a host virtual N_Port data structure.
1137 *
1138 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1139 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1140 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1141 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1142 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1143 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1144 * @vport.
1145 *
1146 * Return code
1147 * 0 - failed to issue initial flogi for @vport
1148 * 1 - successfully issued initial flogi for @vport
1149 **/
dea31012005-04-17 16:05:31 -05001150int
James Smart2e0fef82007-06-17 19:56:36 -05001151lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001152{
James Smart2e0fef82007-06-17 19:56:36 -05001153 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001154 struct lpfc_nodelist *ndlp;
1155
James Smart98c9ea52007-10-27 13:37:33 -04001156 vport->port_state = LPFC_FLOGI;
1157 lpfc_set_disctmo(vport);
1158
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001159 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001160 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001161 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001162 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001163 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1164 if (!ndlp)
1165 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001166 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001167 /* Set the node type */
1168 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001169 /* Put ndlp onto node list */
1170 lpfc_enqueue_node(vport, ndlp);
1171 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1172 /* re-setup ndlp without removing from node list */
1173 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1174 if (!ndlp)
1175 return 0;
dea31012005-04-17 16:05:31 -05001176 }
James Smart87af33f2007-10-27 13:37:43 -04001177
James Smarte47c9092008-02-08 18:49:26 -05001178 if (lpfc_issue_els_flogi(vport, ndlp, 0))
James Smartfa4066b2008-01-11 01:53:27 -05001179 /* This decrement of reference count to node shall kick off
1180 * the release of the node.
1181 */
James Smart329f9bc2007-04-25 09:53:01 -04001182 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001183
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001184 return 1;
dea31012005-04-17 16:05:31 -05001185}
1186
James Smarte59058c2008-08-24 21:49:00 -04001187/**
James Smart3621a712009-04-06 18:47:14 -04001188 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001189 * @vport: pointer to a host virtual N_Port data structure.
1190 *
1191 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1192 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1193 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1194 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1195 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1196 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1197 * @vport.
1198 *
1199 * Return code
1200 * 0 - failed to issue initial fdisc for @vport
1201 * 1 - successfully issued initial fdisc for @vport
1202 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001203int
1204lpfc_initial_fdisc(struct lpfc_vport *vport)
1205{
1206 struct lpfc_hba *phba = vport->phba;
1207 struct lpfc_nodelist *ndlp;
1208
1209 /* First look for the Fabric ndlp */
1210 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1211 if (!ndlp) {
1212 /* Cannot find existing Fabric ndlp, so allocate a new one */
1213 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1214 if (!ndlp)
1215 return 0;
1216 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001217 /* Put ndlp onto node list */
1218 lpfc_enqueue_node(vport, ndlp);
1219 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1220 /* re-setup ndlp without removing from node list */
1221 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1222 if (!ndlp)
1223 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001224 }
James Smarte47c9092008-02-08 18:49:26 -05001225
James Smart92d7f7b2007-06-17 19:56:38 -05001226 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001227 /* decrement node reference count to trigger the release of
1228 * the node.
1229 */
James Smart92d7f7b2007-06-17 19:56:38 -05001230 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001231 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001232 }
1233 return 1;
1234}
James Smart87af33f2007-10-27 13:37:43 -04001235
James Smarte59058c2008-08-24 21:49:00 -04001236/**
James Smart3621a712009-04-06 18:47:14 -04001237 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001238 * @vport: pointer to a host virtual N_Port data structure.
1239 *
1240 * This routine checks whether there are more remaining Port Logins
1241 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1242 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1243 * to issue ELS PLOGIs up to the configured discover threads with the
1244 * @vport (@vport->cfg_discovery_threads). The function also decrement
1245 * the @vport's num_disc_node by 1 if it is not already 0.
1246 **/
James Smart87af33f2007-10-27 13:37:43 -04001247void
James Smart2e0fef82007-06-17 19:56:36 -05001248lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001249{
1250 int sentplogi;
1251
James Smart2e0fef82007-06-17 19:56:36 -05001252 if (vport->num_disc_nodes)
1253 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001254
1255 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001256 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1257 "0232 Continue discovery with %d PLOGIs to go "
1258 "Data: x%x x%x x%x\n",
1259 vport->num_disc_nodes, vport->fc_plogi_cnt,
1260 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001261 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001262 if (vport->fc_flag & FC_NLP_MORE)
1263 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1264 sentplogi = lpfc_els_disc_plogi(vport);
1265
dea31012005-04-17 16:05:31 -05001266 return;
1267}
1268
James Smarte59058c2008-08-24 21:49:00 -04001269/**
James Smart3621a712009-04-06 18:47:14 -04001270 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001271 * @phba: pointer to lpfc hba data structure.
1272 * @prsp: pointer to response IOCB payload.
1273 * @ndlp: pointer to a node-list data structure.
1274 *
1275 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1276 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1277 * The following cases are considered N_Port confirmed:
1278 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1279 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1280 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1281 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1282 * 1) if there is a node on vport list other than the @ndlp with the same
1283 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1284 * on that node to release the RPI associated with the node; 2) if there is
1285 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1286 * into, a new node shall be allocated (or activated). In either case, the
1287 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1288 * be released and the new_ndlp shall be put on to the vport node list and
1289 * its pointer returned as the confirmed node.
1290 *
1291 * Note that before the @ndlp got "released", the keepDID from not-matching
1292 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1293 * of the @ndlp. This is because the release of @ndlp is actually to put it
1294 * into an inactive state on the vport node list and the vport node list
1295 * management algorithm does not allow two node with a same DID.
1296 *
1297 * Return code
1298 * pointer to the PLOGI N_Port @ndlp
1299 **/
James Smart488d1462006-03-07 15:02:37 -05001300static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001301lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001302 struct lpfc_nodelist *ndlp)
1303{
James Smart2e0fef82007-06-17 19:56:36 -05001304 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001305 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001306 struct lpfc_rport_data *rdata;
1307 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001308 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001309 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001310 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001311 int put_node;
1312 int put_rport;
James Smart488d1462006-03-07 15:02:37 -05001313
James Smart2fb9bd82006-12-02 13:33:57 -05001314 /* Fabric nodes can have the same WWPN so we don't bother searching
1315 * by WWPN. Just return the ndlp that was given to us.
1316 */
1317 if (ndlp->nlp_type & NLP_FABRIC)
1318 return ndlp;
1319
James Smart92d7f7b2007-06-17 19:56:38 -05001320 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001321 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001322
James Smart685f0bf2007-04-25 09:53:08 -04001323 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001324 * we have for that ndlp. If not, we have some work to do.
1325 */
James Smart2e0fef82007-06-17 19:56:36 -05001326 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001327
James Smarte47c9092008-02-08 18:49:26 -05001328 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001329 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001330
1331 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001332 rc = memcmp(&ndlp->nlp_portname, name,
1333 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001334 if (!rc)
1335 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001336 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1337 if (!new_ndlp)
1338 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001339 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001340 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001341 rc = memcmp(&ndlp->nlp_portname, name,
1342 sizeof(struct lpfc_name));
1343 if (!rc)
1344 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001345 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1346 NLP_STE_UNUSED_NODE);
1347 if (!new_ndlp)
1348 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001349 keepDID = new_ndlp->nlp_DID;
1350 } else
1351 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001352
James Smart2e0fef82007-06-17 19:56:36 -05001353 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001354 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001355 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001356
1357 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1358 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1359 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1360
James Smarte47c9092008-02-08 18:49:26 -05001361 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001362 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001363
James Smart2e0fef82007-06-17 19:56:36 -05001364 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001365 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1366 /* The new_ndlp is replacing ndlp totally, so we need
1367 * to put ndlp on UNUSED list and try to free it.
1368 */
James Smart0ff10d42008-01-11 01:52:36 -05001369
1370 /* Fix up the rport accordingly */
1371 rport = ndlp->rport;
1372 if (rport) {
1373 rdata = rport->dd_data;
1374 if (rdata->pnode == ndlp) {
1375 lpfc_nlp_put(ndlp);
1376 ndlp->rport = NULL;
1377 rdata->pnode = lpfc_nlp_get(new_ndlp);
1378 new_ndlp->rport = rport;
1379 }
1380 new_ndlp->nlp_type = ndlp->nlp_type;
1381 }
James Smart58da1ff2008-04-07 10:15:56 -04001382 /* We shall actually free the ndlp with both nlp_DID and
1383 * nlp_portname fields equals 0 to avoid any ndlp on the
1384 * nodelist never to be used.
1385 */
1386 if (ndlp->nlp_DID == 0) {
1387 spin_lock_irq(&phba->ndlp_lock);
1388 NLP_SET_FREE_REQ(ndlp);
1389 spin_unlock_irq(&phba->ndlp_lock);
1390 }
James Smart0ff10d42008-01-11 01:52:36 -05001391
James Smart58da1ff2008-04-07 10:15:56 -04001392 /* Two ndlps cannot have the same did on the nodelist */
1393 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001394 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001395 }
James Smart92795652006-07-06 15:50:02 -04001396 else {
James Smart2e0fef82007-06-17 19:56:36 -05001397 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001398 /* Two ndlps cannot have the same did */
1399 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001400 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart38b92ef2010-08-04 16:11:39 -04001401 /* Since we are swapping the ndlp passed in with the new one
1402 * and the did has already been swapped, copy over the
1403 * state and names.
1404 */
1405 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1406 sizeof(struct lpfc_name));
1407 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1408 sizeof(struct lpfc_name));
1409 new_ndlp->nlp_state = ndlp->nlp_state;
1410 /* Fix up the rport accordingly */
1411 rport = ndlp->rport;
1412 if (rport) {
1413 rdata = rport->dd_data;
1414 put_node = rdata->pnode != NULL;
1415 put_rport = ndlp->rport != NULL;
1416 rdata->pnode = NULL;
1417 ndlp->rport = NULL;
1418 if (put_node)
1419 lpfc_nlp_put(ndlp);
1420 if (put_rport)
1421 put_device(&rport->dev);
1422 }
James Smart92795652006-07-06 15:50:02 -04001423 }
James Smart488d1462006-03-07 15:02:37 -05001424 return new_ndlp;
1425}
1426
James Smarte59058c2008-08-24 21:49:00 -04001427/**
James Smart3621a712009-04-06 18:47:14 -04001428 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001429 * @vport: pointer to a host virtual N_Port data structure.
1430 *
1431 * This routine checks whether more Registration State Change
1432 * Notifications (RSCNs) came in while the discovery state machine was in
1433 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1434 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1435 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1436 * handling the RSCNs.
1437 **/
James Smart87af33f2007-10-27 13:37:43 -04001438void
1439lpfc_end_rscn(struct lpfc_vport *vport)
1440{
1441 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1442
1443 if (vport->fc_flag & FC_RSCN_MODE) {
1444 /*
1445 * Check to see if more RSCNs came in while we were
1446 * processing this one.
1447 */
1448 if (vport->fc_rscn_id_cnt ||
1449 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1450 lpfc_els_handle_rscn(vport);
1451 else {
1452 spin_lock_irq(shost->host_lock);
1453 vport->fc_flag &= ~FC_RSCN_MODE;
1454 spin_unlock_irq(shost->host_lock);
1455 }
1456 }
1457}
1458
James Smarte59058c2008-08-24 21:49:00 -04001459/**
James Smart3621a712009-04-06 18:47:14 -04001460 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001461 * @phba: pointer to lpfc hba data structure.
1462 * @cmdiocb: pointer to lpfc command iocb data structure.
1463 * @rspiocb: pointer to lpfc response iocb data structure.
1464 *
1465 * This routine is the completion callback function for issuing the Port
1466 * Login (PLOGI) command. For PLOGI completion, there must be an active
1467 * ndlp on the vport node list that matches the remote node ID from the
1468 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1469 * ignored and command IOCB released. The PLOGI response IOCB status is
1470 * checked for error conditons. If there is error status reported, PLOGI
1471 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1472 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1473 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1474 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1475 * there are additional N_Port nodes with the vport that need to perform
1476 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1477 * PLOGIs.
1478 **/
dea31012005-04-17 16:05:31 -05001479static void
James Smart2e0fef82007-06-17 19:56:36 -05001480lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1481 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001482{
James Smart2e0fef82007-06-17 19:56:36 -05001483 struct lpfc_vport *vport = cmdiocb->vport;
1484 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001485 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001486 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001487 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001488 int disc, rc, did, type;
1489
dea31012005-04-17 16:05:31 -05001490 /* we pass cmdiocb to state machine which needs rspiocb as well */
1491 cmdiocb->context_un.rsp_iocb = rspiocb;
1492
1493 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001494 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1495 "PLOGI cmpl: status:x%x/x%x did:x%x",
1496 irsp->ulpStatus, irsp->un.ulpWord[4],
1497 irsp->un.elsreq64.remoteID);
1498
James Smart2e0fef82007-06-17 19:56:36 -05001499 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001500 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001501 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1502 "0136 PLOGI completes to NPort x%x "
1503 "with no ndlp. Data: x%x x%x x%x\n",
1504 irsp->un.elsreq64.remoteID,
1505 irsp->ulpStatus, irsp->un.ulpWord[4],
1506 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001507 goto out;
James Smarted957682007-06-17 19:56:37 -05001508 }
dea31012005-04-17 16:05:31 -05001509
1510 /* Since ndlp can be freed in the disc state machine, note if this node
1511 * is being used during discovery.
1512 */
James Smart2e0fef82007-06-17 19:56:36 -05001513 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001514 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001515 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001516 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001517 rc = 0;
1518
1519 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001520 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1521 "0102 PLOGI completes to NPort x%x "
1522 "Data: x%x x%x x%x x%x x%x\n",
1523 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1524 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001525 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001526 if (lpfc_els_chk_latt(vport)) {
1527 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001528 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001529 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001530 goto out;
1531 }
1532
1533 /* ndlp could be freed in DSM, save these values now */
1534 type = ndlp->nlp_type;
1535 did = ndlp->nlp_DID;
1536
1537 if (irsp->ulpStatus) {
1538 /* Check for retry */
1539 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1540 /* ELS command is being retried */
1541 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001542 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001543 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001544 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001545 }
1546 goto out;
1547 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001548 /* PLOGI failed Don't print the vport to vport rjts */
1549 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1550 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1551 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1552 (phba)->pport->cfg_log_verbose & LOG_ELS)
1553 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001554 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1555 ndlp->nlp_DID, irsp->ulpStatus,
1556 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001557 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001558 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001559 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001560 else
James Smart2e0fef82007-06-17 19:56:36 -05001561 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001562 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001563 } else {
1564 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001565 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001566 cmdiocb->context2)->list.next,
1567 struct lpfc_dmabuf, list);
1568 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001569 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001570 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001571 }
1572
James Smart2e0fef82007-06-17 19:56:36 -05001573 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001574 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001575 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001576
James Smart2e0fef82007-06-17 19:56:36 -05001577 if (vport->num_disc_nodes == 0) {
1578 spin_lock_irq(shost->host_lock);
1579 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1580 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001581
James Smart2e0fef82007-06-17 19:56:36 -05001582 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001583 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001584 }
1585 }
1586
1587out:
1588 lpfc_els_free_iocb(phba, cmdiocb);
1589 return;
1590}
1591
James Smarte59058c2008-08-24 21:49:00 -04001592/**
James Smart3621a712009-04-06 18:47:14 -04001593 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001594 * @vport: pointer to a host virtual N_Port data structure.
1595 * @did: destination port identifier.
1596 * @retry: number of retries to the command IOCB.
1597 *
1598 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1599 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1600 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1601 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1602 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1603 *
1604 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1605 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1606 * will be stored into the context1 field of the IOCB for the completion
1607 * callback function to the PLOGI ELS command.
1608 *
1609 * Return code
1610 * 0 - Successfully issued a plogi for @vport
1611 * 1 - failed to issue a plogi for @vport
1612 **/
dea31012005-04-17 16:05:31 -05001613int
James Smart2e0fef82007-06-17 19:56:36 -05001614lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001615{
James Smart2e0fef82007-06-17 19:56:36 -05001616 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001617 struct serv_parm *sp;
1618 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001619 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001620 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001621 struct lpfc_sli *psli;
1622 uint8_t *pcmd;
1623 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001624 int ret;
dea31012005-04-17 16:05:31 -05001625
1626 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001627
James Smart98c9ea52007-10-27 13:37:33 -04001628 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001629 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1630 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001631
James Smarte47c9092008-02-08 18:49:26 -05001632 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001633 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001634 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001635 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001636 if (!elsiocb)
1637 return 1;
dea31012005-04-17 16:05:31 -05001638
1639 icmd = &elsiocb->iocb;
1640 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1641
1642 /* For PLOGI request, remainder of payload is service parameters */
1643 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001644 pcmd += sizeof(uint32_t);
1645 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001646 sp = (struct serv_parm *) pcmd;
1647
1648 if (sp->cmn.fcphLow < FC_PH_4_3)
1649 sp->cmn.fcphLow = FC_PH_4_3;
1650
1651 if (sp->cmn.fcphHigh < FC_PH3)
1652 sp->cmn.fcphHigh = FC_PH3;
1653
James Smart858c9f62007-06-17 19:56:39 -05001654 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1655 "Issue PLOGI: did:x%x",
1656 did, 0, 0);
1657
dea31012005-04-17 16:05:31 -05001658 phba->fc_stat.elsXmitPLOGI++;
1659 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001660 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001661
1662 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001663 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001664 return 1;
dea31012005-04-17 16:05:31 -05001665 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001666 return 0;
dea31012005-04-17 16:05:31 -05001667}
1668
James Smarte59058c2008-08-24 21:49:00 -04001669/**
James Smart3621a712009-04-06 18:47:14 -04001670 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001671 * @phba: pointer to lpfc hba data structure.
1672 * @cmdiocb: pointer to lpfc command iocb data structure.
1673 * @rspiocb: pointer to lpfc response iocb data structure.
1674 *
1675 * This routine is the completion callback function for a Process Login
1676 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1677 * status. If there is error status reported, PRLI retry shall be attempted
1678 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1679 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1680 * ndlp to mark the PRLI completion.
1681 **/
dea31012005-04-17 16:05:31 -05001682static void
James Smart2e0fef82007-06-17 19:56:36 -05001683lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1684 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001685{
James Smart2e0fef82007-06-17 19:56:36 -05001686 struct lpfc_vport *vport = cmdiocb->vport;
1687 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001688 IOCB_t *irsp;
1689 struct lpfc_sli *psli;
1690 struct lpfc_nodelist *ndlp;
1691
1692 psli = &phba->sli;
1693 /* we pass cmdiocb to state machine which needs rspiocb as well */
1694 cmdiocb->context_un.rsp_iocb = rspiocb;
1695
1696 irsp = &(rspiocb->iocb);
1697 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001698 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001699 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001700 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001701
James Smart858c9f62007-06-17 19:56:39 -05001702 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1703 "PRLI cmpl: status:x%x/x%x did:x%x",
1704 irsp->ulpStatus, irsp->un.ulpWord[4],
1705 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001706 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001707 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1708 "0103 PRLI completes to NPort x%x "
1709 "Data: x%x x%x x%x x%x\n",
1710 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1711 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001712
James Smart2e0fef82007-06-17 19:56:36 -05001713 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001714 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001715 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001716 goto out;
1717
1718 if (irsp->ulpStatus) {
1719 /* Check for retry */
1720 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1721 /* ELS command is being retried */
1722 goto out;
1723 }
1724 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001725 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1726 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1727 ndlp->nlp_DID, irsp->ulpStatus,
1728 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001729 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001730 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001731 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001732 else
James Smart2e0fef82007-06-17 19:56:36 -05001733 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001734 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001735 } else
dea31012005-04-17 16:05:31 -05001736 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001737 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001738 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001739out:
1740 lpfc_els_free_iocb(phba, cmdiocb);
1741 return;
1742}
1743
James Smarte59058c2008-08-24 21:49:00 -04001744/**
James Smart3621a712009-04-06 18:47:14 -04001745 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001746 * @vport: pointer to a host virtual N_Port data structure.
1747 * @ndlp: pointer to a node-list data structure.
1748 * @retry: number of retries to the command IOCB.
1749 *
1750 * This routine issues a Process Login (PRLI) ELS command for the
1751 * @vport. The PRLI service parameters are set up in the payload of the
1752 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1753 * is put to the IOCB completion callback func field before invoking the
1754 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1755 *
1756 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1757 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1758 * will be stored into the context1 field of the IOCB for the completion
1759 * callback function to the PRLI ELS command.
1760 *
1761 * Return code
1762 * 0 - successfully issued prli iocb command for @vport
1763 * 1 - failed to issue prli iocb command for @vport
1764 **/
dea31012005-04-17 16:05:31 -05001765int
James Smart2e0fef82007-06-17 19:56:36 -05001766lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001767 uint8_t retry)
1768{
James Smart2e0fef82007-06-17 19:56:36 -05001769 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1770 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001771 PRLI *npr;
1772 IOCB_t *icmd;
1773 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001774 uint8_t *pcmd;
1775 uint16_t cmdsize;
1776
James Smart92d7f7b2007-06-17 19:56:38 -05001777 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001778 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1779 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001780 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001781 return 1;
dea31012005-04-17 16:05:31 -05001782
1783 icmd = &elsiocb->iocb;
1784 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1785
1786 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001787 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001788 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001789 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001790
1791 /* For PRLI, remainder of payload is PRLI parameter page */
1792 npr = (PRLI *) pcmd;
1793 /*
1794 * If our firmware version is 3.20 or later,
1795 * set the following bits for FC-TAPE support.
1796 */
1797 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1798 npr->ConfmComplAllowed = 1;
1799 npr->Retry = 1;
1800 npr->TaskRetryIdReq = 1;
1801 }
1802 npr->estabImagePair = 1;
1803 npr->readXferRdyDis = 1;
1804
1805 /* For FCP support */
1806 npr->prliType = PRLI_FCP_TYPE;
1807 npr->initiatorFunc = 1;
1808
James Smart858c9f62007-06-17 19:56:39 -05001809 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1810 "Issue PRLI: did:x%x",
1811 ndlp->nlp_DID, 0, 0);
1812
dea31012005-04-17 16:05:31 -05001813 phba->fc_stat.elsXmitPRLI++;
1814 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001815 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001816 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001817 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001818 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1819 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001820 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001821 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001822 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001823 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001824 return 1;
dea31012005-04-17 16:05:31 -05001825 }
James Smart2e0fef82007-06-17 19:56:36 -05001826 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001827 return 0;
dea31012005-04-17 16:05:31 -05001828}
1829
James Smarte59058c2008-08-24 21:49:00 -04001830/**
James Smart3621a712009-04-06 18:47:14 -04001831 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001832 * @vport: pointer to a host virtual N_Port data structure.
1833 *
1834 * This routine performs Registration State Change Notification (RSCN)
1835 * discovery for a @vport. If the @vport's node port recovery count is not
1836 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1837 * the nodes that need recovery. If none of the PLOGI were needed through
1838 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1839 * invoked to check and handle possible more RSCN came in during the period
1840 * of processing the current ones.
1841 **/
1842static void
1843lpfc_rscn_disc(struct lpfc_vport *vport)
1844{
1845 lpfc_can_disctmo(vport);
1846
1847 /* RSCN discovery */
1848 /* go thru NPR nodes and issue ELS PLOGIs */
1849 if (vport->fc_npr_cnt)
1850 if (lpfc_els_disc_plogi(vport))
1851 return;
1852
1853 lpfc_end_rscn(vport);
1854}
1855
1856/**
James Smart3621a712009-04-06 18:47:14 -04001857 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001858 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1859 *
1860 * This function is called when the final ADISC is completed during discovery.
1861 * This function handles clearing link attention or issuing reg_vpi depending
1862 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1863 * discovery.
1864 * This function is called with no locks held.
1865 **/
1866static void
1867lpfc_adisc_done(struct lpfc_vport *vport)
1868{
1869 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1870 struct lpfc_hba *phba = vport->phba;
1871
1872 /*
1873 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1874 * and continue discovery.
1875 */
1876 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04001877 !(vport->fc_flag & FC_RSCN_MODE) &&
1878 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04001879 lpfc_issue_reg_vpi(phba, vport);
1880 return;
1881 }
1882 /*
1883 * For SLI2, we need to set port_state to READY
1884 * and continue discovery.
1885 */
1886 if (vport->port_state < LPFC_VPORT_READY) {
1887 /* If we get here, there is nothing to ADISC */
1888 if (vport->port_type == LPFC_PHYSICAL_PORT)
1889 lpfc_issue_clear_la(phba, vport);
1890 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1891 vport->num_disc_nodes = 0;
1892 /* go thru NPR list, issue ELS PLOGIs */
1893 if (vport->fc_npr_cnt)
1894 lpfc_els_disc_plogi(vport);
1895 if (!vport->num_disc_nodes) {
1896 spin_lock_irq(shost->host_lock);
1897 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1898 spin_unlock_irq(shost->host_lock);
1899 lpfc_can_disctmo(vport);
1900 lpfc_end_rscn(vport);
1901 }
1902 }
1903 vport->port_state = LPFC_VPORT_READY;
1904 } else
1905 lpfc_rscn_disc(vport);
1906}
1907
1908/**
James Smart3621a712009-04-06 18:47:14 -04001909 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001910 * @vport: pointer to a host virtual N_Port data structure.
1911 *
1912 * This routine determines whether there are more ndlps on a @vport
1913 * node list need to have Address Discover (ADISC) issued. If so, it will
1914 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1915 * remaining nodes which need to have ADISC sent.
1916 **/
James Smart0ff10d42008-01-11 01:52:36 -05001917void
James Smart2e0fef82007-06-17 19:56:36 -05001918lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001919{
1920 int sentadisc;
1921
James Smart2e0fef82007-06-17 19:56:36 -05001922 if (vport->num_disc_nodes)
1923 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001924 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001925 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1926 "0210 Continue discovery with %d ADISCs to go "
1927 "Data: x%x x%x x%x\n",
1928 vport->num_disc_nodes, vport->fc_adisc_cnt,
1929 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001930 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001931 if (vport->fc_flag & FC_NLP_MORE) {
1932 lpfc_set_disctmo(vport);
1933 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1934 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001935 }
James Smart90160e02008-08-24 21:49:45 -04001936 if (!vport->num_disc_nodes)
1937 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001938 return;
1939}
1940
James Smarte59058c2008-08-24 21:49:00 -04001941/**
James Smart3621a712009-04-06 18:47:14 -04001942 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04001943 * @phba: pointer to lpfc hba data structure.
1944 * @cmdiocb: pointer to lpfc command iocb data structure.
1945 * @rspiocb: pointer to lpfc response iocb data structure.
1946 *
1947 * This routine is the completion function for issuing the Address Discover
1948 * (ADISC) command. It first checks to see whether link went down during
1949 * the discovery process. If so, the node will be marked as node port
1950 * recovery for issuing discover IOCB by the link attention handler and
1951 * exit. Otherwise, the response status is checked. If error was reported
1952 * in the response status, the ADISC command shall be retried by invoking
1953 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1954 * the response status, the state machine is invoked to set transition
1955 * with respect to NLP_EVT_CMPL_ADISC event.
1956 **/
dea31012005-04-17 16:05:31 -05001957static void
James Smart2e0fef82007-06-17 19:56:36 -05001958lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1959 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001960{
James Smart2e0fef82007-06-17 19:56:36 -05001961 struct lpfc_vport *vport = cmdiocb->vport;
1962 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001963 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001964 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001965 int disc;
dea31012005-04-17 16:05:31 -05001966
1967 /* we pass cmdiocb to state machine which needs rspiocb as well */
1968 cmdiocb->context_un.rsp_iocb = rspiocb;
1969
1970 irsp = &(rspiocb->iocb);
1971 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001972
James Smart858c9f62007-06-17 19:56:39 -05001973 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1974 "ADISC cmpl: status:x%x/x%x did:x%x",
1975 irsp->ulpStatus, irsp->un.ulpWord[4],
1976 ndlp->nlp_DID);
1977
dea31012005-04-17 16:05:31 -05001978 /* Since ndlp can be freed in the disc state machine, note if this node
1979 * is being used during discovery.
1980 */
James Smart2e0fef82007-06-17 19:56:36 -05001981 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001982 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001983 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001984 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001985 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001986 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1987 "0104 ADISC completes to NPort x%x "
1988 "Data: x%x x%x x%x x%x x%x\n",
1989 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1990 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001991 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001992 if (lpfc_els_chk_latt(vport)) {
1993 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001994 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001995 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001996 goto out;
1997 }
1998
1999 if (irsp->ulpStatus) {
2000 /* Check for retry */
2001 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2002 /* ELS command is being retried */
2003 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002004 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002005 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002006 spin_unlock_irq(shost->host_lock);
2007 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002008 }
2009 goto out;
2010 }
2011 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002012 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2013 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2014 ndlp->nlp_DID, irsp->ulpStatus,
2015 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002016 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002017 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002018 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002019 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002020 } else
dea31012005-04-17 16:05:31 -05002021 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002022 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002023 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002024
James Smart90160e02008-08-24 21:49:45 -04002025 /* Check to see if there are more ADISCs to be sent */
2026 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002027 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002028out:
2029 lpfc_els_free_iocb(phba, cmdiocb);
2030 return;
2031}
2032
James Smarte59058c2008-08-24 21:49:00 -04002033/**
James Smart3621a712009-04-06 18:47:14 -04002034 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002035 * @vport: pointer to a virtual N_Port data structure.
2036 * @ndlp: pointer to a node-list data structure.
2037 * @retry: number of retries to the command IOCB.
2038 *
2039 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2040 * @vport. It prepares the payload of the ADISC ELS command, updates the
2041 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2042 * to issue the ADISC ELS command.
2043 *
2044 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2045 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2046 * will be stored into the context1 field of the IOCB for the completion
2047 * callback function to the ADISC ELS command.
2048 *
2049 * Return code
2050 * 0 - successfully issued adisc
2051 * 1 - failed to issue adisc
2052 **/
dea31012005-04-17 16:05:31 -05002053int
James Smart2e0fef82007-06-17 19:56:36 -05002054lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002055 uint8_t retry)
2056{
James Smart2e0fef82007-06-17 19:56:36 -05002057 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2058 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002059 ADISC *ap;
2060 IOCB_t *icmd;
2061 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002062 uint8_t *pcmd;
2063 uint16_t cmdsize;
2064
James Smart92d7f7b2007-06-17 19:56:38 -05002065 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002066 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2067 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002068 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002069 return 1;
dea31012005-04-17 16:05:31 -05002070
2071 icmd = &elsiocb->iocb;
2072 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2073
2074 /* For ADISC request, remainder of payload is service parameters */
2075 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002076 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002077
2078 /* Fill in ADISC payload */
2079 ap = (ADISC *) pcmd;
2080 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002081 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2082 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002083 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002084
James Smart858c9f62007-06-17 19:56:39 -05002085 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2086 "Issue ADISC: did:x%x",
2087 ndlp->nlp_DID, 0, 0);
2088
dea31012005-04-17 16:05:31 -05002089 phba->fc_stat.elsXmitADISC++;
2090 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002091 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002092 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002093 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002094 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2095 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002096 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002097 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002098 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002099 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002100 return 1;
dea31012005-04-17 16:05:31 -05002101 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002102 return 0;
dea31012005-04-17 16:05:31 -05002103}
2104
James Smarte59058c2008-08-24 21:49:00 -04002105/**
James Smart3621a712009-04-06 18:47:14 -04002106 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002107 * @phba: pointer to lpfc hba data structure.
2108 * @cmdiocb: pointer to lpfc command iocb data structure.
2109 * @rspiocb: pointer to lpfc response iocb data structure.
2110 *
2111 * This routine is the completion function for issuing the ELS Logout (LOGO)
2112 * command. If no error status was reported from the LOGO response, the
2113 * state machine of the associated ndlp shall be invoked for transition with
2114 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2115 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2116 **/
dea31012005-04-17 16:05:31 -05002117static void
James Smart2e0fef82007-06-17 19:56:36 -05002118lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2119 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002120{
James Smart2e0fef82007-06-17 19:56:36 -05002121 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2122 struct lpfc_vport *vport = ndlp->vport;
2123 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002124 IOCB_t *irsp;
2125 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002126
2127 psli = &phba->sli;
2128 /* we pass cmdiocb to state machine which needs rspiocb as well */
2129 cmdiocb->context_un.rsp_iocb = rspiocb;
2130
2131 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002132 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002133 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002134 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002135
James Smart858c9f62007-06-17 19:56:39 -05002136 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2137 "LOGO cmpl: status:x%x/x%x did:x%x",
2138 irsp->ulpStatus, irsp->un.ulpWord[4],
2139 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002140 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002141 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2142 "0105 LOGO completes to NPort x%x "
2143 "Data: x%x x%x x%x x%x\n",
2144 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2145 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002146 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002147 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002148 goto out;
2149
James Smart92d7f7b2007-06-17 19:56:38 -05002150 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2151 /* NLP_EVT_DEVICE_RM should unregister the RPI
2152 * which should abort all outstanding IOs.
2153 */
2154 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2155 NLP_EVT_DEVICE_RM);
2156 goto out;
2157 }
2158
dea31012005-04-17 16:05:31 -05002159 if (irsp->ulpStatus) {
2160 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002161 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002162 /* ELS command is being retried */
2163 goto out;
dea31012005-04-17 16:05:31 -05002164 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002165 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2166 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2167 ndlp->nlp_DID, irsp->ulpStatus,
2168 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002169 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002170 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002171 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002172 else
James Smart2e0fef82007-06-17 19:56:36 -05002173 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002174 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002175 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002176 /* Good status, call state machine.
2177 * This will unregister the rpi if needed.
2178 */
James Smart2e0fef82007-06-17 19:56:36 -05002179 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002180 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002181out:
2182 lpfc_els_free_iocb(phba, cmdiocb);
2183 return;
2184}
2185
James Smarte59058c2008-08-24 21:49:00 -04002186/**
James Smart3621a712009-04-06 18:47:14 -04002187 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002188 * @vport: pointer to a virtual N_Port data structure.
2189 * @ndlp: pointer to a node-list data structure.
2190 * @retry: number of retries to the command IOCB.
2191 *
2192 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2193 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2194 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2195 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2196 *
2197 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2198 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2199 * will be stored into the context1 field of the IOCB for the completion
2200 * callback function to the LOGO ELS command.
2201 *
2202 * Return code
2203 * 0 - successfully issued logo
2204 * 1 - failed to issue logo
2205 **/
dea31012005-04-17 16:05:31 -05002206int
James Smart2e0fef82007-06-17 19:56:36 -05002207lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002208 uint8_t retry)
2209{
James Smart2e0fef82007-06-17 19:56:36 -05002210 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2211 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002212 IOCB_t *icmd;
2213 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002214 uint8_t *pcmd;
2215 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002216 int rc;
dea31012005-04-17 16:05:31 -05002217
James Smart98c9ea52007-10-27 13:37:33 -04002218 spin_lock_irq(shost->host_lock);
2219 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2220 spin_unlock_irq(shost->host_lock);
2221 return 0;
2222 }
2223 spin_unlock_irq(shost->host_lock);
2224
James Smart92d7f7b2007-06-17 19:56:38 -05002225 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002226 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2227 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002228 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002229 return 1;
dea31012005-04-17 16:05:31 -05002230
2231 icmd = &elsiocb->iocb;
2232 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2233 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002234 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002235
2236 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002237 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002238 pcmd += sizeof(uint32_t);
2239 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002240
James Smart858c9f62007-06-17 19:56:39 -05002241 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2242 "Issue LOGO: did:x%x",
2243 ndlp->nlp_DID, 0, 0);
2244
dea31012005-04-17 16:05:31 -05002245 phba->fc_stat.elsXmitLOGO++;
2246 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002247 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002248 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002249 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002250 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002251
2252 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002253 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002254 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002255 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002256 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002257 return 1;
dea31012005-04-17 16:05:31 -05002258 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002259 return 0;
dea31012005-04-17 16:05:31 -05002260}
2261
James Smarte59058c2008-08-24 21:49:00 -04002262/**
James Smart3621a712009-04-06 18:47:14 -04002263 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002264 * @phba: pointer to lpfc hba data structure.
2265 * @cmdiocb: pointer to lpfc command iocb data structure.
2266 * @rspiocb: pointer to lpfc response iocb data structure.
2267 *
2268 * This routine is a generic completion callback function for ELS commands.
2269 * Specifically, it is the callback function which does not need to perform
2270 * any command specific operations. It is currently used by the ELS command
2271 * issuing routines for the ELS State Change Request (SCR),
2272 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2273 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2274 * certain debug loggings, this callback function simply invokes the
2275 * lpfc_els_chk_latt() routine to check whether link went down during the
2276 * discovery process.
2277 **/
dea31012005-04-17 16:05:31 -05002278static void
James Smart2e0fef82007-06-17 19:56:36 -05002279lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2280 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002281{
James Smart2e0fef82007-06-17 19:56:36 -05002282 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002283 IOCB_t *irsp;
2284
2285 irsp = &rspiocb->iocb;
2286
James Smart858c9f62007-06-17 19:56:39 -05002287 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2288 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2289 irsp->ulpStatus, irsp->un.ulpWord[4],
2290 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002291 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002292 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2293 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2294 irsp->ulpIoTag, irsp->ulpStatus,
2295 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002296 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002297 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002298 lpfc_els_free_iocb(phba, cmdiocb);
2299 return;
2300}
2301
James Smarte59058c2008-08-24 21:49:00 -04002302/**
James Smart3621a712009-04-06 18:47:14 -04002303 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002304 * @vport: pointer to a host virtual N_Port data structure.
2305 * @nportid: N_Port identifier to the remote node.
2306 * @retry: number of retries to the command IOCB.
2307 *
2308 * This routine issues a State Change Request (SCR) to a fabric node
2309 * on a @vport. The remote node @nportid is passed into the function. It
2310 * first search the @vport node list to find the matching ndlp. If no such
2311 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2312 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2313 * routine is invoked to send the SCR IOCB.
2314 *
2315 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2316 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2317 * will be stored into the context1 field of the IOCB for the completion
2318 * callback function to the SCR ELS command.
2319 *
2320 * Return code
2321 * 0 - Successfully issued scr command
2322 * 1 - Failed to issue scr command
2323 **/
dea31012005-04-17 16:05:31 -05002324int
James Smart2e0fef82007-06-17 19:56:36 -05002325lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002326{
James Smart2e0fef82007-06-17 19:56:36 -05002327 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002328 IOCB_t *icmd;
2329 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002330 struct lpfc_sli *psli;
2331 uint8_t *pcmd;
2332 uint16_t cmdsize;
2333 struct lpfc_nodelist *ndlp;
2334
2335 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002336 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002337
James Smarte47c9092008-02-08 18:49:26 -05002338 ndlp = lpfc_findnode_did(vport, nportid);
2339 if (!ndlp) {
2340 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2341 if (!ndlp)
2342 return 1;
2343 lpfc_nlp_init(vport, ndlp, nportid);
2344 lpfc_enqueue_node(vport, ndlp);
2345 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2346 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2347 if (!ndlp)
2348 return 1;
2349 }
dea31012005-04-17 16:05:31 -05002350
James Smart2e0fef82007-06-17 19:56:36 -05002351 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2352 ndlp->nlp_DID, ELS_CMD_SCR);
2353
James Smart488d1462006-03-07 15:02:37 -05002354 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002355 /* This will trigger the release of the node just
2356 * allocated
2357 */
James Smart329f9bc2007-04-25 09:53:01 -04002358 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002359 return 1;
dea31012005-04-17 16:05:31 -05002360 }
2361
2362 icmd = &elsiocb->iocb;
2363 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2364
2365 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002366 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002367
2368 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002369 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002370 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2371
James Smart858c9f62007-06-17 19:56:39 -05002372 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2373 "Issue SCR: did:x%x",
2374 ndlp->nlp_DID, 0, 0);
2375
dea31012005-04-17 16:05:31 -05002376 phba->fc_stat.elsXmitSCR++;
2377 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002378 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2379 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002380 /* The additional lpfc_nlp_put will cause the following
2381 * lpfc_els_free_iocb routine to trigger the rlease of
2382 * the node.
2383 */
James Smart329f9bc2007-04-25 09:53:01 -04002384 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002385 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002386 return 1;
dea31012005-04-17 16:05:31 -05002387 }
James Smartfa4066b2008-01-11 01:53:27 -05002388 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2389 * trigger the release of node.
2390 */
James Smart329f9bc2007-04-25 09:53:01 -04002391 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002392 return 0;
dea31012005-04-17 16:05:31 -05002393}
2394
James Smarte59058c2008-08-24 21:49:00 -04002395/**
James Smart3621a712009-04-06 18:47:14 -04002396 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002397 * @vport: pointer to a host virtual N_Port data structure.
2398 * @nportid: N_Port identifier to the remote node.
2399 * @retry: number of retries to the command IOCB.
2400 *
2401 * This routine issues a Fibre Channel Address Resolution Response
2402 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2403 * is passed into the function. It first search the @vport node list to find
2404 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2405 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2406 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2407 *
2408 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2409 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2410 * will be stored into the context1 field of the IOCB for the completion
2411 * callback function to the PARPR ELS command.
2412 *
2413 * Return code
2414 * 0 - Successfully issued farpr command
2415 * 1 - Failed to issue farpr command
2416 **/
dea31012005-04-17 16:05:31 -05002417static int
James Smart2e0fef82007-06-17 19:56:36 -05002418lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002419{
James Smart2e0fef82007-06-17 19:56:36 -05002420 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002421 IOCB_t *icmd;
2422 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002423 struct lpfc_sli *psli;
2424 FARP *fp;
2425 uint8_t *pcmd;
2426 uint32_t *lp;
2427 uint16_t cmdsize;
2428 struct lpfc_nodelist *ondlp;
2429 struct lpfc_nodelist *ndlp;
2430
2431 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002432 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002433
James Smarte47c9092008-02-08 18:49:26 -05002434 ndlp = lpfc_findnode_did(vport, nportid);
2435 if (!ndlp) {
2436 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2437 if (!ndlp)
2438 return 1;
2439 lpfc_nlp_init(vport, ndlp, nportid);
2440 lpfc_enqueue_node(vport, ndlp);
2441 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2442 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2443 if (!ndlp)
2444 return 1;
2445 }
James Smart2e0fef82007-06-17 19:56:36 -05002446
2447 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2448 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002449 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002450 /* This will trigger the release of the node just
2451 * allocated
2452 */
James Smart329f9bc2007-04-25 09:53:01 -04002453 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002454 return 1;
dea31012005-04-17 16:05:31 -05002455 }
2456
2457 icmd = &elsiocb->iocb;
2458 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2459
2460 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002461 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002462
2463 /* Fill in FARPR payload */
2464 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002465 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002466 lp = (uint32_t *) pcmd;
2467 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002468 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002469 fp->Rflags = 0;
2470 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2471
James Smart92d7f7b2007-06-17 19:56:38 -05002472 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2473 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002474 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002475 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002476 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002477 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002478 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002479 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002480 }
2481
James Smart858c9f62007-06-17 19:56:39 -05002482 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2483 "Issue FARPR: did:x%x",
2484 ndlp->nlp_DID, 0, 0);
2485
dea31012005-04-17 16:05:31 -05002486 phba->fc_stat.elsXmitFARPR++;
2487 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002488 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2489 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002490 /* The additional lpfc_nlp_put will cause the following
2491 * lpfc_els_free_iocb routine to trigger the release of
2492 * the node.
2493 */
James Smart329f9bc2007-04-25 09:53:01 -04002494 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002495 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002496 return 1;
dea31012005-04-17 16:05:31 -05002497 }
James Smartfa4066b2008-01-11 01:53:27 -05002498 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2499 * trigger the release of the node.
2500 */
James Smart329f9bc2007-04-25 09:53:01 -04002501 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002502 return 0;
dea31012005-04-17 16:05:31 -05002503}
2504
James Smarte59058c2008-08-24 21:49:00 -04002505/**
James Smart3621a712009-04-06 18:47:14 -04002506 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002507 * @vport: pointer to a host virtual N_Port data structure.
2508 * @nlp: pointer to a node-list data structure.
2509 *
2510 * This routine cancels the timer with a delayed IOCB-command retry for
2511 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2512 * removes the ELS retry event if it presents. In addition, if the
2513 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2514 * commands are sent for the @vport's nodes that require issuing discovery
2515 * ADISC.
2516 **/
dea31012005-04-17 16:05:31 -05002517void
James Smart2e0fef82007-06-17 19:56:36 -05002518lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002519{
James Smart2e0fef82007-06-17 19:56:36 -05002520 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002521 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002522
James Smart0d2b6b82008-06-14 22:52:47 -04002523 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2524 return;
James Smart2e0fef82007-06-17 19:56:36 -05002525 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002526 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002527 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002528 del_timer_sync(&nlp->nlp_delayfunc);
2529 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002530 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002531 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002532 /* Decrement nlp reference count held for the delayed retry */
2533 evtp = &nlp->els_retry_evt;
2534 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2535 }
James Smartfdcebe22006-03-07 15:04:01 -05002536 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002537 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002538 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002539 spin_unlock_irq(shost->host_lock);
2540 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002541 if (vport->port_state < LPFC_VPORT_READY) {
2542 /* Check if there are more ADISCs to be sent */
2543 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002544 } else {
2545 /* Check if there are more PLOGIs to be sent */
2546 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002547 if (vport->num_disc_nodes == 0) {
2548 spin_lock_irq(shost->host_lock);
2549 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2550 spin_unlock_irq(shost->host_lock);
2551 lpfc_can_disctmo(vport);
2552 lpfc_end_rscn(vport);
2553 }
James Smartfdcebe22006-03-07 15:04:01 -05002554 }
2555 }
2556 }
2557 return;
2558}
2559
James Smarte59058c2008-08-24 21:49:00 -04002560/**
James Smart3621a712009-04-06 18:47:14 -04002561 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002562 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2563 *
2564 * This routine is invoked by the ndlp delayed-function timer to check
2565 * whether there is any pending ELS retry event(s) with the node. If not, it
2566 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2567 * adds the delayed events to the HBA work list and invokes the
2568 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2569 * event. Note that lpfc_nlp_get() is called before posting the event to
2570 * the work list to hold reference count of ndlp so that it guarantees the
2571 * reference to ndlp will still be available when the worker thread gets
2572 * to the event associated with the ndlp.
2573 **/
James Smartfdcebe22006-03-07 15:04:01 -05002574void
dea31012005-04-17 16:05:31 -05002575lpfc_els_retry_delay(unsigned long ptr)
2576{
James Smart2e0fef82007-06-17 19:56:36 -05002577 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2578 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002579 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002580 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002581 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002582
James Smart92d7f7b2007-06-17 19:56:38 -05002583 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002584 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002585 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002586 return;
2587 }
2588
James Smartfa4066b2008-01-11 01:53:27 -05002589 /* We need to hold the node by incrementing the reference
2590 * count until the queued work is done
2591 */
2592 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002593 if (evtp->evt_arg1) {
2594 evtp->evt = LPFC_EVT_ELS_RETRY;
2595 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002596 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002597 }
James Smart92d7f7b2007-06-17 19:56:38 -05002598 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002599 return;
2600}
2601
James Smarte59058c2008-08-24 21:49:00 -04002602/**
James Smart3621a712009-04-06 18:47:14 -04002603 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002604 * @ndlp: pointer to a node-list data structure.
2605 *
2606 * This routine is the worker-thread handler for processing the @ndlp delayed
2607 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2608 * the last ELS command from the associated ndlp and invokes the proper ELS
2609 * function according to the delayed ELS command to retry the command.
2610 **/
dea31012005-04-17 16:05:31 -05002611void
2612lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2613{
James Smart2e0fef82007-06-17 19:56:36 -05002614 struct lpfc_vport *vport = ndlp->vport;
2615 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2616 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002617
James Smart2e0fef82007-06-17 19:56:36 -05002618 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002619 did = ndlp->nlp_DID;
2620 cmd = ndlp->nlp_last_elscmd;
2621 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002622
2623 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002624 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002625 return;
2626 }
2627
2628 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002629 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002630 /*
2631 * If a discovery event readded nlp_delayfunc after timer
2632 * firing and before processing the timer, cancel the
2633 * nlp_delayfunc.
2634 */
2635 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002636 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002637 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002638
2639 switch (cmd) {
2640 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002641 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002642 break;
2643 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002644 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002645 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002646 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002647 }
dea31012005-04-17 16:05:31 -05002648 break;
2649 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002650 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002651 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002652 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002653 }
dea31012005-04-17 16:05:31 -05002654 break;
2655 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002656 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002657 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002658 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002659 }
dea31012005-04-17 16:05:31 -05002660 break;
2661 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002662 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002663 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002664 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002665 }
dea31012005-04-17 16:05:31 -05002666 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002667 case ELS_CMD_FDISC:
2668 lpfc_issue_els_fdisc(vport, ndlp, retry);
2669 break;
dea31012005-04-17 16:05:31 -05002670 }
2671 return;
2672}
2673
James Smarte59058c2008-08-24 21:49:00 -04002674/**
James Smart3621a712009-04-06 18:47:14 -04002675 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002676 * @phba: pointer to lpfc hba data structure.
2677 * @cmdiocb: pointer to lpfc command iocb data structure.
2678 * @rspiocb: pointer to lpfc response iocb data structure.
2679 *
2680 * This routine makes a retry decision on an ELS command IOCB, which has
2681 * failed. The following ELS IOCBs use this function for retrying the command
2682 * when previously issued command responsed with error status: FLOGI, PLOGI,
2683 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2684 * returned error status, it makes the decision whether a retry shall be
2685 * issued for the command, and whether a retry shall be made immediately or
2686 * delayed. In the former case, the corresponding ELS command issuing-function
2687 * is called to retry the command. In the later case, the ELS command shall
2688 * be posted to the ndlp delayed event and delayed function timer set to the
2689 * ndlp for the delayed command issusing.
2690 *
2691 * Return code
2692 * 0 - No retry of els command is made
2693 * 1 - Immediate or delayed retry of els command is made
2694 **/
dea31012005-04-17 16:05:31 -05002695static int
James Smart2e0fef82007-06-17 19:56:36 -05002696lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2697 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002698{
James Smart2e0fef82007-06-17 19:56:36 -05002699 struct lpfc_vport *vport = cmdiocb->vport;
2700 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2701 IOCB_t *irsp = &rspiocb->iocb;
2702 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2703 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002704 uint32_t *elscmd;
2705 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002706 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002707 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002708 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002709 uint32_t did;
dea31012005-04-17 16:05:31 -05002710
James Smart488d1462006-03-07 15:02:37 -05002711
dea31012005-04-17 16:05:31 -05002712 /* Note: context2 may be 0 for internal driver abort
2713 * of delays ELS command.
2714 */
2715
2716 if (pcmd && pcmd->virt) {
2717 elscmd = (uint32_t *) (pcmd->virt);
2718 cmd = *elscmd++;
2719 }
2720
James Smarte47c9092008-02-08 18:49:26 -05002721 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002722 did = ndlp->nlp_DID;
2723 else {
2724 /* We should only hit this case for retrying PLOGI */
2725 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002726 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002727 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2728 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002729 return 1;
2730 }
2731
James Smart858c9f62007-06-17 19:56:39 -05002732 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2733 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2734 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2735
dea31012005-04-17 16:05:31 -05002736 switch (irsp->ulpStatus) {
2737 case IOSTAT_FCP_RSP_ERROR:
2738 case IOSTAT_REMOTE_STOP:
2739 break;
2740
2741 case IOSTAT_LOCAL_REJECT:
2742 switch ((irsp->un.ulpWord[4] & 0xff)) {
2743 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002744 if (cmd == ELS_CMD_FLOGI) {
2745 if (PCI_DEVICE_ID_HORNET ==
2746 phba->pcidev->device) {
2747 phba->fc_topology = TOPOLOGY_LOOP;
2748 phba->pport->fc_myDID = 0;
2749 phba->alpa_map[0] = 0;
2750 phba->alpa_map[1] = 0;
2751 }
2752 }
James Smart2e0fef82007-06-17 19:56:36 -05002753 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002754 delay = 1000;
dea31012005-04-17 16:05:31 -05002755 retry = 1;
2756 break;
2757
James Smart92d7f7b2007-06-17 19:56:38 -05002758 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002759 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2760 "0124 Retry illegal cmd x%x "
2761 "retry:x%x delay:x%x\n",
2762 cmd, cmdiocb->retry, delay);
2763 retry = 1;
2764 /* All command's retry policy */
2765 maxretry = 8;
2766 if (cmdiocb->retry > 2)
2767 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002768 break;
2769
dea31012005-04-17 16:05:31 -05002770 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002771 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002772 retry = 1;
2773 if (cmdiocb->retry > 100)
2774 delay = 100;
2775 maxretry = 250;
2776 break;
2777
2778 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002779 delay = 100;
dea31012005-04-17 16:05:31 -05002780 retry = 1;
2781 break;
2782
James Smart858c9f62007-06-17 19:56:39 -05002783 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002784 case IOERR_INVALID_RPI:
2785 retry = 1;
2786 break;
2787 }
2788 break;
2789
2790 case IOSTAT_NPORT_RJT:
2791 case IOSTAT_FABRIC_RJT:
2792 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2793 retry = 1;
2794 break;
2795 }
2796 break;
2797
2798 case IOSTAT_NPORT_BSY:
2799 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002800 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002801 retry = 1;
2802 break;
2803
2804 case IOSTAT_LS_RJT:
2805 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2806 /* Added for Vendor specifc support
2807 * Just keep retrying for these Rsn / Exp codes
2808 */
2809 switch (stat.un.b.lsRjtRsnCode) {
2810 case LSRJT_UNABLE_TPC:
2811 if (stat.un.b.lsRjtRsnCodeExp ==
2812 LSEXP_CMD_IN_PROGRESS) {
2813 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002814 delay = 1000;
dea31012005-04-17 16:05:31 -05002815 maxretry = 48;
2816 }
2817 retry = 1;
2818 break;
2819 }
James Smartffc95492010-06-07 15:23:17 -04002820 if (stat.un.b.lsRjtRsnCodeExp ==
2821 LSEXP_CANT_GIVE_DATA) {
2822 if (cmd == ELS_CMD_PLOGI) {
2823 delay = 1000;
2824 maxretry = 48;
2825 }
2826 retry = 1;
2827 break;
2828 }
dea31012005-04-17 16:05:31 -05002829 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002830 delay = 1000;
dea31012005-04-17 16:05:31 -05002831 maxretry = lpfc_max_els_tries + 1;
2832 retry = 1;
2833 break;
2834 }
James Smart92d7f7b2007-06-17 19:56:38 -05002835 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2836 (cmd == ELS_CMD_FDISC) &&
2837 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002838 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2839 "0125 FDISC Failed (x%x). "
2840 "Fabric out of resources\n",
2841 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002842 lpfc_vport_set_state(vport,
2843 FC_VPORT_NO_FABRIC_RSCS);
2844 }
dea31012005-04-17 16:05:31 -05002845 break;
2846
2847 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002848 if ((cmd == ELS_CMD_PLOGI) ||
2849 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002850 delay = 1000;
dea31012005-04-17 16:05:31 -05002851 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002852 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002853 /* FDISC retry policy */
2854 maxretry = 48;
2855 if (cmdiocb->retry >= 32)
2856 delay = 1000;
dea31012005-04-17 16:05:31 -05002857 }
2858 retry = 1;
2859 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002860
2861 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002862 /* There are some cases where switches return this
2863 * error when they are not ready and should be returning
2864 * Logical Busy. We should delay every time.
2865 */
2866 if (cmd == ELS_CMD_FDISC &&
2867 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2868 maxretry = 3;
2869 delay = 1000;
2870 retry = 1;
2871 break;
2872 }
James Smart92d7f7b2007-06-17 19:56:38 -05002873 case LSRJT_PROTOCOL_ERR:
2874 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2875 (cmd == ELS_CMD_FDISC) &&
2876 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2877 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2878 ) {
James Smarte8b62012007-08-02 11:10:09 -04002879 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002880 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002881 "Fabric Detected Bad WWN\n",
2882 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002883 lpfc_vport_set_state(vport,
2884 FC_VPORT_FABRIC_REJ_WWN);
2885 }
2886 break;
dea31012005-04-17 16:05:31 -05002887 }
2888 break;
2889
2890 case IOSTAT_INTERMED_RSP:
2891 case IOSTAT_BA_RJT:
2892 break;
2893
2894 default:
2895 break;
2896 }
2897
James Smart488d1462006-03-07 15:02:37 -05002898 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002899 retry = 1;
dea31012005-04-17 16:05:31 -05002900
James Smart695a8142010-01-26 23:08:03 -05002901 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002902 (phba->fc_topology != TOPOLOGY_LOOP) &&
2903 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002904 /* FLOGI retry policy */
2905 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04002906 /* retry forever */
2907 maxretry = 0;
2908 if (cmdiocb->retry >= 100)
2909 delay = 5000;
2910 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04002911 delay = 1000;
2912 }
2913
James Smart6669f9b2009-10-02 15:16:45 -04002914 cmdiocb->retry++;
2915 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05002916 phba->fc_stat.elsRetryExceeded++;
2917 retry = 0;
2918 }
2919
James Smarted957682007-06-17 19:56:37 -05002920 if ((vport->load_flag & FC_UNLOADING) != 0)
2921 retry = 0;
2922
dea31012005-04-17 16:05:31 -05002923 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04002924 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
2925 /* Stop retrying PLOGI and FDISC if in FCF discovery */
2926 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
2927 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2928 "2849 Stop retry ELS command "
2929 "x%x to remote NPORT x%x, "
2930 "Data: x%x x%x\n", cmd, did,
2931 cmdiocb->retry, delay);
2932 return 0;
2933 }
2934 }
dea31012005-04-17 16:05:31 -05002935
2936 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002937 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2938 "0107 Retry ELS command x%x to remote "
2939 "NPORT x%x Data: x%x x%x\n",
2940 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002941
James Smart858c9f62007-06-17 19:56:39 -05002942 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2943 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2944 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2945 /* Don't reset timer for no resources */
2946
dea31012005-04-17 16:05:31 -05002947 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002948 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002949 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002950 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002951 }
2952
2953 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002954 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002955 phba->fc_stat.elsDelayRetry++;
2956 ndlp->nlp_retry = cmdiocb->retry;
2957
James Smart92d7f7b2007-06-17 19:56:38 -05002958 /* delay is specified in milliseconds */
2959 mod_timer(&ndlp->nlp_delayfunc,
2960 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002961 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002962 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002963 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002964
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002965 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002966 if (cmd == ELS_CMD_PRLI)
2967 lpfc_nlp_set_state(vport, ndlp,
2968 NLP_STE_REG_LOGIN_ISSUE);
2969 else
2970 lpfc_nlp_set_state(vport, ndlp,
2971 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002972 ndlp->nlp_last_elscmd = cmd;
2973
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002974 return 1;
dea31012005-04-17 16:05:31 -05002975 }
2976 switch (cmd) {
2977 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002978 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002979 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002980 case ELS_CMD_FDISC:
2981 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2982 return 1;
dea31012005-04-17 16:05:31 -05002983 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002984 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002985 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002986 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002987 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002988 }
James Smart2e0fef82007-06-17 19:56:36 -05002989 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002990 return 1;
dea31012005-04-17 16:05:31 -05002991 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002992 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002993 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2994 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002995 return 1;
dea31012005-04-17 16:05:31 -05002996 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002997 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002998 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2999 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003000 return 1;
dea31012005-04-17 16:05:31 -05003001 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003002 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003003 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3004 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003005 return 1;
dea31012005-04-17 16:05:31 -05003006 }
3007 }
dea31012005-04-17 16:05:31 -05003008 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003009 if (logerr) {
3010 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3011 "0137 No retry ELS command x%x to remote "
3012 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3013 cmd, did, irsp->ulpStatus,
3014 irsp->un.ulpWord[4]);
3015 }
3016 else {
3017 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003018 "0108 No retry ELS command x%x to remote "
3019 "NPORT x%x Retried:%d Error:x%x/%x\n",
3020 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3021 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003022 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003023 return 0;
dea31012005-04-17 16:05:31 -05003024}
3025
James Smarte59058c2008-08-24 21:49:00 -04003026/**
James Smart3621a712009-04-06 18:47:14 -04003027 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003028 * @phba: pointer to lpfc hba data structure.
3029 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3030 *
3031 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3032 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3033 * checks to see whether there is a lpfc DMA buffer associated with the
3034 * response of the command IOCB. If so, it will be released before releasing
3035 * the lpfc DMA buffer associated with the IOCB itself.
3036 *
3037 * Return code
3038 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3039 **/
James Smart09372822008-01-11 01:52:54 -05003040static int
James Smart87af33f2007-10-27 13:37:43 -04003041lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3042{
3043 struct lpfc_dmabuf *buf_ptr;
3044
James Smarte59058c2008-08-24 21:49:00 -04003045 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003046 if (!list_empty(&buf_ptr1->list)) {
3047 list_remove_head(&buf_ptr1->list, buf_ptr,
3048 struct lpfc_dmabuf,
3049 list);
3050 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3051 kfree(buf_ptr);
3052 }
3053 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3054 kfree(buf_ptr1);
3055 return 0;
3056}
3057
James Smarte59058c2008-08-24 21:49:00 -04003058/**
James Smart3621a712009-04-06 18:47:14 -04003059 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003060 * @phba: pointer to lpfc hba data structure.
3061 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3062 *
3063 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3064 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3065 * pool.
3066 *
3067 * Return code
3068 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3069 **/
James Smart09372822008-01-11 01:52:54 -05003070static int
James Smart87af33f2007-10-27 13:37:43 -04003071lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3072{
3073 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3074 kfree(buf_ptr);
3075 return 0;
3076}
3077
James Smarte59058c2008-08-24 21:49:00 -04003078/**
James Smart3621a712009-04-06 18:47:14 -04003079 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003080 * @phba: pointer to lpfc hba data structure.
3081 * @elsiocb: pointer to lpfc els command iocb data structure.
3082 *
3083 * This routine frees a command IOCB and its associated resources. The
3084 * command IOCB data structure contains the reference to various associated
3085 * resources, these fields must be set to NULL if the associated reference
3086 * not present:
3087 * context1 - reference to ndlp
3088 * context2 - reference to cmd
3089 * context2->next - reference to rsp
3090 * context3 - reference to bpl
3091 *
3092 * It first properly decrements the reference count held on ndlp for the
3093 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3094 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3095 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3096 * adds the DMA buffer the @phba data structure for the delayed release.
3097 * If reference to the Buffer Pointer List (BPL) is present, the
3098 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3099 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3100 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3101 *
3102 * Return code
3103 * 0 - Success (currently, always return 0)
3104 **/
James Smart87af33f2007-10-27 13:37:43 -04003105int
James Smart329f9bc2007-04-25 09:53:01 -04003106lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003107{
3108 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003109 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003110
James Smarta8adb832007-10-27 13:37:53 -04003111 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3112 if (ndlp) {
3113 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3114 lpfc_nlp_put(ndlp);
3115
3116 /* If the ndlp is not being used by another discovery
3117 * thread, free it.
3118 */
3119 if (!lpfc_nlp_not_used(ndlp)) {
3120 /* If ndlp is being used by another discovery
3121 * thread, just clear NLP_DEFER_RM
3122 */
3123 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3124 }
3125 }
3126 else
3127 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003128 elsiocb->context1 = NULL;
3129 }
dea31012005-04-17 16:05:31 -05003130 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3131 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003132 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3133 /* Firmware could still be in progress of DMAing
3134 * payload, so don't free data buffer till after
3135 * a hbeat.
3136 */
3137 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3138 buf_ptr = elsiocb->context2;
3139 elsiocb->context2 = NULL;
3140 if (buf_ptr) {
3141 buf_ptr1 = NULL;
3142 spin_lock_irq(&phba->hbalock);
3143 if (!list_empty(&buf_ptr->list)) {
3144 list_remove_head(&buf_ptr->list,
3145 buf_ptr1, struct lpfc_dmabuf,
3146 list);
3147 INIT_LIST_HEAD(&buf_ptr1->list);
3148 list_add_tail(&buf_ptr1->list,
3149 &phba->elsbuf);
3150 phba->elsbuf_cnt++;
3151 }
3152 INIT_LIST_HEAD(&buf_ptr->list);
3153 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3154 phba->elsbuf_cnt++;
3155 spin_unlock_irq(&phba->hbalock);
3156 }
3157 } else {
3158 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3159 lpfc_els_free_data(phba, buf_ptr1);
3160 }
dea31012005-04-17 16:05:31 -05003161 }
3162
3163 if (elsiocb->context3) {
3164 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003165 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003166 }
James Bottomley604a3e32005-10-29 10:28:33 -05003167 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003168 return 0;
3169}
3170
James Smarte59058c2008-08-24 21:49:00 -04003171/**
James Smart3621a712009-04-06 18:47:14 -04003172 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003173 * @phba: pointer to lpfc hba data structure.
3174 * @cmdiocb: pointer to lpfc command iocb data structure.
3175 * @rspiocb: pointer to lpfc response iocb data structure.
3176 *
3177 * This routine is the completion callback function to the Logout (LOGO)
3178 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3179 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3180 * release the ndlp if it has the last reference remaining (reference count
3181 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3182 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3183 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3184 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3185 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3186 * IOCB data structure.
3187 **/
dea31012005-04-17 16:05:31 -05003188static void
James Smart2e0fef82007-06-17 19:56:36 -05003189lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3190 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003191{
James Smart2e0fef82007-06-17 19:56:36 -05003192 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3193 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003194 IOCB_t *irsp;
3195
3196 irsp = &rspiocb->iocb;
3197 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3198 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3199 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003200 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003201 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3202 "0109 ACC to LOGO completes to NPort x%x "
3203 "Data: x%x x%x x%x\n",
3204 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3205 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003206
3207 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3208 /* NPort Recovery mode or node is just allocated */
3209 if (!lpfc_nlp_not_used(ndlp)) {
3210 /* If the ndlp is being used by another discovery
3211 * thread, just unregister the RPI.
3212 */
3213 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003214 } else {
3215 /* Indicate the node has already released, should
3216 * not reference to it from within lpfc_els_free_iocb.
3217 */
3218 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003219 }
dea31012005-04-17 16:05:31 -05003220 }
3221 lpfc_els_free_iocb(phba, cmdiocb);
3222 return;
3223}
3224
James Smarte59058c2008-08-24 21:49:00 -04003225/**
James Smart3621a712009-04-06 18:47:14 -04003226 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003227 * @phba: pointer to lpfc hba data structure.
3228 * @pmb: pointer to the driver internal queue element for mailbox command.
3229 *
3230 * This routine is the completion callback function for unregister default
3231 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3232 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3233 * decrements the ndlp reference count held for this completion callback
3234 * function. After that, it invokes the lpfc_nlp_not_used() to check
3235 * whether there is only one reference left on the ndlp. If so, it will
3236 * perform one more decrement and trigger the release of the ndlp.
3237 **/
James Smart858c9f62007-06-17 19:56:39 -05003238void
3239lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3240{
3241 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3242 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3243
James Smart6fb120a2009-05-22 14:52:59 -04003244 /*
3245 * This routine is used to register and unregister in previous SLI
3246 * modes.
3247 */
3248 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3249 (phba->sli_rev == LPFC_SLI_REV4))
3250 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3251
James Smart858c9f62007-06-17 19:56:39 -05003252 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003253 pmb->context2 = NULL;
3254
James Smart858c9f62007-06-17 19:56:39 -05003255 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3256 kfree(mp);
3257 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003258 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003259 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003260 /* This is the end of the default RPI cleanup logic for this
3261 * ndlp. If no other discovery threads are using this ndlp.
3262 * we should free all resources associated with it.
3263 */
3264 lpfc_nlp_not_used(ndlp);
3265 }
James Smart3772a992009-05-22 14:50:54 -04003266
James Smart858c9f62007-06-17 19:56:39 -05003267 return;
3268}
3269
James Smarte59058c2008-08-24 21:49:00 -04003270/**
James Smart3621a712009-04-06 18:47:14 -04003271 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003272 * @phba: pointer to lpfc hba data structure.
3273 * @cmdiocb: pointer to lpfc command iocb data structure.
3274 * @rspiocb: pointer to lpfc response iocb data structure.
3275 *
3276 * This routine is the completion callback function for ELS Response IOCB
3277 * command. In normal case, this callback function just properly sets the
3278 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3279 * field in the command IOCB is not NULL, the referred mailbox command will
3280 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3281 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3282 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3283 * routine shall be invoked trying to release the ndlp if no other threads
3284 * are currently referring it.
3285 **/
dea31012005-04-17 16:05:31 -05003286static void
James Smart858c9f62007-06-17 19:56:39 -05003287lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003288 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003289{
James Smart2e0fef82007-06-17 19:56:36 -05003290 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3291 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3292 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003293 IOCB_t *irsp;
3294 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003295 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003296 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003297 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003298
James Smart33ccf8d2006-08-17 11:57:58 -04003299 irsp = &rspiocb->iocb;
3300
dea31012005-04-17 16:05:31 -05003301 if (cmdiocb->context_un.mbox)
3302 mbox = cmdiocb->context_un.mbox;
3303
James Smartfa4066b2008-01-11 01:53:27 -05003304 /* First determine if this is a LS_RJT cmpl. Note, this callback
3305 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3306 */
James Smart87af33f2007-10-27 13:37:43 -04003307 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003308 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3309 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003310 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003311 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003312 */
3313 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3314 ls_rjt = 1;
3315 }
3316
dea31012005-04-17 16:05:31 -05003317 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003318 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003319 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003320 mp = (struct lpfc_dmabuf *) mbox->context1;
3321 if (mp) {
3322 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3323 kfree(mp);
3324 }
James Smart329f9bc2007-04-25 09:53:01 -04003325 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003326 }
James Smart58da1ff2008-04-07 10:15:56 -04003327 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3328 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003329 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003330 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003331 /* Indicate the node has already released,
3332 * should not reference to it from within
3333 * the routine lpfc_els_free_iocb.
3334 */
3335 cmdiocb->context1 = NULL;
3336 }
dea31012005-04-17 16:05:31 -05003337 goto out;
3338 }
3339
James Smart858c9f62007-06-17 19:56:39 -05003340 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003341 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003342 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003343 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003344 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003345 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3346 "0110 ELS response tag x%x completes "
3347 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3348 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3349 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3350 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3351 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003352 if (mbox) {
3353 if ((rspiocb->iocb.ulpStatus == 0)
3354 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003355 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003356 /* Increment reference count to ndlp to hold the
3357 * reference to ndlp for the callback function.
3358 */
James Smart329f9bc2007-04-25 09:53:01 -04003359 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003360 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003361 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3362 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3363 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3364 }
3365 else {
3366 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3367 ndlp->nlp_prev_state = ndlp->nlp_state;
3368 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003369 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003370 }
James Smart0b727fe2007-10-27 13:37:25 -04003371 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003372 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003373 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003374 else
3375 /* Decrement the ndlp reference count we
3376 * set for this failed mailbox command.
3377 */
3378 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003379
3380 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3381 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3382 "0138 ELS rsp: Cannot issue reg_login for x%x "
3383 "Data: x%x x%x x%x\n",
3384 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3385 ndlp->nlp_rpi);
3386
James Smartfa4066b2008-01-11 01:53:27 -05003387 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003388 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003389 /* Indicate node has already been released,
3390 * should not reference to it from within
3391 * the routine lpfc_els_free_iocb.
3392 */
3393 cmdiocb->context1 = NULL;
3394 }
dea31012005-04-17 16:05:31 -05003395 } else {
James Smart858c9f62007-06-17 19:56:39 -05003396 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3397 if (!lpfc_error_lost_link(irsp) &&
3398 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003399 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003400 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003401 /* Indicate node has already been
3402 * released, should not reference
3403 * to it from within the routine
3404 * lpfc_els_free_iocb.
3405 */
3406 cmdiocb->context1 = NULL;
3407 }
dea31012005-04-17 16:05:31 -05003408 }
3409 }
James Smart14691152006-12-02 13:34:28 -05003410 mp = (struct lpfc_dmabuf *) mbox->context1;
3411 if (mp) {
3412 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3413 kfree(mp);
3414 }
3415 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003416 }
3417out:
James Smart58da1ff2008-04-07 10:15:56 -04003418 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003419 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003420 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003421 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003422
3423 /* If the node is not being used by another discovery thread,
3424 * and we are sending a reject, we are done with it.
3425 * Release driver reference count here and free associated
3426 * resources.
3427 */
3428 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003429 if (lpfc_nlp_not_used(ndlp))
3430 /* Indicate node has already been released,
3431 * should not reference to it from within
3432 * the routine lpfc_els_free_iocb.
3433 */
3434 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003435 }
James Smart87af33f2007-10-27 13:37:43 -04003436
dea31012005-04-17 16:05:31 -05003437 lpfc_els_free_iocb(phba, cmdiocb);
3438 return;
3439}
3440
James Smarte59058c2008-08-24 21:49:00 -04003441/**
James Smart3621a712009-04-06 18:47:14 -04003442 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003443 * @vport: pointer to a host virtual N_Port data structure.
3444 * @flag: the els command code to be accepted.
3445 * @oldiocb: pointer to the original lpfc command iocb data structure.
3446 * @ndlp: pointer to a node-list data structure.
3447 * @mbox: pointer to the driver internal queue element for mailbox command.
3448 *
3449 * This routine prepares and issues an Accept (ACC) response IOCB
3450 * command. It uses the @flag to properly set up the IOCB field for the
3451 * specific ACC response command to be issued and invokes the
3452 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3453 * @mbox pointer is passed in, it will be put into the context_un.mbox
3454 * field of the IOCB for the completion callback function to issue the
3455 * mailbox command to the HBA later when callback is invoked.
3456 *
3457 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3458 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3459 * will be stored into the context1 field of the IOCB for the completion
3460 * callback function to the corresponding response ELS IOCB command.
3461 *
3462 * Return code
3463 * 0 - Successfully issued acc response
3464 * 1 - Failed to issue acc response
3465 **/
dea31012005-04-17 16:05:31 -05003466int
James Smart2e0fef82007-06-17 19:56:36 -05003467lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3468 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003469 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003470{
James Smart2e0fef82007-06-17 19:56:36 -05003471 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3472 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003473 IOCB_t *icmd;
3474 IOCB_t *oldcmd;
3475 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003476 struct lpfc_sli *psli;
3477 uint8_t *pcmd;
3478 uint16_t cmdsize;
3479 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003480 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003481
3482 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003483 oldcmd = &oldiocb->iocb;
3484
3485 switch (flag) {
3486 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003487 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003488 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3489 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003490 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003491 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003492 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003493 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003494 return 1;
dea31012005-04-17 16:05:31 -05003495 }
James Smart2e0fef82007-06-17 19:56:36 -05003496
dea31012005-04-17 16:05:31 -05003497 icmd = &elsiocb->iocb;
3498 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3499 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3500 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003501 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003502
3503 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3504 "Issue ACC: did:x%x flg:x%x",
3505 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003506 break;
3507 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003508 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003509 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3510 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003511 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003512 return 1;
James Smart488d1462006-03-07 15:02:37 -05003513
dea31012005-04-17 16:05:31 -05003514 icmd = &elsiocb->iocb;
3515 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3516 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3517
3518 if (mbox)
3519 elsiocb->context_un.mbox = mbox;
3520
3521 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003522 pcmd += sizeof(uint32_t);
3523 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003524
3525 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3526 "Issue ACC PLOGI: did:x%x flg:x%x",
3527 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003528 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003529 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003530 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003531 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003532 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3533 if (!elsiocb)
3534 return 1;
3535
3536 icmd = &elsiocb->iocb;
3537 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3538 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3539
3540 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003541 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003542 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3543 els_pkt_ptr = (ELS_PKT *) pcmd;
3544 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003545
3546 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3547 "Issue ACC PRLO: did:x%x flg:x%x",
3548 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003549 break;
dea31012005-04-17 16:05:31 -05003550 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003551 return 1;
dea31012005-04-17 16:05:31 -05003552 }
dea31012005-04-17 16:05:31 -05003553 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003554 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3555 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3556 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3557 elsiocb->iotag, elsiocb->iocb.ulpContext,
3558 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3559 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003560 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003561 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003562 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003563 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003564 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3565 } else {
James Smart858c9f62007-06-17 19:56:39 -05003566 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003567 }
3568
3569 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003570 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003571 if (rc == IOCB_ERROR) {
3572 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003573 return 1;
dea31012005-04-17 16:05:31 -05003574 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003575 return 0;
dea31012005-04-17 16:05:31 -05003576}
3577
James Smarte59058c2008-08-24 21:49:00 -04003578/**
James Smart3621a712009-04-06 18:47:14 -04003579 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003580 * @vport: pointer to a virtual N_Port data structure.
3581 * @rejectError:
3582 * @oldiocb: pointer to the original lpfc command iocb data structure.
3583 * @ndlp: pointer to a node-list data structure.
3584 * @mbox: pointer to the driver internal queue element for mailbox command.
3585 *
3586 * This routine prepares and issue an Reject (RJT) response IOCB
3587 * command. If a @mbox pointer is passed in, it will be put into the
3588 * context_un.mbox field of the IOCB for the completion callback function
3589 * to issue to the HBA later.
3590 *
3591 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3592 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3593 * will be stored into the context1 field of the IOCB for the completion
3594 * callback function to the reject response ELS IOCB command.
3595 *
3596 * Return code
3597 * 0 - Successfully issued reject response
3598 * 1 - Failed to issue reject response
3599 **/
dea31012005-04-17 16:05:31 -05003600int
James Smart2e0fef82007-06-17 19:56:36 -05003601lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003602 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3603 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003604{
James Smart2e0fef82007-06-17 19:56:36 -05003605 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003606 IOCB_t *icmd;
3607 IOCB_t *oldcmd;
3608 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003609 struct lpfc_sli *psli;
3610 uint8_t *pcmd;
3611 uint16_t cmdsize;
3612 int rc;
3613
3614 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003615 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003616 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3617 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003618 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003619 return 1;
dea31012005-04-17 16:05:31 -05003620
3621 icmd = &elsiocb->iocb;
3622 oldcmd = &oldiocb->iocb;
3623 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3624 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3625
3626 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003627 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003628 *((uint32_t *) (pcmd)) = rejectError;
3629
James Smart51ef4c22007-08-02 11:10:31 -04003630 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003631 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003632
dea31012005-04-17 16:05:31 -05003633 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003634 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3635 "0129 Xmit ELS RJT x%x response tag x%x "
3636 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3637 "rpi x%x\n",
3638 rejectError, elsiocb->iotag,
3639 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3640 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003641 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3642 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3643 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3644
dea31012005-04-17 16:05:31 -05003645 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003646 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003647 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003648
dea31012005-04-17 16:05:31 -05003649 if (rc == IOCB_ERROR) {
3650 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003651 return 1;
dea31012005-04-17 16:05:31 -05003652 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003653 return 0;
dea31012005-04-17 16:05:31 -05003654}
3655
James Smarte59058c2008-08-24 21:49:00 -04003656/**
James Smart3621a712009-04-06 18:47:14 -04003657 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003658 * @vport: pointer to a virtual N_Port data structure.
3659 * @oldiocb: pointer to the original lpfc command iocb data structure.
3660 * @ndlp: pointer to a node-list data structure.
3661 *
3662 * This routine prepares and issues an Accept (ACC) response to Address
3663 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3664 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3665 *
3666 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3667 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3668 * will be stored into the context1 field of the IOCB for the completion
3669 * callback function to the ADISC Accept response ELS IOCB command.
3670 *
3671 * Return code
3672 * 0 - Successfully issued acc adisc response
3673 * 1 - Failed to issue adisc acc response
3674 **/
dea31012005-04-17 16:05:31 -05003675int
James Smart2e0fef82007-06-17 19:56:36 -05003676lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3677 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003678{
James Smart2e0fef82007-06-17 19:56:36 -05003679 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003680 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003681 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003682 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003683 uint8_t *pcmd;
3684 uint16_t cmdsize;
3685 int rc;
3686
James Smart92d7f7b2007-06-17 19:56:38 -05003687 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003688 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3689 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003690 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003691 return 1;
dea31012005-04-17 16:05:31 -05003692
dea31012005-04-17 16:05:31 -05003693 icmd = &elsiocb->iocb;
3694 oldcmd = &oldiocb->iocb;
3695 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003696
3697 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003698 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3699 "0130 Xmit ADISC ACC response iotag x%x xri: "
3700 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3701 elsiocb->iotag, elsiocb->iocb.ulpContext,
3702 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3703 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003704 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3705
3706 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003707 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003708
3709 ap = (ADISC *) (pcmd);
3710 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003711 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3712 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003713 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003714
James Smart858c9f62007-06-17 19:56:39 -05003715 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3716 "Issue ACC ADISC: did:x%x flg:x%x",
3717 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3718
dea31012005-04-17 16:05:31 -05003719 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003720 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003721 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003722 if (rc == IOCB_ERROR) {
3723 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003724 return 1;
dea31012005-04-17 16:05:31 -05003725 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003726 return 0;
dea31012005-04-17 16:05:31 -05003727}
3728
James Smarte59058c2008-08-24 21:49:00 -04003729/**
James Smart3621a712009-04-06 18:47:14 -04003730 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003731 * @vport: pointer to a virtual N_Port data structure.
3732 * @oldiocb: pointer to the original lpfc command iocb data structure.
3733 * @ndlp: pointer to a node-list data structure.
3734 *
3735 * This routine prepares and issues an Accept (ACC) response to Process
3736 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3737 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3738 *
3739 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3740 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3741 * will be stored into the context1 field of the IOCB for the completion
3742 * callback function to the PRLI Accept response ELS IOCB command.
3743 *
3744 * Return code
3745 * 0 - Successfully issued acc prli response
3746 * 1 - Failed to issue acc prli response
3747 **/
dea31012005-04-17 16:05:31 -05003748int
James Smart2e0fef82007-06-17 19:56:36 -05003749lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003750 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003751{
James Smart2e0fef82007-06-17 19:56:36 -05003752 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003753 PRLI *npr;
3754 lpfc_vpd_t *vpd;
3755 IOCB_t *icmd;
3756 IOCB_t *oldcmd;
3757 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003758 struct lpfc_sli *psli;
3759 uint8_t *pcmd;
3760 uint16_t cmdsize;
3761 int rc;
3762
3763 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003764
James Smart92d7f7b2007-06-17 19:56:38 -05003765 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003766 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003767 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003768 if (!elsiocb)
3769 return 1;
dea31012005-04-17 16:05:31 -05003770
dea31012005-04-17 16:05:31 -05003771 icmd = &elsiocb->iocb;
3772 oldcmd = &oldiocb->iocb;
3773 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003774 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003775 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3776 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3777 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3778 elsiocb->iotag, elsiocb->iocb.ulpContext,
3779 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3780 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003781 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3782
3783 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003784 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003785
3786 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003787 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003788
3789 npr = (PRLI *) pcmd;
3790 vpd = &phba->vpd;
3791 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003792 * If the remote port is a target and our firmware version is 3.20 or
3793 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003794 */
James Smart0d2b6b82008-06-14 22:52:47 -04003795 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3796 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003797 npr->ConfmComplAllowed = 1;
3798 npr->Retry = 1;
3799 npr->TaskRetryIdReq = 1;
3800 }
3801
3802 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3803 npr->estabImagePair = 1;
3804 npr->readXferRdyDis = 1;
3805 npr->ConfmComplAllowed = 1;
3806
3807 npr->prliType = PRLI_FCP_TYPE;
3808 npr->initiatorFunc = 1;
3809
James Smart858c9f62007-06-17 19:56:39 -05003810 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3811 "Issue ACC PRLI: did:x%x flg:x%x",
3812 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3813
dea31012005-04-17 16:05:31 -05003814 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003815 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003816
James Smart3772a992009-05-22 14:50:54 -04003817 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003818 if (rc == IOCB_ERROR) {
3819 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003820 return 1;
dea31012005-04-17 16:05:31 -05003821 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003822 return 0;
dea31012005-04-17 16:05:31 -05003823}
3824
James Smarte59058c2008-08-24 21:49:00 -04003825/**
James Smart3621a712009-04-06 18:47:14 -04003826 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003827 * @vport: pointer to a virtual N_Port data structure.
3828 * @format: rnid command format.
3829 * @oldiocb: pointer to the original lpfc command iocb data structure.
3830 * @ndlp: pointer to a node-list data structure.
3831 *
3832 * This routine issues a Request Node Identification Data (RNID) Accept
3833 * (ACC) response. It constructs the RNID ACC response command according to
3834 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3835 * issue the response. Note that this command does not need to hold the ndlp
3836 * reference count for the callback. So, the ndlp reference count taken by
3837 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3838 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3839 * there is no ndlp reference available.
3840 *
3841 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3842 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3843 * will be stored into the context1 field of the IOCB for the completion
3844 * callback function. However, for the RNID Accept Response ELS command,
3845 * this is undone later by this routine after the IOCB is allocated.
3846 *
3847 * Return code
3848 * 0 - Successfully issued acc rnid response
3849 * 1 - Failed to issue acc rnid response
3850 **/
dea31012005-04-17 16:05:31 -05003851static int
James Smart2e0fef82007-06-17 19:56:36 -05003852lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003853 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003854{
James Smart2e0fef82007-06-17 19:56:36 -05003855 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003856 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003857 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003858 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003859 struct lpfc_sli *psli;
3860 uint8_t *pcmd;
3861 uint16_t cmdsize;
3862 int rc;
3863
3864 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003865 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3866 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003867 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003868 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003869
James Smart2e0fef82007-06-17 19:56:36 -05003870 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3871 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003872 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003873 return 1;
dea31012005-04-17 16:05:31 -05003874
dea31012005-04-17 16:05:31 -05003875 icmd = &elsiocb->iocb;
3876 oldcmd = &oldiocb->iocb;
3877 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003878 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003879 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3880 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3881 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003882 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003883 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003884 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003885
James Smart92d7f7b2007-06-17 19:56:38 -05003886 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003887 rn = (RNID *) (pcmd);
3888 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003889 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3890 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3891 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003892 switch (format) {
3893 case 0:
3894 rn->SpecificLen = 0;
3895 break;
3896 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003897 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003898 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003899 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003900 rn->un.topologyDisc.unitType = RNID_HBA;
3901 rn->un.topologyDisc.physPort = 0;
3902 rn->un.topologyDisc.attachedNodes = 0;
3903 break;
3904 default:
3905 rn->CommonLen = 0;
3906 rn->SpecificLen = 0;
3907 break;
3908 }
3909
James Smart858c9f62007-06-17 19:56:39 -05003910 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3911 "Issue ACC RNID: did:x%x flg:x%x",
3912 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3913
dea31012005-04-17 16:05:31 -05003914 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003915 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003916 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003917 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3918 * it could be freed */
3919
James Smart3772a992009-05-22 14:50:54 -04003920 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003921 if (rc == IOCB_ERROR) {
3922 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003923 return 1;
dea31012005-04-17 16:05:31 -05003924 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003925 return 0;
dea31012005-04-17 16:05:31 -05003926}
3927
James Smarte59058c2008-08-24 21:49:00 -04003928/**
James Smart3621a712009-04-06 18:47:14 -04003929 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04003930 * @vport: pointer to a host virtual N_Port data structure.
3931 *
3932 * This routine issues Address Discover (ADISC) ELS commands to those
3933 * N_Ports which are in node port recovery state and ADISC has not been issued
3934 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3935 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3936 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3937 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3938 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3939 * IOCBs quit for later pick up. On the other hand, after walking through
3940 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3941 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3942 * no more ADISC need to be sent.
3943 *
3944 * Return code
3945 * The number of N_Ports with adisc issued.
3946 **/
dea31012005-04-17 16:05:31 -05003947int
James Smart2e0fef82007-06-17 19:56:36 -05003948lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003949{
James Smart2e0fef82007-06-17 19:56:36 -05003950 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003951 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003952 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003953
James Smart685f0bf2007-04-25 09:53:08 -04003954 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05003955 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003956 if (!NLP_CHK_NODE_ACT(ndlp))
3957 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003958 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3959 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3960 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003961 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003962 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05003963 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003964 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003965 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3966 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003967 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05003968 vport->num_disc_nodes++;
3969 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003970 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003971 spin_lock_irq(shost->host_lock);
3972 vport->fc_flag |= FC_NLP_MORE;
3973 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003974 break;
dea31012005-04-17 16:05:31 -05003975 }
3976 }
3977 }
3978 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003979 spin_lock_irq(shost->host_lock);
3980 vport->fc_flag &= ~FC_NLP_MORE;
3981 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003982 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003983 return sentadisc;
dea31012005-04-17 16:05:31 -05003984}
3985
James Smarte59058c2008-08-24 21:49:00 -04003986/**
James Smart3621a712009-04-06 18:47:14 -04003987 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04003988 * @vport: pointer to a host virtual N_Port data structure.
3989 *
3990 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3991 * which are in node port recovery state, with a @vport. Each time an ELS
3992 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3993 * the per @vport number of discover count (num_disc_nodes) shall be
3994 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3995 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3996 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3997 * later pick up. On the other hand, after walking through all the ndlps with
3998 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3999 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4000 * PLOGI need to be sent.
4001 *
4002 * Return code
4003 * The number of N_Ports with plogi issued.
4004 **/
dea31012005-04-17 16:05:31 -05004005int
James Smart2e0fef82007-06-17 19:56:36 -05004006lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004007{
James Smart2e0fef82007-06-17 19:56:36 -05004008 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004009 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004010 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004011
James Smart2e0fef82007-06-17 19:56:36 -05004012 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4013 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004014 if (!NLP_CHK_NODE_ACT(ndlp))
4015 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004016 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4017 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4018 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4019 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4020 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004021 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4022 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004023 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004024 vport->num_disc_nodes++;
4025 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004026 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004027 spin_lock_irq(shost->host_lock);
4028 vport->fc_flag |= FC_NLP_MORE;
4029 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004030 break;
dea31012005-04-17 16:05:31 -05004031 }
4032 }
4033 }
James Smart87af33f2007-10-27 13:37:43 -04004034 if (sentplogi) {
4035 lpfc_set_disctmo(vport);
4036 }
4037 else {
James Smart2e0fef82007-06-17 19:56:36 -05004038 spin_lock_irq(shost->host_lock);
4039 vport->fc_flag &= ~FC_NLP_MORE;
4040 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004041 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004042 return sentplogi;
dea31012005-04-17 16:05:31 -05004043}
4044
James Smarte59058c2008-08-24 21:49:00 -04004045/**
James Smart3621a712009-04-06 18:47:14 -04004046 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004047 * @vport: pointer to a host virtual N_Port data structure.
4048 *
4049 * This routine cleans up any Registration State Change Notification
4050 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4051 * @vport together with the host_lock is used to prevent multiple thread
4052 * trying to access the RSCN array on a same @vport at the same time.
4053 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004054void
James Smart2e0fef82007-06-17 19:56:36 -05004055lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004056{
James Smart2e0fef82007-06-17 19:56:36 -05004057 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4058 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004059 int i;
4060
James Smart7f5f3d02008-02-08 18:50:14 -05004061 spin_lock_irq(shost->host_lock);
4062 if (vport->fc_rscn_flush) {
4063 /* Another thread is walking fc_rscn_id_list on this vport */
4064 spin_unlock_irq(shost->host_lock);
4065 return;
4066 }
4067 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4068 vport->fc_rscn_flush = 1;
4069 spin_unlock_irq(shost->host_lock);
4070
James Smart2e0fef82007-06-17 19:56:36 -05004071 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004072 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004073 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004074 }
James Smart2e0fef82007-06-17 19:56:36 -05004075 spin_lock_irq(shost->host_lock);
4076 vport->fc_rscn_id_cnt = 0;
4077 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4078 spin_unlock_irq(shost->host_lock);
4079 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004080 /* Indicate we are done walking this fc_rscn_id_list */
4081 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004082}
4083
James Smarte59058c2008-08-24 21:49:00 -04004084/**
James Smart3621a712009-04-06 18:47:14 -04004085 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004086 * @vport: pointer to a host virtual N_Port data structure.
4087 * @did: remote destination port identifier.
4088 *
4089 * This routine checks whether there is any pending Registration State
4090 * Configuration Notification (RSCN) to a @did on @vport.
4091 *
4092 * Return code
4093 * None zero - The @did matched with a pending rscn
4094 * 0 - not able to match @did with a pending rscn
4095 **/
dea31012005-04-17 16:05:31 -05004096int
James Smart2e0fef82007-06-17 19:56:36 -05004097lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004098{
4099 D_ID ns_did;
4100 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004101 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004102 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004103 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004104
4105 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004106
4107 /* Never match fabric nodes for RSCNs */
4108 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004109 return 0;
dea31012005-04-17 16:05:31 -05004110
4111 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004112 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004113 return did;
dea31012005-04-17 16:05:31 -05004114
James Smart7f5f3d02008-02-08 18:50:14 -05004115 spin_lock_irq(shost->host_lock);
4116 if (vport->fc_rscn_flush) {
4117 /* Another thread is walking fc_rscn_id_list on this vport */
4118 spin_unlock_irq(shost->host_lock);
4119 return 0;
4120 }
4121 /* Indicate we are walking fc_rscn_id_list on this vport */
4122 vport->fc_rscn_flush = 1;
4123 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004124 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004125 lp = vport->fc_rscn_id_list[i]->virt;
4126 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4127 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004128 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004129 rscn_did.un.word = be32_to_cpu(*lp++);
4130 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004131 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4132 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004133 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4134 && (ns_did.un.b.area == rscn_did.un.b.area)
4135 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004136 goto return_did_out;
dea31012005-04-17 16:05:31 -05004137 break;
James Smarteaf15d52008-12-04 22:39:29 -05004138 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004139 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4140 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004141 goto return_did_out;
dea31012005-04-17 16:05:31 -05004142 break;
James Smarteaf15d52008-12-04 22:39:29 -05004143 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004144 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004145 goto return_did_out;
dea31012005-04-17 16:05:31 -05004146 break;
James Smarteaf15d52008-12-04 22:39:29 -05004147 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004148 goto return_did_out;
dea31012005-04-17 16:05:31 -05004149 }
4150 }
James Smart92d7f7b2007-06-17 19:56:38 -05004151 }
James Smart7f5f3d02008-02-08 18:50:14 -05004152 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4153 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004154 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004155return_did_out:
4156 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4157 vport->fc_rscn_flush = 0;
4158 return did;
dea31012005-04-17 16:05:31 -05004159}
4160
James Smarte59058c2008-08-24 21:49:00 -04004161/**
James Smart3621a712009-04-06 18:47:14 -04004162 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004163 * @vport: pointer to a host virtual N_Port data structure.
4164 *
4165 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4166 * state machine for a @vport's nodes that are with pending RSCN (Registration
4167 * State Change Notification).
4168 *
4169 * Return code
4170 * 0 - Successful (currently alway return 0)
4171 **/
dea31012005-04-17 16:05:31 -05004172static int
James Smart2e0fef82007-06-17 19:56:36 -05004173lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004174{
James Smart685f0bf2007-04-25 09:53:08 -04004175 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004176
James Smart0d2b6b82008-06-14 22:52:47 -04004177 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004178 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004179 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004180 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4181 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004182 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004183 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004184 NLP_EVT_DEVICE_RECOVERY);
4185 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004186 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004187 return 0;
dea31012005-04-17 16:05:31 -05004188}
4189
James Smarte59058c2008-08-24 21:49:00 -04004190/**
James Smart3621a712009-04-06 18:47:14 -04004191 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004192 * @vport: pointer to a host virtual N_Port data structure.
4193 * @cmdiocb: pointer to lpfc command iocb data structure.
4194 *
4195 * lpfc_send_rscn_event sends an RSCN netlink event to management
4196 * applications.
4197 */
4198static void
4199lpfc_send_rscn_event(struct lpfc_vport *vport,
4200 struct lpfc_iocbq *cmdiocb)
4201{
4202 struct lpfc_dmabuf *pcmd;
4203 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4204 uint32_t *payload_ptr;
4205 uint32_t payload_len;
4206 struct lpfc_rscn_event_header *rscn_event_data;
4207
4208 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4209 payload_ptr = (uint32_t *) pcmd->virt;
4210 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4211
4212 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4213 payload_len, GFP_KERNEL);
4214 if (!rscn_event_data) {
4215 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4216 "0147 Failed to allocate memory for RSCN event\n");
4217 return;
4218 }
4219 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4220 rscn_event_data->payload_length = payload_len;
4221 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4222 payload_len);
4223
4224 fc_host_post_vendor_event(shost,
4225 fc_get_event_number(),
4226 sizeof(struct lpfc_els_event_header) + payload_len,
4227 (char *)rscn_event_data,
4228 LPFC_NL_VENDOR_ID);
4229
4230 kfree(rscn_event_data);
4231}
4232
4233/**
James Smart3621a712009-04-06 18:47:14 -04004234 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004235 * @vport: pointer to a host virtual N_Port data structure.
4236 * @cmdiocb: pointer to lpfc command iocb data structure.
4237 * @ndlp: pointer to a node-list data structure.
4238 *
4239 * This routine processes an unsolicited RSCN (Registration State Change
4240 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4241 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4242 * discover state machine is about to begin discovery, it just accepts the
4243 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4244 * contains N_Port IDs for other vports on this HBA, it just accepts the
4245 * RSCN and ignore processing it. If the state machine is in the recovery
4246 * state, the fc_rscn_id_list of this @vport is walked and the
4247 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4248 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4249 * routine is invoked to handle the RSCN event.
4250 *
4251 * Return code
4252 * 0 - Just sent the acc response
4253 * 1 - Sent the acc response and waited for name server completion
4254 **/
dea31012005-04-17 16:05:31 -05004255static int
James Smart2e0fef82007-06-17 19:56:36 -05004256lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004257 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004258{
James Smart2e0fef82007-06-17 19:56:36 -05004259 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4260 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004261 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004262 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004263 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004264 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004265 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004266 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004267 int i;
dea31012005-04-17 16:05:31 -05004268
4269 icmd = &cmdiocb->iocb;
4270 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4271 lp = (uint32_t *) pcmd->virt;
4272
James Smart92d7f7b2007-06-17 19:56:38 -05004273 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4274 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004275 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004276 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4277 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004278 vport->fc_flag, payload_len, *lp,
4279 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004280
4281 /* Send an RSCN event to the management application */
4282 lpfc_send_rscn_event(vport, cmdiocb);
4283
James Smartd2873e42006-08-18 17:46:43 -04004284 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004285 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004286 FCH_EVT_RSCN, lp[i]);
4287
dea31012005-04-17 16:05:31 -05004288 /* If we are about to begin discovery, just ACC the RSCN.
4289 * Discovery processing will satisfy it.
4290 */
James Smart2e0fef82007-06-17 19:56:36 -05004291 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004292 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4293 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4294 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4295
James Smart51ef4c22007-08-02 11:10:31 -04004296 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004297 return 0;
dea31012005-04-17 16:05:31 -05004298 }
4299
James Smart92d7f7b2007-06-17 19:56:38 -05004300 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4301 * just ACC and ignore it.
4302 */
4303 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004304 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004305 i = payload_len;
4306 datap = lp;
4307 while (i > 0) {
4308 nportid = *datap++;
4309 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4310 i -= sizeof(uint32_t);
4311 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004312 if (lpfc_find_vport_by_did(phba, nportid))
4313 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004314 }
4315 if (rscn_id == hba_id) {
4316 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004317 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004318 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004319 "Data: x%x x%x x%x x%x\n",
4320 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004321 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004322 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4323 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4324 ndlp->nlp_DID, vport->port_state,
4325 ndlp->nlp_flag);
4326
James Smart92d7f7b2007-06-17 19:56:38 -05004327 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004328 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004329 return 0;
4330 }
4331 }
4332
James Smart7f5f3d02008-02-08 18:50:14 -05004333 spin_lock_irq(shost->host_lock);
4334 if (vport->fc_rscn_flush) {
4335 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004336 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004337 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004338 /* Send back ACC */
4339 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004340 return 0;
4341 }
4342 /* Indicate we are walking fc_rscn_id_list on this vport */
4343 vport->fc_rscn_flush = 1;
4344 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004345 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004346 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004347 /* If we are already processing an RSCN, save the received
4348 * RSCN payload buffer, cmdiocb->context2 to process later.
4349 */
James Smart2e0fef82007-06-17 19:56:36 -05004350 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004351 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4352 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4353 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4354
James Smart09372822008-01-11 01:52:54 -05004355 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004356 vport->fc_flag |= FC_RSCN_DEFERRED;
4357 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004358 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004359 vport->fc_flag |= FC_RSCN_MODE;
4360 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004361 if (rscn_cnt) {
4362 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4363 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4364 }
4365 if ((rscn_cnt) &&
4366 (payload_len + length <= LPFC_BPL_SIZE)) {
4367 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004368 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004369 memcpy(((uint8_t *)cmd) + length, lp,
4370 payload_len);
4371 } else {
4372 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4373 vport->fc_rscn_id_cnt++;
4374 /* If we zero, cmdiocb->context2, the calling
4375 * routine will not try to free it.
4376 */
4377 cmdiocb->context2 = NULL;
4378 }
dea31012005-04-17 16:05:31 -05004379 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004380 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4381 "0235 Deferred RSCN "
4382 "Data: x%x x%x x%x\n",
4383 vport->fc_rscn_id_cnt, vport->fc_flag,
4384 vport->port_state);
dea31012005-04-17 16:05:31 -05004385 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004386 vport->fc_flag |= FC_RSCN_DISCOVERY;
4387 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004388 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004389 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4390 "0234 ReDiscovery RSCN "
4391 "Data: x%x x%x x%x\n",
4392 vport->fc_rscn_id_cnt, vport->fc_flag,
4393 vport->port_state);
dea31012005-04-17 16:05:31 -05004394 }
James Smart7f5f3d02008-02-08 18:50:14 -05004395 /* Indicate we are done walking fc_rscn_id_list on this vport */
4396 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004397 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004398 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004399 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004400 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004401 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004402 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004403 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004404 return 0;
dea31012005-04-17 16:05:31 -05004405 }
James Smart858c9f62007-06-17 19:56:39 -05004406 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4407 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4408 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4409
James Smart2e0fef82007-06-17 19:56:36 -05004410 spin_lock_irq(shost->host_lock);
4411 vport->fc_flag |= FC_RSCN_MODE;
4412 spin_unlock_irq(shost->host_lock);
4413 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004414 /* Indicate we are done walking fc_rscn_id_list on this vport */
4415 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004416 /*
4417 * If we zero, cmdiocb->context2, the calling routine will
4418 * not try to free it.
4419 */
4420 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004421 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004422 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004423 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004424 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004425 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004426 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004427}
4428
James Smarte59058c2008-08-24 21:49:00 -04004429/**
James Smart3621a712009-04-06 18:47:14 -04004430 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004431 * @vport: pointer to a host virtual N_Port data structure.
4432 *
4433 * This routine handles the Registration State Configuration Notification
4434 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4435 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4436 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4437 * NameServer shall be issued. If CT command to the NameServer fails to be
4438 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4439 * RSCN activities with the @vport.
4440 *
4441 * Return code
4442 * 0 - Cleaned up rscn on the @vport
4443 * 1 - Wait for plogi to name server before proceed
4444 **/
dea31012005-04-17 16:05:31 -05004445int
James Smart2e0fef82007-06-17 19:56:36 -05004446lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004447{
4448 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004449 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004450
James Smart92d7f7b2007-06-17 19:56:38 -05004451 /* Ignore RSCN if the port is being torn down. */
4452 if (vport->load_flag & FC_UNLOADING) {
4453 lpfc_els_flush_rscn(vport);
4454 return 0;
4455 }
4456
dea31012005-04-17 16:05:31 -05004457 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004458 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004459
4460 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004461 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4462 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4463 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4464 vport->port_state);
dea31012005-04-17 16:05:31 -05004465
4466 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004467 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004468 vport->num_disc_nodes = 0;
4469
James Smart2e0fef82007-06-17 19:56:36 -05004470 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004471 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4472 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004473 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004474 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004475 /* Wait for NameServer query cmpl before we can
4476 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004477 return 1;
dea31012005-04-17 16:05:31 -05004478 } else {
4479 /* If login to NameServer does not exist, issue one */
4480 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004481 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004482 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004483 /* Wait for NameServer login cmpl before we can
4484 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004485 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004486
James Smarte47c9092008-02-08 18:49:26 -05004487 if (ndlp) {
4488 ndlp = lpfc_enable_node(vport, ndlp,
4489 NLP_STE_PLOGI_ISSUE);
4490 if (!ndlp) {
4491 lpfc_els_flush_rscn(vport);
4492 return 0;
4493 }
4494 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004495 } else {
James Smarte47c9092008-02-08 18:49:26 -05004496 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4497 if (!ndlp) {
4498 lpfc_els_flush_rscn(vport);
4499 return 0;
4500 }
James Smart2e0fef82007-06-17 19:56:36 -05004501 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004502 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004503 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004504 }
James Smarte47c9092008-02-08 18:49:26 -05004505 ndlp->nlp_type |= NLP_FABRIC;
4506 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4507 /* Wait for NameServer login cmpl before we can
4508 * continue
4509 */
4510 return 1;
dea31012005-04-17 16:05:31 -05004511 }
4512
James Smart2e0fef82007-06-17 19:56:36 -05004513 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004514 return 0;
dea31012005-04-17 16:05:31 -05004515}
4516
James Smarte59058c2008-08-24 21:49:00 -04004517/**
James Smart3621a712009-04-06 18:47:14 -04004518 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004519 * @vport: pointer to a host virtual N_Port data structure.
4520 * @cmdiocb: pointer to lpfc command iocb data structure.
4521 * @ndlp: pointer to a node-list data structure.
4522 *
4523 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4524 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4525 * point topology. As an unsolicited FLOGI should not be received in a loop
4526 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4527 * lpfc_check_sparm() routine is invoked to check the parameters in the
4528 * unsolicited FLOGI. If parameters validation failed, the routine
4529 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4530 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4531 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4532 * will initiate PLOGI. The higher lexicographical value party shall has
4533 * higher priority (as the winning port) and will initiate PLOGI and
4534 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4535 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4536 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4537 *
4538 * Return code
4539 * 0 - Successfully processed the unsolicited flogi
4540 * 1 - Failed to process the unsolicited flogi
4541 **/
dea31012005-04-17 16:05:31 -05004542static int
James Smart2e0fef82007-06-17 19:56:36 -05004543lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004544 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004545{
James Smart2e0fef82007-06-17 19:56:36 -05004546 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4547 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004548 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4549 uint32_t *lp = (uint32_t *) pcmd->virt;
4550 IOCB_t *icmd = &cmdiocb->iocb;
4551 struct serv_parm *sp;
4552 LPFC_MBOXQ_t *mbox;
4553 struct ls_rjt stat;
4554 uint32_t cmd, did;
4555 int rc;
4556
4557 cmd = *lp++;
4558 sp = (struct serv_parm *) lp;
4559
4560 /* FLOGI received */
4561
James Smart2e0fef82007-06-17 19:56:36 -05004562 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004563
4564 if (phba->fc_topology == TOPOLOGY_LOOP) {
4565 /* We should never receive a FLOGI in loop mode, ignore it */
4566 did = icmd->un.elsreq64.remoteID;
4567
4568 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4569 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004570 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4571 "0113 An FLOGI ELS command x%x was "
4572 "received from DID x%x in Loop Mode\n",
4573 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004574 return 1;
dea31012005-04-17 16:05:31 -05004575 }
4576
4577 did = Fabric_DID;
4578
James Smart341af102010-01-26 23:07:37 -05004579 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004580 /* For a FLOGI we accept, then if our portname is greater
4581 * then the remote portname we initiate Nport login.
4582 */
4583
James Smart2e0fef82007-06-17 19:56:36 -05004584 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004585 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004586
4587 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004588 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4589 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004590 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004591
dea31012005-04-17 16:05:31 -05004592 lpfc_linkdown(phba);
4593 lpfc_init_link(phba, mbox,
4594 phba->cfg_topology,
4595 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004596 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004597 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004598 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004599 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004600 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004601 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004602 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004603 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004604 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004605 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004606 spin_lock_irq(shost->host_lock);
4607 vport->fc_flag |= FC_PT2PT_PLOGI;
4608 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004609 }
James Smart2e0fef82007-06-17 19:56:36 -05004610 spin_lock_irq(shost->host_lock);
4611 vport->fc_flag |= FC_PT2PT;
4612 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4613 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004614 } else {
4615 /* Reject this request because invalid parameters */
4616 stat.un.b.lsRjtRsvd0 = 0;
4617 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4618 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4619 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004620 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4621 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004622 return 1;
dea31012005-04-17 16:05:31 -05004623 }
4624
4625 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004626 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004627
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004628 return 0;
dea31012005-04-17 16:05:31 -05004629}
4630
James Smarte59058c2008-08-24 21:49:00 -04004631/**
James Smart3621a712009-04-06 18:47:14 -04004632 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004633 * @vport: pointer to a host virtual N_Port data structure.
4634 * @cmdiocb: pointer to lpfc command iocb data structure.
4635 * @ndlp: pointer to a node-list data structure.
4636 *
4637 * This routine processes Request Node Identification Data (RNID) IOCB
4638 * received as an ELS unsolicited event. Only when the RNID specified format
4639 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4640 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4641 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4642 * rejected by invoking the lpfc_els_rsp_reject() routine.
4643 *
4644 * Return code
4645 * 0 - Successfully processed rnid iocb (currently always return 0)
4646 **/
dea31012005-04-17 16:05:31 -05004647static int
James Smart2e0fef82007-06-17 19:56:36 -05004648lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4649 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004650{
4651 struct lpfc_dmabuf *pcmd;
4652 uint32_t *lp;
4653 IOCB_t *icmd;
4654 RNID *rn;
4655 struct ls_rjt stat;
4656 uint32_t cmd, did;
4657
4658 icmd = &cmdiocb->iocb;
4659 did = icmd->un.elsreq64.remoteID;
4660 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4661 lp = (uint32_t *) pcmd->virt;
4662
4663 cmd = *lp++;
4664 rn = (RNID *) lp;
4665
4666 /* RNID received */
4667
4668 switch (rn->Format) {
4669 case 0:
4670 case RNID_TOPOLOGY_DISC:
4671 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004672 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004673 break;
4674 default:
4675 /* Reject this request because format not supported */
4676 stat.un.b.lsRjtRsvd0 = 0;
4677 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4678 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4679 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004680 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4681 NULL);
dea31012005-04-17 16:05:31 -05004682 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004683 return 0;
dea31012005-04-17 16:05:31 -05004684}
4685
James Smarte59058c2008-08-24 21:49:00 -04004686/**
James Smart3621a712009-04-06 18:47:14 -04004687 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004688 * @vport: pointer to a host virtual N_Port data structure.
4689 * @cmdiocb: pointer to lpfc command iocb data structure.
4690 * @ndlp: pointer to a node-list data structure.
4691 *
4692 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4693 * received as an ELS unsolicited event. Currently, this function just invokes
4694 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4695 *
4696 * Return code
4697 * 0 - Successfully processed lirr iocb (currently always return 0)
4698 **/
dea31012005-04-17 16:05:31 -05004699static int
James Smart2e0fef82007-06-17 19:56:36 -05004700lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4701 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004702{
4703 struct ls_rjt stat;
4704
4705 /* For now, unconditionally reject this command */
4706 stat.un.b.lsRjtRsvd0 = 0;
4707 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4708 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4709 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004710 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004711 return 0;
4712}
4713
James Smarte59058c2008-08-24 21:49:00 -04004714/**
James Smart5ffc2662009-11-18 15:39:44 -05004715 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4716 * @vport: pointer to a host virtual N_Port data structure.
4717 * @cmdiocb: pointer to lpfc command iocb data structure.
4718 * @ndlp: pointer to a node-list data structure.
4719 *
4720 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4721 * received as an ELS unsolicited event. A request to RRQ shall only
4722 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4723 * Nx_Port N_Port_ID of the target Exchange is the same as the
4724 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4725 * not accepted, an LS_RJT with reason code "Unable to perform
4726 * command request" and reason code explanation "Invalid Originator
4727 * S_ID" shall be returned. For now, we just unconditionally accept
4728 * RRQ from the target.
4729 **/
4730static void
4731lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4732 struct lpfc_nodelist *ndlp)
4733{
4734 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4735}
4736
4737/**
James Smart3621a712009-04-06 18:47:14 -04004738 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004739 * @phba: pointer to lpfc hba data structure.
4740 * @pmb: pointer to the driver internal queue element for mailbox command.
4741 *
4742 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4743 * mailbox command. This callback function is to actually send the Accept
4744 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4745 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4746 * mailbox command, constructs the RPS response with the link statistics
4747 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4748 * response to the RPS.
4749 *
4750 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4751 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4752 * will be stored into the context1 field of the IOCB for the completion
4753 * callback function to the RPS Accept Response ELS IOCB command.
4754 *
4755 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004756static void
James Smart329f9bc2007-04-25 09:53:01 -04004757lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004758{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004759 MAILBOX_t *mb;
4760 IOCB_t *icmd;
4761 RPS_RSP *rps_rsp;
4762 uint8_t *pcmd;
4763 struct lpfc_iocbq *elsiocb;
4764 struct lpfc_nodelist *ndlp;
4765 uint16_t xri, status;
4766 uint32_t cmdsize;
4767
James Smart04c68492009-05-22 14:52:52 -04004768 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004769
4770 ndlp = (struct lpfc_nodelist *) pmb->context2;
4771 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004772 pmb->context1 = NULL;
4773 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004774
4775 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004776 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004777 return;
4778 }
4779
4780 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004781 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004782 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4783 lpfc_max_els_tries, ndlp,
4784 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004785
4786 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004787 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004788
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004789 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004790 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004791
4792 icmd = &elsiocb->iocb;
4793 icmd->ulpContext = xri;
4794
4795 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4796 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004797 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004798 rps_rsp = (RPS_RSP *)pcmd;
4799
4800 if (phba->fc_topology != TOPOLOGY_LOOP)
4801 status = 0x10;
4802 else
4803 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004804 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004805 status |= 0x4;
4806
4807 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004808 rps_rsp->portStatus = cpu_to_be16(status);
4809 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4810 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4811 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4812 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4813 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4814 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004815 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004816 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4817 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4818 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4819 elsiocb->iotag, elsiocb->iocb.ulpContext,
4820 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4821 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004822 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004823 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004824 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004825 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004826 return;
4827}
4828
James Smarte59058c2008-08-24 21:49:00 -04004829/**
James Smart3621a712009-04-06 18:47:14 -04004830 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04004831 * @vport: pointer to a host virtual N_Port data structure.
4832 * @cmdiocb: pointer to lpfc command iocb data structure.
4833 * @ndlp: pointer to a node-list data structure.
4834 *
4835 * This routine processes Read Port Status (RPS) IOCB received as an
4836 * ELS unsolicited event. It first checks the remote port state. If the
4837 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4838 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4839 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4840 * for reading the HBA link statistics. It is for the callback function,
4841 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4842 * to actually sending out RPS Accept (ACC) response.
4843 *
4844 * Return codes
4845 * 0 - Successfully processed rps iocb (currently always return 0)
4846 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004847static int
James Smart2e0fef82007-06-17 19:56:36 -05004848lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4849 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004850{
James Smart2e0fef82007-06-17 19:56:36 -05004851 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004852 uint32_t *lp;
4853 uint8_t flag;
4854 LPFC_MBOXQ_t *mbox;
4855 struct lpfc_dmabuf *pcmd;
4856 RPS *rps;
4857 struct ls_rjt stat;
4858
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004859 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04004860 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4861 /* reject the unsolicited RPS request and done with it */
4862 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004863
4864 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4865 lp = (uint32_t *) pcmd->virt;
4866 flag = (be32_to_cpu(*lp++) & 0xf);
4867 rps = (RPS *) lp;
4868
4869 if ((flag == 0) ||
4870 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05004871 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004872 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05004873
James Smart92d7f7b2007-06-17 19:56:38 -05004874 printk("Fix me....\n");
4875 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05004876 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4877 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004878 lpfc_read_lnk_stat(phba, mbox);
4879 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05004880 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04004881 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004882 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004883 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05004884 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04004885 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004886 /* Mbox completion will send ELS Response */
4887 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05004888 /* Decrement reference count used for the failed mbox
4889 * command.
4890 */
James Smart329f9bc2007-04-25 09:53:01 -04004891 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004892 mempool_free(mbox, phba->mbox_mem_pool);
4893 }
4894 }
James Smart90160e02008-08-24 21:49:45 -04004895
4896reject_out:
4897 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004898 stat.un.b.lsRjtRsvd0 = 0;
4899 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4900 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4901 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004902 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004903 return 0;
4904}
4905
James Smarte59058c2008-08-24 21:49:00 -04004906/**
James Smart3621a712009-04-06 18:47:14 -04004907 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04004908 * @vport: pointer to a host virtual N_Port data structure.
4909 * @cmdsize: size of the ELS command.
4910 * @oldiocb: pointer to the original lpfc command iocb data structure.
4911 * @ndlp: pointer to a node-list data structure.
4912 *
4913 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4914 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4915 *
4916 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4917 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4918 * will be stored into the context1 field of the IOCB for the completion
4919 * callback function to the RPL Accept Response ELS command.
4920 *
4921 * Return code
4922 * 0 - Successfully issued ACC RPL ELS command
4923 * 1 - Failed to issue ACC RPL ELS command
4924 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004925static int
James Smart2e0fef82007-06-17 19:56:36 -05004926lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4927 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004928{
James Smart2e0fef82007-06-17 19:56:36 -05004929 struct lpfc_hba *phba = vport->phba;
4930 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004931 RPL_RSP rpl_rsp;
4932 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004933 uint8_t *pcmd;
4934
James Smart2e0fef82007-06-17 19:56:36 -05004935 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4936 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004937
James Smart488d1462006-03-07 15:02:37 -05004938 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004939 return 1;
James Smart488d1462006-03-07 15:02:37 -05004940
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004941 icmd = &elsiocb->iocb;
4942 oldcmd = &oldiocb->iocb;
4943 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4944
4945 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4946 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004947 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004948 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4949 pcmd += sizeof(uint16_t);
4950
4951 /* Setup the RPL ACC payload */
4952 rpl_rsp.listLen = be32_to_cpu(1);
4953 rpl_rsp.index = 0;
4954 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004955 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4956 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004957 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004958 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004959 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004960 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4961 "0120 Xmit ELS RPL ACC response tag x%x "
4962 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4963 "rpi x%x\n",
4964 elsiocb->iotag, elsiocb->iocb.ulpContext,
4965 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4966 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004967 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004968 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004969 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
4970 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004971 lpfc_els_free_iocb(phba, elsiocb);
4972 return 1;
4973 }
4974 return 0;
4975}
4976
James Smarte59058c2008-08-24 21:49:00 -04004977/**
James Smart3621a712009-04-06 18:47:14 -04004978 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04004979 * @vport: pointer to a host virtual N_Port data structure.
4980 * @cmdiocb: pointer to lpfc command iocb data structure.
4981 * @ndlp: pointer to a node-list data structure.
4982 *
4983 * This routine processes Read Port List (RPL) IOCB received as an ELS
4984 * unsolicited event. It first checks the remote port state. If the remote
4985 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4986 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4987 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4988 * to accept the RPL.
4989 *
4990 * Return code
4991 * 0 - Successfully processed rpl iocb (currently always return 0)
4992 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004993static int
James Smart2e0fef82007-06-17 19:56:36 -05004994lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4995 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004996{
4997 struct lpfc_dmabuf *pcmd;
4998 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004999 uint32_t maxsize;
5000 uint16_t cmdsize;
5001 RPL *rpl;
5002 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005003
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005004 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5005 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005006 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005007 stat.un.b.lsRjtRsvd0 = 0;
5008 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5009 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5010 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005011 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5012 NULL);
James Smart90160e02008-08-24 21:49:45 -04005013 /* rejected the unsolicited RPL request and done with it */
5014 return 0;
dea31012005-04-17 16:05:31 -05005015 }
5016
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005017 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5018 lp = (uint32_t *) pcmd->virt;
5019 rpl = (RPL *) (lp + 1);
5020
5021 maxsize = be32_to_cpu(rpl->maxsize);
5022
5023 /* We support only one port */
5024 if ((rpl->index == 0) &&
5025 ((maxsize == 0) ||
5026 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5027 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005028 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005029 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5030 }
James Smart2e0fef82007-06-17 19:56:36 -05005031 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005032
5033 return 0;
5034}
5035
James Smarte59058c2008-08-24 21:49:00 -04005036/**
James Smart3621a712009-04-06 18:47:14 -04005037 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005038 * @vport: pointer to a virtual N_Port data structure.
5039 * @cmdiocb: pointer to lpfc command iocb data structure.
5040 * @ndlp: pointer to a node-list data structure.
5041 *
5042 * This routine processes Fibre Channel Address Resolution Protocol
5043 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5044 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5045 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5046 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5047 * remote PortName is compared against the FC PortName stored in the @vport
5048 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5049 * compared against the FC NodeName stored in the @vport data structure.
5050 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5051 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5052 * invoked to send out FARP Response to the remote node. Before sending the
5053 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5054 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5055 * routine is invoked to log into the remote port first.
5056 *
5057 * Return code
5058 * 0 - Either the FARP Match Mode not supported or successfully processed
5059 **/
dea31012005-04-17 16:05:31 -05005060static int
James Smart2e0fef82007-06-17 19:56:36 -05005061lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5062 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005063{
5064 struct lpfc_dmabuf *pcmd;
5065 uint32_t *lp;
5066 IOCB_t *icmd;
5067 FARP *fp;
5068 uint32_t cmd, cnt, did;
5069
5070 icmd = &cmdiocb->iocb;
5071 did = icmd->un.elsreq64.remoteID;
5072 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5073 lp = (uint32_t *) pcmd->virt;
5074
5075 cmd = *lp++;
5076 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005077 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005078 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5079 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005080 /* We will only support match on WWPN or WWNN */
5081 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005082 return 0;
dea31012005-04-17 16:05:31 -05005083 }
5084
5085 cnt = 0;
5086 /* If this FARP command is searching for my portname */
5087 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005088 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005089 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005090 cnt = 1;
5091 }
5092
5093 /* If this FARP command is searching for my nodename */
5094 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005095 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005096 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005097 cnt = 1;
5098 }
5099
5100 if (cnt) {
5101 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5102 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5103 /* Log back into the node before sending the FARP. */
5104 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005105 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005106 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005107 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005108 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005109 }
5110
5111 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005112 if (fp->Rflags & FARP_REQUEST_FARPR)
5113 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005114 }
5115 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005116 return 0;
dea31012005-04-17 16:05:31 -05005117}
5118
James Smarte59058c2008-08-24 21:49:00 -04005119/**
James Smart3621a712009-04-06 18:47:14 -04005120 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005121 * @vport: pointer to a host virtual N_Port data structure.
5122 * @cmdiocb: pointer to lpfc command iocb data structure.
5123 * @ndlp: pointer to a node-list data structure.
5124 *
5125 * This routine processes Fibre Channel Address Resolution Protocol
5126 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5127 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5128 * the FARP response request.
5129 *
5130 * Return code
5131 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5132 **/
dea31012005-04-17 16:05:31 -05005133static int
James Smart2e0fef82007-06-17 19:56:36 -05005134lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5135 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005136{
5137 struct lpfc_dmabuf *pcmd;
5138 uint32_t *lp;
5139 IOCB_t *icmd;
5140 uint32_t cmd, did;
5141
5142 icmd = &cmdiocb->iocb;
5143 did = icmd->un.elsreq64.remoteID;
5144 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5145 lp = (uint32_t *) pcmd->virt;
5146
5147 cmd = *lp++;
5148 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005149 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5150 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005151 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005152 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005153
5154 return 0;
5155}
5156
James Smarte59058c2008-08-24 21:49:00 -04005157/**
James Smart3621a712009-04-06 18:47:14 -04005158 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005159 * @vport: pointer to a host virtual N_Port data structure.
5160 * @cmdiocb: pointer to lpfc command iocb data structure.
5161 * @fan_ndlp: pointer to a node-list data structure.
5162 *
5163 * This routine processes a Fabric Address Notification (FAN) IOCB
5164 * command received as an ELS unsolicited event. The FAN ELS command will
5165 * only be processed on a physical port (i.e., the @vport represents the
5166 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5167 * compared against those in the phba data structure. If any of those is
5168 * different, the lpfc_initial_flogi() routine is invoked to initialize
5169 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5170 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5171 * is invoked to register login to the fabric.
5172 *
5173 * Return code
5174 * 0 - Successfully processed fan iocb (currently always return 0).
5175 **/
dea31012005-04-17 16:05:31 -05005176static int
James Smart2e0fef82007-06-17 19:56:36 -05005177lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5178 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005179{
James Smart2e0fef82007-06-17 19:56:36 -05005180 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005181 uint32_t *lp;
5182 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005183
James Smart0d2b6b82008-06-14 22:52:47 -04005184 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5185 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5186 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005187 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005188 if ((vport == phba->pport) &&
5189 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005190 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005191 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005192 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005193 sizeof(struct lpfc_name)))) {
5194 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05005195 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005196 } else {
5197 /* FAN verified - skip FLOGI */
5198 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005199 if (phba->sli_rev < LPFC_SLI_REV4)
5200 lpfc_issue_fabric_reglogin(vport);
5201 else
5202 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005203 }
dea31012005-04-17 16:05:31 -05005204 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005205 return 0;
dea31012005-04-17 16:05:31 -05005206}
5207
James Smarte59058c2008-08-24 21:49:00 -04005208/**
James Smart3621a712009-04-06 18:47:14 -04005209 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005210 * @ptr: holder for the timer function associated data.
5211 *
5212 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5213 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5214 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5215 * up the worker thread. It is for the worker thread to invoke the routine
5216 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5217 **/
dea31012005-04-17 16:05:31 -05005218void
5219lpfc_els_timeout(unsigned long ptr)
5220{
James Smart2e0fef82007-06-17 19:56:36 -05005221 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5222 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005223 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005224 unsigned long iflag;
5225
James Smart2e0fef82007-06-17 19:56:36 -05005226 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005227 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5228 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005229 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005230 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005231
James Smart5e9d9b82008-06-14 22:52:53 -04005232 if (!tmo_posted)
5233 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005234 return;
5235}
5236
James Smart2a9bf3d2010-06-07 15:24:45 -04005237
James Smarte59058c2008-08-24 21:49:00 -04005238/**
James Smart3621a712009-04-06 18:47:14 -04005239 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005240 * @vport: pointer to a virtual N_Port data structure.
5241 *
5242 * This routine is the actual handler function that processes an ELS timeout
5243 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5244 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5245 * invoking the lpfc_sli_issue_abort_iotag() routine.
5246 **/
dea31012005-04-17 16:05:31 -05005247void
James Smart2e0fef82007-06-17 19:56:36 -05005248lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005249{
James Smart2e0fef82007-06-17 19:56:36 -05005250 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005251 struct lpfc_sli_ring *pring;
5252 struct lpfc_iocbq *tmp_iocb, *piocb;
5253 IOCB_t *cmd = NULL;
5254 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005255 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005256 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005257 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005258 LIST_HEAD(txcmplq_completions);
5259 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005260
James Smart2a9bf3d2010-06-07 15:24:45 -04005261
dea31012005-04-17 16:05:31 -05005262 timeout = (uint32_t)(phba->fc_ratov << 1);
5263
5264 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005265
James Smart2a9bf3d2010-06-07 15:24:45 -04005266 spin_lock_irq(&phba->hbalock);
5267 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5268 spin_unlock_irq(&phba->hbalock);
5269
5270 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005271 cmd = &piocb->iocb;
5272
James Smart2e0fef82007-06-17 19:56:36 -05005273 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5274 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5275 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005276 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005277
5278 if (piocb->vport != vport)
5279 continue;
5280
dea31012005-04-17 16:05:31 -05005281 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005282 if (pcmd)
5283 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005284
James Smart92d7f7b2007-06-17 19:56:38 -05005285 if (els_command == ELS_CMD_FARP ||
5286 els_command == ELS_CMD_FARPR ||
5287 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005288 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005289
dea31012005-04-17 16:05:31 -05005290 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005291 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005292 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005293 else
dea31012005-04-17 16:05:31 -05005294 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005295 continue;
5296 }
5297
James Smart2e0fef82007-06-17 19:56:36 -05005298 remote_ID = 0xffffffff;
5299 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005300 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005301 else {
5302 struct lpfc_nodelist *ndlp;
5303 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005304 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005305 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005306 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005307 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05005308 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005309 spin_lock_irq(&phba->hbalock);
5310 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05005311 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005312
James Smart2a9bf3d2010-06-07 15:24:45 -04005313 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5314 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5315 "0127 ELS timeout Data: x%x x%x x%x "
5316 "x%x\n", els_command,
5317 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5318 spin_lock_irq(&phba->hbalock);
5319 list_del_init(&piocb->dlist);
5320 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5321 spin_unlock_irq(&phba->hbalock);
5322 }
5323
James Smart2e0fef82007-06-17 19:56:36 -05005324 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5325 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005326}
5327
James Smarte59058c2008-08-24 21:49:00 -04005328/**
James Smart3621a712009-04-06 18:47:14 -04005329 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005330 * @vport: pointer to a host virtual N_Port data structure.
5331 *
5332 * This routine is used to clean up all the outstanding ELS commands on a
5333 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5334 * routine. After that, it walks the ELS transmit queue to remove all the
5335 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5336 * the IOCBs with a non-NULL completion callback function, the callback
5337 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5338 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5339 * callback function, the IOCB will simply be released. Finally, it walks
5340 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5341 * completion queue IOCB that is associated with the @vport and is not
5342 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5343 * part of the discovery state machine) out to HBA by invoking the
5344 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5345 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5346 * the IOCBs are aborted when this function returns.
5347 **/
dea31012005-04-17 16:05:31 -05005348void
James Smart2e0fef82007-06-17 19:56:36 -05005349lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005350{
James Smart2534ba72007-04-25 09:52:20 -04005351 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005352 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005353 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005354 struct lpfc_iocbq *tmp_iocb, *piocb;
5355 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005356
5357 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005358
James Smart2e0fef82007-06-17 19:56:36 -05005359 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005360 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5361 cmd = &piocb->iocb;
5362
5363 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5364 continue;
5365 }
5366
5367 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005368 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5369 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5370 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5371 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005372 continue;
dea31012005-04-17 16:05:31 -05005373
James Smart2e0fef82007-06-17 19:56:36 -05005374 if (piocb->vport != vport)
5375 continue;
5376
James Smart2534ba72007-04-25 09:52:20 -04005377 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005378 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005379 }
5380
5381 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005382 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5383 continue;
5384 }
dea31012005-04-17 16:05:31 -05005385
James Smart2e0fef82007-06-17 19:56:36 -05005386 if (piocb->vport != vport)
5387 continue;
5388
James Smart07951072007-04-25 09:51:38 -04005389 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005390 }
James Smart2e0fef82007-06-17 19:56:36 -05005391 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005392
James Smarta257bf92009-04-06 18:48:10 -04005393 /* Cancell all the IOCBs from the completions list */
5394 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5395 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005396
dea31012005-04-17 16:05:31 -05005397 return;
5398}
5399
James Smarte59058c2008-08-24 21:49:00 -04005400/**
James Smart3621a712009-04-06 18:47:14 -04005401 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005402 * @phba: pointer to lpfc hba data structure.
5403 *
5404 * This routine is used to clean up all the outstanding ELS commands on a
5405 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5406 * routine. After that, it walks the ELS transmit queue to remove all the
5407 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5408 * the IOCBs with the completion callback function associated, the callback
5409 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5410 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5411 * callback function associated, the IOCB will simply be released. Finally,
5412 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5413 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5414 * management plane IOCBs that are not part of the discovery state machine)
5415 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5416 **/
James Smart549e55c2007-08-02 11:09:51 -04005417void
5418lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5419{
5420 LIST_HEAD(completions);
5421 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5422 struct lpfc_iocbq *tmp_iocb, *piocb;
5423 IOCB_t *cmd = NULL;
5424
5425 lpfc_fabric_abort_hba(phba);
5426 spin_lock_irq(&phba->hbalock);
5427 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5428 cmd = &piocb->iocb;
5429 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5430 continue;
5431 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5432 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5433 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5434 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5435 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5436 continue;
5437 list_move_tail(&piocb->list, &completions);
5438 pring->txq_cnt--;
5439 }
5440 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5441 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5442 continue;
5443 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5444 }
5445 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005446
5447 /* Cancel all the IOCBs from the completions list */
5448 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5449 IOERR_SLI_ABORTED);
5450
James Smart549e55c2007-08-02 11:09:51 -04005451 return;
5452}
5453
James Smarte59058c2008-08-24 21:49:00 -04005454/**
James Smart3621a712009-04-06 18:47:14 -04005455 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005456 * @phba: Pointer to hba context object.
5457 * @cmdiocbp: Pointer to command iocb which reported error.
5458 * @rspiocbp: Pointer to response iocb which reported error.
5459 *
5460 * This function sends an event when there is an ELS command
5461 * failure.
5462 **/
5463void
5464lpfc_send_els_failure_event(struct lpfc_hba *phba,
5465 struct lpfc_iocbq *cmdiocbp,
5466 struct lpfc_iocbq *rspiocbp)
5467{
5468 struct lpfc_vport *vport = cmdiocbp->vport;
5469 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5470 struct lpfc_lsrjt_event lsrjt_event;
5471 struct lpfc_fabric_event_header fabric_event;
5472 struct ls_rjt stat;
5473 struct lpfc_nodelist *ndlp;
5474 uint32_t *pcmd;
5475
5476 ndlp = cmdiocbp->context1;
5477 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5478 return;
5479
5480 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5481 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5482 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5483 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5484 sizeof(struct lpfc_name));
5485 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5486 sizeof(struct lpfc_name));
5487 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5488 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04005489 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04005490 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5491 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5492 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5493 fc_host_post_vendor_event(shost,
5494 fc_get_event_number(),
5495 sizeof(lsrjt_event),
5496 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005497 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005498 return;
5499 }
5500 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5501 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5502 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5503 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5504 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5505 else
5506 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5507 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5508 sizeof(struct lpfc_name));
5509 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5510 sizeof(struct lpfc_name));
5511 fc_host_post_vendor_event(shost,
5512 fc_get_event_number(),
5513 sizeof(fabric_event),
5514 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005515 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005516 return;
5517 }
5518
5519}
5520
5521/**
James Smart3621a712009-04-06 18:47:14 -04005522 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04005523 * @vport: Pointer to vport object.
5524 * @ndlp: Pointer FC node object.
5525 * @cmd: ELS command code.
5526 *
5527 * This function posts an event when there is an incoming
5528 * unsolicited ELS command.
5529 **/
5530static void
5531lpfc_send_els_event(struct lpfc_vport *vport,
5532 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005533 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005534{
James Smartddcc50f2008-12-04 22:38:46 -05005535 struct lpfc_els_event_header *els_data = NULL;
5536 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005537 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5538
James Smartddcc50f2008-12-04 22:38:46 -05005539 if (*payload == ELS_CMD_LOGO) {
5540 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5541 if (!logo_data) {
5542 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5543 "0148 Failed to allocate memory "
5544 "for LOGO event\n");
5545 return;
5546 }
5547 els_data = &logo_data->header;
5548 } else {
5549 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5550 GFP_KERNEL);
5551 if (!els_data) {
5552 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5553 "0149 Failed to allocate memory "
5554 "for ELS event\n");
5555 return;
5556 }
5557 }
5558 els_data->event_type = FC_REG_ELS_EVENT;
5559 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005560 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005561 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005562 break;
5563 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005564 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005565 break;
5566 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005567 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5568 break;
5569 case ELS_CMD_LOGO:
5570 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5571 /* Copy the WWPN in the LOGO payload */
5572 memcpy(logo_data->logo_wwpn, &payload[2],
5573 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005574 break;
5575 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005576 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005577 return;
5578 }
James Smartddcc50f2008-12-04 22:38:46 -05005579 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5580 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5581 if (*payload == ELS_CMD_LOGO) {
5582 fc_host_post_vendor_event(shost,
5583 fc_get_event_number(),
5584 sizeof(struct lpfc_logo_event),
5585 (char *)logo_data,
5586 LPFC_NL_VENDOR_ID);
5587 kfree(logo_data);
5588 } else {
5589 fc_host_post_vendor_event(shost,
5590 fc_get_event_number(),
5591 sizeof(struct lpfc_els_event_header),
5592 (char *)els_data,
5593 LPFC_NL_VENDOR_ID);
5594 kfree(els_data);
5595 }
James Smartea2151b2008-09-07 11:52:10 -04005596
5597 return;
5598}
5599
5600
5601/**
James Smart3621a712009-04-06 18:47:14 -04005602 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04005603 * @phba: pointer to lpfc hba data structure.
5604 * @pring: pointer to a SLI ring.
5605 * @vport: pointer to a host virtual N_Port data structure.
5606 * @elsiocb: pointer to lpfc els command iocb data structure.
5607 *
5608 * This routine is used for processing the IOCB associated with a unsolicited
5609 * event. It first determines whether there is an existing ndlp that matches
5610 * the DID from the unsolicited IOCB. If not, it will create a new one with
5611 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5612 * IOCB is then used to invoke the proper routine and to set up proper state
5613 * of the discovery state machine.
5614 **/
James Smarted957682007-06-17 19:56:37 -05005615static void
5616lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005617 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005618{
James Smart87af33f2007-10-27 13:37:43 -04005619 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005620 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005621 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005622 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005623 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005624 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005625
James Smarte47c9092008-02-08 18:49:26 -05005626 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005627 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005628
dea31012005-04-17 16:05:31 -05005629 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005630 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5631 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005632 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005633 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005634
James Smart858c9f62007-06-17 19:56:39 -05005635 did = icmd->un.rcvels.remoteID;
5636 if (icmd->ulpStatus) {
5637 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5638 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5639 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005640 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005641 }
dea31012005-04-17 16:05:31 -05005642
5643 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005644 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005645 goto dropit;
dea31012005-04-17 16:05:31 -05005646
James Smartc8685952009-11-18 15:39:16 -05005647 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05005648 if (vport->load_flag & FC_UNLOADING)
5649 goto dropit;
5650
James Smart2e0fef82007-06-17 19:56:36 -05005651 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005652 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005653 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005654 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005655 if (!ndlp)
dea31012005-04-17 16:05:31 -05005656 goto dropit;
dea31012005-04-17 16:05:31 -05005657
James Smart2e0fef82007-06-17 19:56:36 -05005658 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005659 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005660 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005661 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005662 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005663 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5664 ndlp = lpfc_enable_node(vport, ndlp,
5665 NLP_STE_UNUSED_NODE);
5666 if (!ndlp)
5667 goto dropit;
5668 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5669 newnode = 1;
5670 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5671 ndlp->nlp_type |= NLP_FABRIC;
5672 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5673 /* This is similar to the new node path */
5674 ndlp = lpfc_nlp_get(ndlp);
5675 if (!ndlp)
5676 goto dropit;
5677 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5678 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005679 }
dea31012005-04-17 16:05:31 -05005680
5681 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005682
James Smart329f9bc2007-04-25 09:53:01 -04005683 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005684 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005685
5686 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5687 cmd &= ELS_CMD_MASK;
5688 }
5689 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005690 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5691 "0112 ELS command x%x received from NPORT x%x "
5692 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005693 switch (cmd) {
5694 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005695 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5696 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5697 did, vport->port_state, ndlp->nlp_flag);
5698
dea31012005-04-17 16:05:31 -05005699 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005700 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5701
James Smartddcc50f2008-12-04 22:38:46 -05005702 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05005703 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05005704 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5705 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5706 rjt_err = LSRJT_UNABLE_TPC;
5707 break;
5708 }
5709 /* We get here, and drop thru, if we are PT2PT with
5710 * another NPort and the other side has initiated
5711 * the PLOGI before responding to our FLOGI.
5712 */
dea31012005-04-17 16:05:31 -05005713 }
James Smart87af33f2007-10-27 13:37:43 -04005714
5715 shost = lpfc_shost_from_vport(vport);
5716 spin_lock_irq(shost->host_lock);
5717 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5718 spin_unlock_irq(shost->host_lock);
5719
James Smart2e0fef82007-06-17 19:56:36 -05005720 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5721 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05005722
dea31012005-04-17 16:05:31 -05005723 break;
5724 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005725 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5726 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5727 did, vport->port_state, ndlp->nlp_flag);
5728
dea31012005-04-17 16:05:31 -05005729 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04005730 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005731 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005732 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005733 break;
5734 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05005735 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5736 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5737 did, vport->port_state, ndlp->nlp_flag);
5738
dea31012005-04-17 16:05:31 -05005739 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05005740 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005741 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005742 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005743 break;
5744 }
James Smart2e0fef82007-06-17 19:56:36 -05005745 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05005746 break;
5747 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05005748 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5749 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5750 did, vport->port_state, ndlp->nlp_flag);
5751
dea31012005-04-17 16:05:31 -05005752 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05005753 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005754 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005755 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005756 break;
5757 }
James Smart2e0fef82007-06-17 19:56:36 -05005758 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05005759 break;
5760 case ELS_CMD_RSCN:
5761 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04005762 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005763 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005764 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005765 break;
5766 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05005767 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5768 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5769 did, vport->port_state, ndlp->nlp_flag);
5770
James Smartddcc50f2008-12-04 22:38:46 -05005771 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05005772 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005773 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005774 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005775 break;
5776 }
James Smart2e0fef82007-06-17 19:56:36 -05005777 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5778 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05005779 break;
5780 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05005781 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5782 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5783 did, vport->port_state, ndlp->nlp_flag);
5784
dea31012005-04-17 16:05:31 -05005785 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005786 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005787 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005788 break;
5789 }
James Smart2e0fef82007-06-17 19:56:36 -05005790 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5791 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05005792 break;
5793 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05005794 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5795 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5796 did, vport->port_state, ndlp->nlp_flag);
5797
dea31012005-04-17 16:05:31 -05005798 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05005799 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005800 break;
5801 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05005802 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5803 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5804 did, vport->port_state, ndlp->nlp_flag);
5805
dea31012005-04-17 16:05:31 -05005806 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05005807 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005808 break;
5809 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05005810 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5811 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5812 did, vport->port_state, ndlp->nlp_flag);
5813
dea31012005-04-17 16:05:31 -05005814 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05005815 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005816 break;
dea31012005-04-17 16:05:31 -05005817 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05005818 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5819 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5820 did, vport->port_state, ndlp->nlp_flag);
5821
dea31012005-04-17 16:05:31 -05005822 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05005823 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005824 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005825 break;
5826 }
James Smart2e0fef82007-06-17 19:56:36 -05005827 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05005828 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005829 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05005830 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5831 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5832 did, vport->port_state, ndlp->nlp_flag);
5833
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005834 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05005835 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005836 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005837 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005838 break;
5839 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05005840 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5841 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5842 did, vport->port_state, ndlp->nlp_flag);
5843
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005844 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05005845 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005846 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005847 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005848 break;
5849 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05005850 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5851 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5852 did, vport->port_state, ndlp->nlp_flag);
5853
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005854 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05005855 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005856 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005857 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005858 break;
dea31012005-04-17 16:05:31 -05005859 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05005860 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5861 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5862 did, vport->port_state, ndlp->nlp_flag);
5863
dea31012005-04-17 16:05:31 -05005864 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05005865 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005866 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005867 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005868 break;
James Smart5ffc2662009-11-18 15:39:44 -05005869 case ELS_CMD_RRQ:
5870 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5871 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
5872 did, vport->port_state, ndlp->nlp_flag);
5873
5874 phba->fc_stat.elsRcvRRQ++;
5875 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
5876 if (newnode)
5877 lpfc_nlp_put(ndlp);
5878 break;
dea31012005-04-17 16:05:31 -05005879 default:
James Smart858c9f62007-06-17 19:56:39 -05005880 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5881 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5882 cmd, did, vport->port_state);
5883
dea31012005-04-17 16:05:31 -05005884 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05005885 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05005886
5887 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005888 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5889 "0115 Unknown ELS command x%x "
5890 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04005891 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005892 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005893 break;
5894 }
5895
5896 /* check if need to LS_RJT received ELS cmd */
5897 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05005898 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05005899 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04005900 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05005901 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5902 NULL);
dea31012005-04-17 16:05:31 -05005903 }
5904
James Smartd7c255b2008-08-24 21:50:00 -04005905 lpfc_nlp_put(elsiocb->context1);
5906 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05005907 return;
5908
5909dropit:
James Smart98c9ea52007-10-27 13:37:33 -04005910 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04005911 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5912 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05005913 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04005914 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05005915 phba->fc_stat.elsRcvDrop++;
5916}
5917
James Smarte59058c2008-08-24 21:49:00 -04005918/**
James Smart3621a712009-04-06 18:47:14 -04005919 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04005920 * @phba: pointer to lpfc hba data structure.
5921 * @vpi: host virtual N_Port identifier.
5922 *
5923 * This routine finds a vport on a HBA (referred by @phba) through a
5924 * @vpi. The function walks the HBA's vport list and returns the address
5925 * of the vport with the matching @vpi.
5926 *
5927 * Return code
5928 * NULL - No vport with the matching @vpi found
5929 * Otherwise - Address to the vport with the matching @vpi.
5930 **/
James Smart6669f9b2009-10-02 15:16:45 -04005931struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05005932lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5933{
5934 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04005935 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05005936
James Smart549e55c2007-08-02 11:09:51 -04005937 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005938 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04005939 if (vport->vpi == vpi) {
5940 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005941 return vport;
James Smart549e55c2007-08-02 11:09:51 -04005942 }
James Smart92d7f7b2007-06-17 19:56:38 -05005943 }
James Smart549e55c2007-08-02 11:09:51 -04005944 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005945 return NULL;
5946}
James Smarted957682007-06-17 19:56:37 -05005947
James Smarte59058c2008-08-24 21:49:00 -04005948/**
James Smart3621a712009-04-06 18:47:14 -04005949 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04005950 * @phba: pointer to lpfc hba data structure.
5951 * @pring: pointer to a SLI ring.
5952 * @elsiocb: pointer to lpfc els iocb data structure.
5953 *
5954 * This routine is used to process an unsolicited event received from a SLI
5955 * (Service Level Interface) ring. The actual processing of the data buffer
5956 * associated with the unsolicited event is done by invoking the routine
5957 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5958 * SLI ring on which the unsolicited event was received.
5959 **/
James Smarted957682007-06-17 19:56:37 -05005960void
5961lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5962 struct lpfc_iocbq *elsiocb)
5963{
5964 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05005965 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05005966 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05005967 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5968 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05005969
James Smartd7c255b2008-08-24 21:50:00 -04005970 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005971 elsiocb->context2 = NULL;
5972 elsiocb->context3 = NULL;
5973
5974 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5975 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5976 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5977 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05005978 phba->fc_stat.NoRcvBuf++;
5979 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05005980 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04005981 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05005982 return;
5983 }
5984
James Smart92d7f7b2007-06-17 19:56:38 -05005985 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5986 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5987 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5988 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5989 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04005990 else
5991 vport = lpfc_find_vport_by_vpid(phba,
5992 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05005993 }
James Smart7f5f3d02008-02-08 18:50:14 -05005994 /* If there are no BDEs associated
5995 * with this IOCB, there is nothing to do.
5996 */
James Smarted957682007-06-17 19:56:37 -05005997 if (icmd->ulpBdeCount == 0)
5998 return;
5999
James Smart7f5f3d02008-02-08 18:50:14 -05006000 /* type of ELS cmd is first 32bit word
6001 * in packet
6002 */
James Smarted957682007-06-17 19:56:37 -05006003 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006004 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006005 } else {
6006 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6007 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006008 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6009 paddr);
James Smarted957682007-06-17 19:56:37 -05006010 }
6011
James Smart92d7f7b2007-06-17 19:56:38 -05006012 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6013 /*
6014 * The different unsolicited event handlers would tell us
6015 * if they are done with "mp" by setting context2 to NULL.
6016 */
dea31012005-04-17 16:05:31 -05006017 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006018 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6019 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006020 }
James Smarted957682007-06-17 19:56:37 -05006021
6022 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006023 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006024 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006025 elsiocb->context2 = bdeBuf2;
6026 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006027 /* free mp if we are done with it */
6028 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006029 lpfc_in_buf_free(phba, elsiocb->context2);
6030 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006031 }
dea31012005-04-17 16:05:31 -05006032 }
dea31012005-04-17 16:05:31 -05006033}
James Smart92d7f7b2007-06-17 19:56:38 -05006034
James Smarte59058c2008-08-24 21:49:00 -04006035/**
James Smart3621a712009-04-06 18:47:14 -04006036 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006037 * @phba: pointer to lpfc hba data structure.
6038 * @vport: pointer to a virtual N_Port data structure.
6039 *
6040 * This routine issues a Port Login (PLOGI) to the Name Server with
6041 * State Change Request (SCR) for a @vport. This routine will create an
6042 * ndlp for the Name Server associated to the @vport if such node does
6043 * not already exist. The PLOGI to Name Server is issued by invoking the
6044 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6045 * (FDMI) is configured to the @vport, a FDMI node will be created and
6046 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6047 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006048void
6049lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6050{
6051 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
6052
6053 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6054 if (!ndlp) {
6055 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6056 if (!ndlp) {
6057 if (phba->fc_topology == TOPOLOGY_LOOP) {
6058 lpfc_disc_start(vport);
6059 return;
6060 }
6061 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006062 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6063 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006064 return;
6065 }
6066 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006067 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6068 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6069 if (!ndlp) {
6070 if (phba->fc_topology == TOPOLOGY_LOOP) {
6071 lpfc_disc_start(vport);
6072 return;
6073 }
6074 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6075 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6076 "0348 NameServer login: node freed\n");
6077 return;
6078 }
James Smart92d7f7b2007-06-17 19:56:38 -05006079 }
James Smart58da1ff2008-04-07 10:15:56 -04006080 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006081
6082 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6083
6084 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6085 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006086 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6087 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006088 return;
6089 }
6090
James Smart3de2a652007-08-02 11:09:59 -04006091 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05006092 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6093 GFP_KERNEL);
6094 if (ndlp_fdmi) {
6095 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6096 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006097 lpfc_nlp_set_state(vport, ndlp_fdmi,
6098 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05006099 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
6100 0);
6101 }
6102 }
6103 return;
6104}
6105
James Smarte59058c2008-08-24 21:49:00 -04006106/**
James Smart3621a712009-04-06 18:47:14 -04006107 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006108 * @phba: pointer to lpfc hba data structure.
6109 * @pmb: pointer to the driver internal queue element for mailbox command.
6110 *
6111 * This routine is the completion callback function to register new vport
6112 * mailbox command. If the new vport mailbox command completes successfully,
6113 * the fabric registration login shall be performed on physical port (the
6114 * new vport created is actually a physical port, with VPI 0) or the port
6115 * login to Name Server for State Change Request (SCR) will be performed
6116 * on virtual port (real virtual port, with VPI greater than 0).
6117 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006118static void
6119lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6120{
6121 struct lpfc_vport *vport = pmb->vport;
6122 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6123 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006124 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006125 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006126
James Smart09372822008-01-11 01:52:54 -05006127 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006128 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006129 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006130
6131 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006132 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006133 "0915 Register VPI failed : Status: x%x"
6134 " upd bit: x%x \n", mb->mbxStatus,
6135 mb->un.varRegVpi.upd);
6136 if (phba->sli_rev == LPFC_SLI_REV4 &&
6137 mb->un.varRegVpi.upd)
6138 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006139
6140 switch (mb->mbxStatus) {
6141 case 0x11: /* unsupported feature */
6142 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006143 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006144 /* giving up on vport registration */
6145 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6146 spin_lock_irq(shost->host_lock);
6147 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6148 spin_unlock_irq(shost->host_lock);
6149 lpfc_can_disctmo(vport);
6150 break;
James Smart695a8142010-01-26 23:08:03 -05006151 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6152 case 0x20:
6153 spin_lock_irq(shost->host_lock);
6154 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6155 spin_unlock_irq(shost->host_lock);
6156 lpfc_init_vpi(phba, pmb, vport->vpi);
6157 pmb->vport = vport;
6158 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6159 rc = lpfc_sli_issue_mbox(phba, pmb,
6160 MBX_NOWAIT);
6161 if (rc == MBX_NOT_FINISHED) {
6162 lpfc_printf_vlog(vport,
6163 KERN_ERR, LOG_MBOX,
6164 "2732 Failed to issue INIT_VPI"
6165 " mailbox command\n");
6166 } else {
6167 lpfc_nlp_put(ndlp);
6168 return;
6169 }
6170
James Smart92d7f7b2007-06-17 19:56:38 -05006171 default:
6172 /* Try to recover from this error */
6173 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006174 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006175 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006176 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006177 if (vport->port_type == LPFC_PHYSICAL_PORT
6178 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart7f5f3d02008-02-08 18:50:14 -05006179 lpfc_initial_flogi(vport);
6180 else
6181 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006182 break;
6183 }
James Smart92d7f7b2007-06-17 19:56:38 -05006184 } else {
James Smart695a8142010-01-26 23:08:03 -05006185 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006186 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006187 spin_unlock_irq(shost->host_lock);
6188 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006189 if (phba->sli_rev < LPFC_SLI_REV4)
6190 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006191 else {
James Smartfc2b9892010-02-26 14:15:29 -05006192 /*
6193 * If the physical port is instantiated using
6194 * FDISC, do not start vport discovery.
6195 */
6196 if (vport->port_state != LPFC_FDISC)
6197 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006198 lpfc_do_scr_ns_plogi(phba, vport);
6199 }
6200 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006201 lpfc_do_scr_ns_plogi(phba, vport);
6202 }
James Smart38b92ef2010-08-04 16:11:39 -04006203mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05006204 /* Now, we decrement the ndlp reference count held for this
6205 * callback function
6206 */
6207 lpfc_nlp_put(ndlp);
6208
James Smart92d7f7b2007-06-17 19:56:38 -05006209 mempool_free(pmb, phba->mbox_mem_pool);
6210 return;
6211}
6212
James Smarte59058c2008-08-24 21:49:00 -04006213/**
James Smart3621a712009-04-06 18:47:14 -04006214 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006215 * @phba: pointer to lpfc hba data structure.
6216 * @vport: pointer to a host virtual N_Port data structure.
6217 * @ndlp: pointer to a node-list data structure.
6218 *
6219 * This routine registers the @vport as a new virtual port with a HBA.
6220 * It is done through a registering vpi mailbox command.
6221 **/
James Smart695a8142010-01-26 23:08:03 -05006222void
James Smart92d7f7b2007-06-17 19:56:38 -05006223lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6224 struct lpfc_nodelist *ndlp)
6225{
James Smart09372822008-01-11 01:52:54 -05006226 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006227 LPFC_MBOXQ_t *mbox;
6228
6229 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6230 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006231 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006232 mbox->vport = vport;
6233 mbox->context2 = lpfc_nlp_get(ndlp);
6234 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006235 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006236 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006237 /* mailbox command not success, decrement ndlp
6238 * reference count for this command
6239 */
6240 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006241 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006242
James Smarte8b62012007-08-02 11:10:09 -04006243 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6244 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006245 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006246 }
6247 } else {
James Smarte8b62012007-08-02 11:10:09 -04006248 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6249 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006250 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006251 }
James Smartfa4066b2008-01-11 01:53:27 -05006252 return;
6253
6254mbox_err_exit:
6255 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6256 spin_lock_irq(shost->host_lock);
6257 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6258 spin_unlock_irq(shost->host_lock);
6259 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006260}
6261
James Smarte59058c2008-08-24 21:49:00 -04006262/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006263 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006264 * @phba: pointer to lpfc hba data structure.
6265 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006266 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006267 **/
6268void
James Smart0c9ab6f2010-02-26 14:15:57 -05006269lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006270{
6271 struct lpfc_vport **vports;
6272 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006273 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006274 int i;
James Smart695a8142010-01-26 23:08:03 -05006275
6276 /* Treat this failure as linkdown for all vports */
6277 link_state = phba->link_state;
6278 lpfc_linkdown(phba);
6279 phba->link_state = link_state;
6280
6281 vports = lpfc_create_vport_work_array(phba);
6282
6283 if (vports) {
6284 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6285 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6286 if (ndlp)
6287 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6288 lpfc_els_flush_cmd(vports[i]);
6289 }
6290 lpfc_destroy_vport_work_array(phba, vports);
6291 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006292}
6293
6294/**
6295 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6296 * @phba: pointer to lpfc hba data structure.
6297 *
6298 * This routine abort all pending discovery commands and
6299 * start a timer to retry FLOGI for the physical port
6300 * discovery.
6301 **/
6302void
6303lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6304{
6305 struct lpfc_nodelist *ndlp;
6306 struct Scsi_Host *shost;
6307
6308 /* Cancel the all vports retry delay retry timers */
6309 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05006310
6311 /* If fabric require FLOGI, then re-instantiate physical login */
6312 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6313 if (!ndlp)
6314 return;
6315
James Smart695a8142010-01-26 23:08:03 -05006316 shost = lpfc_shost_from_vport(phba->pport);
6317 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6318 spin_lock_irq(shost->host_lock);
6319 ndlp->nlp_flag |= NLP_DELAY_TMO;
6320 spin_unlock_irq(shost->host_lock);
6321 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6322 phba->pport->port_state = LPFC_FLOGI;
6323 return;
6324}
6325
6326/**
6327 * lpfc_fabric_login_reqd - Check if FLOGI required.
6328 * @phba: pointer to lpfc hba data structure.
6329 * @cmdiocb: pointer to FDISC command iocb.
6330 * @rspiocb: pointer to FDISC response iocb.
6331 *
6332 * This routine checks if a FLOGI is reguired for FDISC
6333 * to succeed.
6334 **/
6335static int
6336lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6337 struct lpfc_iocbq *cmdiocb,
6338 struct lpfc_iocbq *rspiocb)
6339{
6340
6341 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6342 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6343 return 0;
6344 else
6345 return 1;
6346}
6347
6348/**
James Smart3621a712009-04-06 18:47:14 -04006349 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006350 * @phba: pointer to lpfc hba data structure.
6351 * @cmdiocb: pointer to lpfc command iocb data structure.
6352 * @rspiocb: pointer to lpfc response iocb data structure.
6353 *
6354 * This routine is the completion callback function to a Fabric Discover
6355 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6356 * single threaded, each FDISC completion callback function will reset
6357 * the discovery timer for all vports such that the timers will not get
6358 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6359 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6360 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6361 * assigned to the vport has been changed with the completion of the FDISC
6362 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6363 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6364 * routine is invoked to register new vport with the HBA. Otherwise, the
6365 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6366 * Server for State Change Request (SCR).
6367 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006368static void
6369lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6370 struct lpfc_iocbq *rspiocb)
6371{
6372 struct lpfc_vport *vport = cmdiocb->vport;
6373 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6374 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6375 struct lpfc_nodelist *np;
6376 struct lpfc_nodelist *next_np;
6377 IOCB_t *irsp = &rspiocb->iocb;
6378 struct lpfc_iocbq *piocb;
6379
James Smarte8b62012007-08-02 11:10:09 -04006380 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6381 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6382 irsp->ulpStatus, irsp->un.ulpWord[4],
6383 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05006384 /* Since all FDISCs are being single threaded, we
6385 * must reset the discovery timer for ALL vports
6386 * waiting to send FDISC when one completes.
6387 */
6388 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6389 lpfc_set_disctmo(piocb->vport);
6390 }
6391
James Smart858c9f62007-06-17 19:56:39 -05006392 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6393 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6394 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6395
James Smart92d7f7b2007-06-17 19:56:38 -05006396 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05006397
6398 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6399 lpfc_retry_pport_discovery(phba);
6400 goto out;
6401 }
6402
James Smart92d7f7b2007-06-17 19:56:38 -05006403 /* Check for retry */
6404 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6405 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006406 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04006407 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04006408 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04006409 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04006410 goto fdisc_failed;
6411 }
James Smartd7c255b2008-08-24 21:50:00 -04006412 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05006413 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04006414 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04006415 vport->fc_flag |= FC_FABRIC;
6416 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6417 vport->fc_flag |= FC_PUBLIC_LOOP;
6418 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006419
James Smartd7c255b2008-08-24 21:50:00 -04006420 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6421 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6422 if ((vport->fc_prevDID != vport->fc_myDID) &&
6423 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6424 /* If our NportID changed, we need to ensure all
6425 * remaining NPORTs get unreg_login'ed so we can
6426 * issue unreg_vpi.
6427 */
6428 list_for_each_entry_safe(np, next_np,
6429 &vport->fc_nodes, nlp_listp) {
6430 if (!NLP_CHK_NODE_ACT(ndlp) ||
6431 (np->nlp_state != NLP_STE_NPR_NODE) ||
6432 !(np->nlp_flag & NLP_NPR_ADISC))
6433 continue;
James Smart09372822008-01-11 01:52:54 -05006434 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006435 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05006436 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006437 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05006438 }
James Smart78730cf2010-04-06 15:06:30 -04006439 lpfc_cleanup_pending_mbox(vport);
James Smartd7c255b2008-08-24 21:50:00 -04006440 lpfc_mbx_unreg_vpi(vport);
6441 spin_lock_irq(shost->host_lock);
6442 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05006443 if (phba->sli_rev == LPFC_SLI_REV4)
6444 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04006445 else
6446 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04006447 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04006448 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
6449 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6450 /*
6451 * Driver needs to re-reg VPI in order for f/w
6452 * to update the MAC address.
6453 */
6454 lpfc_register_new_vport(phba, vport, ndlp);
6455 return ;
James Smart92d7f7b2007-06-17 19:56:38 -05006456 }
6457
James Smartecfd03c2010-02-12 14:41:27 -05006458 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6459 lpfc_issue_init_vpi(vport);
6460 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04006461 lpfc_register_new_vport(phba, vport, ndlp);
6462 else
6463 lpfc_do_scr_ns_plogi(phba, vport);
6464 goto out;
6465fdisc_failed:
6466 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6467 /* Cancel discovery timer */
6468 lpfc_can_disctmo(vport);
6469 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006470out:
6471 lpfc_els_free_iocb(phba, cmdiocb);
6472}
6473
James Smarte59058c2008-08-24 21:49:00 -04006474/**
James Smart3621a712009-04-06 18:47:14 -04006475 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006476 * @vport: pointer to a virtual N_Port data structure.
6477 * @ndlp: pointer to a node-list data structure.
6478 * @retry: number of retries to the command IOCB.
6479 *
6480 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6481 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6482 * routine to issue the IOCB, which makes sure only one outstanding fabric
6483 * IOCB will be sent off HBA at any given time.
6484 *
6485 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6486 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6487 * will be stored into the context1 field of the IOCB for the completion
6488 * callback function to the FDISC ELS command.
6489 *
6490 * Return code
6491 * 0 - Successfully issued fdisc iocb command
6492 * 1 - Failed to issue fdisc iocb command
6493 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006494static int
James Smart92d7f7b2007-06-17 19:56:38 -05006495lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6496 uint8_t retry)
6497{
6498 struct lpfc_hba *phba = vport->phba;
6499 IOCB_t *icmd;
6500 struct lpfc_iocbq *elsiocb;
6501 struct serv_parm *sp;
6502 uint8_t *pcmd;
6503 uint16_t cmdsize;
6504 int did = ndlp->nlp_DID;
6505 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006506
James Smart5ffc2662009-11-18 15:39:44 -05006507 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05006508 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6509 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6510 ELS_CMD_FDISC);
6511 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006512 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006513 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6514 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006515 return 1;
6516 }
6517
6518 icmd = &elsiocb->iocb;
6519 icmd->un.elsreq64.myID = 0;
6520 icmd->un.elsreq64.fl = 1;
6521
James Smartf1126682009-06-10 17:22:44 -04006522 if (phba->sli_rev == LPFC_SLI_REV4) {
6523 /* FDISC needs to be 1 for WQE VPI */
6524 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6525 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6526 /* Set the ulpContext to the vpi */
6527 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6528 } else {
6529 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6530 icmd->ulpCt_h = 1;
6531 icmd->ulpCt_l = 0;
6532 }
James Smart92d7f7b2007-06-17 19:56:38 -05006533
6534 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6535 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6536 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6537 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6538 sp = (struct serv_parm *) pcmd;
6539 /* Setup CSPs accordingly for Fabric */
6540 sp->cmn.e_d_tov = 0;
6541 sp->cmn.w2.r_a_tov = 0;
6542 sp->cls1.classValid = 0;
6543 sp->cls2.seqDelivery = 1;
6544 sp->cls3.seqDelivery = 1;
6545
6546 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6547 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6548 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6549 pcmd += sizeof(uint32_t); /* Port Name */
6550 memcpy(pcmd, &vport->fc_portname, 8);
6551 pcmd += sizeof(uint32_t); /* Node Name */
6552 pcmd += sizeof(uint32_t); /* Node Name */
6553 memcpy(pcmd, &vport->fc_nodename, 8);
6554
6555 lpfc_set_disctmo(vport);
6556
6557 phba->fc_stat.elsXmitFDISC++;
6558 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6559
James Smart858c9f62007-06-17 19:56:39 -05006560 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6561 "Issue FDISC: did:x%x",
6562 did, 0, 0);
6563
James Smart92d7f7b2007-06-17 19:56:38 -05006564 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6565 if (rc == IOCB_ERROR) {
6566 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006567 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006568 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6569 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006570 return 1;
6571 }
6572 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05006573 return 0;
6574}
6575
James Smarte59058c2008-08-24 21:49:00 -04006576/**
James Smart3621a712009-04-06 18:47:14 -04006577 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04006578 * @phba: pointer to lpfc hba data structure.
6579 * @cmdiocb: pointer to lpfc command iocb data structure.
6580 * @rspiocb: pointer to lpfc response iocb data structure.
6581 *
6582 * This routine is the completion callback function to the issuing of a LOGO
6583 * ELS command off a vport. It frees the command IOCB and then decrement the
6584 * reference count held on ndlp for this completion function, indicating that
6585 * the reference to the ndlp is no long needed. Note that the
6586 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6587 * callback function and an additional explicit ndlp reference decrementation
6588 * will trigger the actual release of the ndlp.
6589 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006590static void
6591lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6592 struct lpfc_iocbq *rspiocb)
6593{
6594 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006595 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006596 struct lpfc_nodelist *ndlp;
6597 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006598
6599 irsp = &rspiocb->iocb;
6600 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6601 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6602 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006603
6604 lpfc_els_free_iocb(phba, cmdiocb);
6605 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006606
6607 /* Trigger the release of the ndlp after logo */
6608 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006609}
6610
James Smarte59058c2008-08-24 21:49:00 -04006611/**
James Smart3621a712009-04-06 18:47:14 -04006612 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04006613 * @vport: pointer to a virtual N_Port data structure.
6614 * @ndlp: pointer to a node-list data structure.
6615 *
6616 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6617 *
6618 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6619 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6620 * will be stored into the context1 field of the IOCB for the completion
6621 * callback function to the LOGO ELS command.
6622 *
6623 * Return codes
6624 * 0 - Successfully issued logo off the @vport
6625 * 1 - Failed to issue logo off the @vport
6626 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006627int
6628lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6629{
6630 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6631 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006632 IOCB_t *icmd;
6633 struct lpfc_iocbq *elsiocb;
6634 uint8_t *pcmd;
6635 uint16_t cmdsize;
6636
6637 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6638 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6639 ELS_CMD_LOGO);
6640 if (!elsiocb)
6641 return 1;
6642
6643 icmd = &elsiocb->iocb;
6644 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6645 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6646 pcmd += sizeof(uint32_t);
6647
6648 /* Fill in LOGO payload */
6649 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6650 pcmd += sizeof(uint32_t);
6651 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6652
James Smart858c9f62007-06-17 19:56:39 -05006653 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6654 "Issue LOGO npiv did:x%x flg:x%x",
6655 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6656
James Smart92d7f7b2007-06-17 19:56:38 -05006657 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6658 spin_lock_irq(shost->host_lock);
6659 ndlp->nlp_flag |= NLP_LOGO_SND;
6660 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04006661 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6662 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05006663 spin_lock_irq(shost->host_lock);
6664 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6665 spin_unlock_irq(shost->host_lock);
6666 lpfc_els_free_iocb(phba, elsiocb);
6667 return 1;
6668 }
6669 return 0;
6670}
6671
James Smarte59058c2008-08-24 21:49:00 -04006672/**
James Smart3621a712009-04-06 18:47:14 -04006673 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04006674 * @ptr: holder for the timer function associated data.
6675 *
6676 * This routine is invoked by the fabric iocb block timer after
6677 * timeout. It posts the fabric iocb block timeout event by setting the
6678 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6679 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6680 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6681 * posted event WORKER_FABRIC_BLOCK_TMO.
6682 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006683void
6684lpfc_fabric_block_timeout(unsigned long ptr)
6685{
6686 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6687 unsigned long iflags;
6688 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04006689
James Smart92d7f7b2007-06-17 19:56:38 -05006690 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6691 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6692 if (!tmo_posted)
6693 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6694 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6695
James Smart5e9d9b82008-06-14 22:52:53 -04006696 if (!tmo_posted)
6697 lpfc_worker_wake_up(phba);
6698 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006699}
6700
James Smarte59058c2008-08-24 21:49:00 -04006701/**
James Smart3621a712009-04-06 18:47:14 -04006702 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04006703 * @phba: pointer to lpfc hba data structure.
6704 *
6705 * This routine issues one fabric iocb from the driver internal list to
6706 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6707 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6708 * remove one pending fabric iocb from the driver internal list and invokes
6709 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6710 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006711static void
6712lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6713{
6714 struct lpfc_iocbq *iocb;
6715 unsigned long iflags;
6716 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05006717 IOCB_t *cmd;
6718
6719repeat:
6720 iocb = NULL;
6721 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05006722 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05006723 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6724 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6725 list);
6726 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05006727 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05006728 atomic_inc(&phba->fabric_iocb_count);
6729 }
6730 spin_unlock_irqrestore(&phba->hbalock, iflags);
6731 if (iocb) {
6732 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6733 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6734 iocb->iocb_flag |= LPFC_IO_FABRIC;
6735
James Smart858c9f62007-06-17 19:56:39 -05006736 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6737 "Fabric sched1: ste:x%x",
6738 iocb->vport->port_state, 0, 0);
6739
James Smart3772a992009-05-22 14:50:54 -04006740 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006741
6742 if (ret == IOCB_ERROR) {
6743 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6744 iocb->fabric_iocb_cmpl = NULL;
6745 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6746 cmd = &iocb->iocb;
6747 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6748 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6749 iocb->iocb_cmpl(phba, iocb, iocb);
6750
6751 atomic_dec(&phba->fabric_iocb_count);
6752 goto repeat;
6753 }
6754 }
6755
6756 return;
6757}
6758
James Smarte59058c2008-08-24 21:49:00 -04006759/**
James Smart3621a712009-04-06 18:47:14 -04006760 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006761 * @phba: pointer to lpfc hba data structure.
6762 *
6763 * This routine unblocks the issuing fabric iocb command. The function
6764 * will clear the fabric iocb block bit and then invoke the routine
6765 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6766 * from the driver internal fabric iocb list.
6767 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006768void
6769lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6770{
6771 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6772
6773 lpfc_resume_fabric_iocbs(phba);
6774 return;
6775}
6776
James Smarte59058c2008-08-24 21:49:00 -04006777/**
James Smart3621a712009-04-06 18:47:14 -04006778 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006779 * @phba: pointer to lpfc hba data structure.
6780 *
6781 * This routine blocks the issuing fabric iocb for a specified amount of
6782 * time (currently 100 ms). This is done by set the fabric iocb block bit
6783 * and set up a timeout timer for 100ms. When the block bit is set, no more
6784 * fabric iocb will be issued out of the HBA.
6785 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006786static void
6787lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6788{
6789 int blocked;
6790
6791 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05006792 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05006793 if (!blocked)
6794 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6795
6796 return;
6797}
6798
James Smarte59058c2008-08-24 21:49:00 -04006799/**
James Smart3621a712009-04-06 18:47:14 -04006800 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04006801 * @phba: pointer to lpfc hba data structure.
6802 * @cmdiocb: pointer to lpfc command iocb data structure.
6803 * @rspiocb: pointer to lpfc response iocb data structure.
6804 *
6805 * This routine is the callback function that is put to the fabric iocb's
6806 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6807 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6808 * function first restores and invokes the original iocb's callback function
6809 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6810 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6811 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006812static void
6813lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6814 struct lpfc_iocbq *rspiocb)
6815{
6816 struct ls_rjt stat;
6817
6818 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6819 BUG();
6820
6821 switch (rspiocb->iocb.ulpStatus) {
6822 case IOSTAT_NPORT_RJT:
6823 case IOSTAT_FABRIC_RJT:
6824 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6825 lpfc_block_fabric_iocbs(phba);
6826 }
6827 break;
6828
6829 case IOSTAT_NPORT_BSY:
6830 case IOSTAT_FABRIC_BSY:
6831 lpfc_block_fabric_iocbs(phba);
6832 break;
6833
6834 case IOSTAT_LS_RJT:
6835 stat.un.lsRjtError =
6836 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6837 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6838 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6839 lpfc_block_fabric_iocbs(phba);
6840 break;
6841 }
6842
6843 if (atomic_read(&phba->fabric_iocb_count) == 0)
6844 BUG();
6845
6846 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6847 cmdiocb->fabric_iocb_cmpl = NULL;
6848 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6849 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6850
6851 atomic_dec(&phba->fabric_iocb_count);
6852 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05006853 /* Post any pending iocbs to HBA */
6854 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05006855 }
6856}
6857
James Smarte59058c2008-08-24 21:49:00 -04006858/**
James Smart3621a712009-04-06 18:47:14 -04006859 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006860 * @phba: pointer to lpfc hba data structure.
6861 * @iocb: pointer to lpfc command iocb data structure.
6862 *
6863 * This routine is used as the top-level API for issuing a fabric iocb command
6864 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6865 * function makes sure that only one fabric bound iocb will be outstanding at
6866 * any given time. As such, this function will first check to see whether there
6867 * is already an outstanding fabric iocb on the wire. If so, it will put the
6868 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6869 * issued later. Otherwise, it will issue the iocb on the wire and update the
6870 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6871 *
6872 * Note, this implementation has a potential sending out fabric IOCBs out of
6873 * order. The problem is caused by the construction of the "ready" boolen does
6874 * not include the condition that the internal fabric IOCB list is empty. As
6875 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6876 * ahead of the fabric IOCBs in the internal list.
6877 *
6878 * Return code
6879 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6880 * IOCB_ERROR - failed to issue fabric iocb
6881 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006882static int
James Smart92d7f7b2007-06-17 19:56:38 -05006883lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6884{
6885 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05006886 int ready;
6887 int ret;
6888
6889 if (atomic_read(&phba->fabric_iocb_count) > 1)
6890 BUG();
6891
6892 spin_lock_irqsave(&phba->hbalock, iflags);
6893 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6894 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6895
James Smart7f5f3d02008-02-08 18:50:14 -05006896 if (ready)
6897 /* Increment fabric iocb count to hold the position */
6898 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05006899 spin_unlock_irqrestore(&phba->hbalock, iflags);
6900 if (ready) {
6901 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6902 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6903 iocb->iocb_flag |= LPFC_IO_FABRIC;
6904
James Smart858c9f62007-06-17 19:56:39 -05006905 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6906 "Fabric sched2: ste:x%x",
6907 iocb->vport->port_state, 0, 0);
6908
James Smart3772a992009-05-22 14:50:54 -04006909 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006910
6911 if (ret == IOCB_ERROR) {
6912 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6913 iocb->fabric_iocb_cmpl = NULL;
6914 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6915 atomic_dec(&phba->fabric_iocb_count);
6916 }
6917 } else {
6918 spin_lock_irqsave(&phba->hbalock, iflags);
6919 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6920 spin_unlock_irqrestore(&phba->hbalock, iflags);
6921 ret = IOCB_SUCCESS;
6922 }
6923 return ret;
6924}
6925
James Smarte59058c2008-08-24 21:49:00 -04006926/**
James Smart3621a712009-04-06 18:47:14 -04006927 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006928 * @vport: pointer to a virtual N_Port data structure.
6929 *
6930 * This routine aborts all the IOCBs associated with a @vport from the
6931 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6932 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6933 * list, removes each IOCB associated with the @vport off the list, set the
6934 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6935 * associated with the IOCB.
6936 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006937static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05006938{
6939 LIST_HEAD(completions);
6940 struct lpfc_hba *phba = vport->phba;
6941 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05006942
6943 spin_lock_irq(&phba->hbalock);
6944 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6945 list) {
6946
6947 if (piocb->vport != vport)
6948 continue;
6949
6950 list_move_tail(&piocb->list, &completions);
6951 }
6952 spin_unlock_irq(&phba->hbalock);
6953
James Smarta257bf92009-04-06 18:48:10 -04006954 /* Cancel all the IOCBs from the completions list */
6955 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6956 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006957}
6958
James Smarte59058c2008-08-24 21:49:00 -04006959/**
James Smart3621a712009-04-06 18:47:14 -04006960 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006961 * @ndlp: pointer to a node-list data structure.
6962 *
6963 * This routine aborts all the IOCBs associated with an @ndlp from the
6964 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6965 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6966 * list, removes each IOCB associated with the @ndlp off the list, set the
6967 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6968 * associated with the IOCB.
6969 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006970void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6971{
6972 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04006973 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006974 struct lpfc_iocbq *tmp_iocb, *piocb;
6975 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05006976
6977 spin_lock_irq(&phba->hbalock);
6978 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6979 list) {
6980 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6981
6982 list_move_tail(&piocb->list, &completions);
6983 }
6984 }
6985 spin_unlock_irq(&phba->hbalock);
6986
James Smarta257bf92009-04-06 18:48:10 -04006987 /* Cancel all the IOCBs from the completions list */
6988 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6989 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006990}
6991
James Smarte59058c2008-08-24 21:49:00 -04006992/**
James Smart3621a712009-04-06 18:47:14 -04006993 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006994 * @phba: pointer to lpfc hba data structure.
6995 *
6996 * This routine aborts all the IOCBs currently on the driver internal
6997 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6998 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6999 * list, removes IOCBs off the list, set the status feild to
7000 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7001 * the IOCB.
7002 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007003void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7004{
7005 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007006
7007 spin_lock_irq(&phba->hbalock);
7008 list_splice_init(&phba->fabric_iocb_list, &completions);
7009 spin_unlock_irq(&phba->hbalock);
7010
James Smarta257bf92009-04-06 18:48:10 -04007011 /* Cancel all the IOCBs from the completions list */
7012 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7013 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007014}
James Smart6fb120a2009-05-22 14:52:59 -04007015
7016/**
7017 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7018 * @phba: pointer to lpfc hba data structure.
7019 * @axri: pointer to the els xri abort wcqe structure.
7020 *
7021 * This routine is invoked by the worker thread to process a SLI4 slow-path
7022 * ELS aborted xri.
7023 **/
7024void
7025lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7026 struct sli4_wcqe_xri_aborted *axri)
7027{
7028 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
7029 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7030 unsigned long iflag = 0;
James Smart589a52d2010-07-14 15:30:54 -04007031 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007032
James Smart0f65ff62010-02-26 14:14:23 -05007033 spin_lock_irqsave(&phba->hbalock, iflag);
7034 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007035 list_for_each_entry_safe(sglq_entry, sglq_next,
7036 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7037 if (sglq_entry->sli4_xritag == xri) {
7038 list_del(&sglq_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04007039 list_add_tail(&sglq_entry->list,
7040 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007041 sglq_entry->state = SGL_FREED;
7042 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007043 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart589a52d2010-07-14 15:30:54 -04007044
7045 /* Check if TXQ queue needs to be serviced */
7046 if (pring->txq_cnt)
7047 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007048 return;
7049 }
7050 }
James Smart0f65ff62010-02-26 14:14:23 -05007051 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7052 sglq_entry = __lpfc_get_active_sglq(phba, xri);
7053 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7054 spin_unlock_irqrestore(&phba->hbalock, iflag);
7055 return;
7056 }
7057 sglq_entry->state = SGL_XRI_ABORTED;
7058 spin_unlock_irqrestore(&phba->hbalock, iflag);
7059 return;
James Smart6fb120a2009-05-22 14:52:59 -04007060}