blob: 2aabaf9c4053adfb98c9e20f3126dbc6a5c40006 [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>
24#include <linux/interrupt.h>
25
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040026#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050027#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h>
29#include <scsi/scsi_transport_fc.h>
30
James Smartda0436e2009-05-22 14:51:39 -040031#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050032#include "lpfc_hw.h"
33#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040034#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040035#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050036#include "lpfc_disc.h"
37#include "lpfc_scsi.h"
38#include "lpfc.h"
39#include "lpfc_logmsg.h"
40#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050041#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050042#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050043
44static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
45 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050046static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
47 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010048static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
49static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
50 struct lpfc_nodelist *ndlp, uint8_t retry);
51static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
52 struct lpfc_iocbq *iocb);
53static void lpfc_register_new_vport(struct lpfc_hba *phba,
54 struct lpfc_vport *vport,
55 struct lpfc_nodelist *ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -050056
dea31012005-04-17 16:05:31 -050057static int lpfc_max_els_tries = 3;
58
James Smarte59058c2008-08-24 21:49:00 -040059/**
James Smart3621a712009-04-06 18:47:14 -040060 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040061 * @vport: pointer to a host virtual N_Port data structure.
62 *
63 * This routine checks whether there is an outstanding host link
64 * attention event during the discovery process with the @vport. It is done
65 * by reading the HBA's Host Attention (HA) register. If there is any host
66 * link attention events during this @vport's discovery process, the @vport
67 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
68 * be issued if the link state is not already in host link cleared state,
69 * and a return code shall indicate whether the host link attention event
70 * had happened.
71 *
72 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
73 * state in LPFC_VPORT_READY, the request for checking host link attention
74 * event will be ignored and a return code shall indicate no host link
75 * attention event had happened.
76 *
77 * Return codes
78 * 0 - no host link attention event happened
79 * 1 - host link attention event happened
80 **/
James Smart858c9f62007-06-17 19:56:39 -050081int
James Smart2e0fef82007-06-17 19:56:36 -050082lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050083{
James Smart2e0fef82007-06-17 19:56:36 -050084 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
85 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050086 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050087
James Smart2e0fef82007-06-17 19:56:36 -050088 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040089 phba->link_state == LPFC_LINK_DOWN ||
90 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050091 return 0;
92
93 /* Read the HBA Host Attention Register */
dea31012005-04-17 16:05:31 -050094 ha_copy = readl(phba->HAregaddr);
dea31012005-04-17 16:05:31 -050095
96 if (!(ha_copy & HA_LATT))
97 return 0;
98
99 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -0400100 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
101 "0237 Pending Link Event during "
102 "Discovery: State x%x\n",
103 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500104
105 /* CLEAR_LA should re-enable link attention events and
106 * we should then imediately take a LATT event. The
107 * LATT processing should call lpfc_linkdown() which
108 * will cleanup any left over in-progress discovery
109 * events.
110 */
James Smart2e0fef82007-06-17 19:56:36 -0500111 spin_lock_irq(shost->host_lock);
112 vport->fc_flag |= FC_ABORT_DISCOVERY;
113 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500114
James Smart92d7f7b2007-06-17 19:56:38 -0500115 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500116 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500117
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500118 return 1;
dea31012005-04-17 16:05:31 -0500119}
120
James Smarte59058c2008-08-24 21:49:00 -0400121/**
James Smart3621a712009-04-06 18:47:14 -0400122 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400123 * @vport: pointer to a host virtual N_Port data structure.
124 * @expectRsp: flag indicating whether response is expected.
125 * @cmdSize: size of the ELS command.
126 * @retry: number of retries to the command IOCB when it fails.
127 * @ndlp: pointer to a node-list data structure.
128 * @did: destination identifier.
129 * @elscmd: the ELS command code.
130 *
131 * This routine is used for allocating a lpfc-IOCB data structure from
132 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
133 * passed into the routine for discovery state machine to issue an Extended
134 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
135 * and preparation routine that is used by all the discovery state machine
136 * routines and the ELS command-specific fields will be later set up by
137 * the individual discovery machine routines after calling this routine
138 * allocating and preparing a generic IOCB data structure. It fills in the
139 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
140 * payload and response payload (if expected). The reference count on the
141 * ndlp is incremented by 1 and the reference to the ndlp is put into
142 * context1 of the IOCB data structure for this IOCB to hold the ndlp
143 * reference for the command's callback function to access later.
144 *
145 * Return code
146 * Pointer to the newly allocated/prepared els iocb data structure
147 * NULL - when els iocb data structure allocation/preparation failed
148 **/
dea31012005-04-17 16:05:31 -0500149static struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500150lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
151 uint16_t cmdSize, uint8_t retry,
152 struct lpfc_nodelist *ndlp, uint32_t did,
153 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500154{
James Smart2e0fef82007-06-17 19:56:36 -0500155 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400156 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500157 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
158 struct ulp_bde64 *bpl;
159 IOCB_t *icmd;
160
dea31012005-04-17 16:05:31 -0500161
James Smart2e0fef82007-06-17 19:56:36 -0500162 if (!lpfc_is_link_up(phba))
163 return NULL;
dea31012005-04-17 16:05:31 -0500164
dea31012005-04-17 16:05:31 -0500165 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400166 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500167
168 if (elsiocb == NULL)
169 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500170
dea31012005-04-17 16:05:31 -0500171 icmd = &elsiocb->iocb;
172
173 /* fill in BDEs for command */
174 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400175 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
176 if (pcmd)
177 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500178 if (!pcmd || !pcmd->virt)
179 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500180
181 INIT_LIST_HEAD(&pcmd->list);
182
183 /* Allocate buffer for response payload */
184 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500185 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500186 if (prsp)
187 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
188 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500189 if (!prsp || !prsp->virt)
190 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500191 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500192 } else
dea31012005-04-17 16:05:31 -0500193 prsp = NULL;
dea31012005-04-17 16:05:31 -0500194
195 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500196 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500197 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500198 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
199 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500200 if (!pbuflist || !pbuflist->virt)
201 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500202
203 INIT_LIST_HEAD(&pbuflist->list);
204
205 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
206 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400207 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart2e0fef82007-06-17 19:56:36 -0500208 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500209 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500210 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500211 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400212 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500213 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500214 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500215 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
216 }
dea31012005-04-17 16:05:31 -0500217 icmd->ulpBdeCount = 1;
218 icmd->ulpLe = 1;
219 icmd->ulpClass = CLASS3;
220
James Smart92d7f7b2007-06-17 19:56:38 -0500221 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
222 icmd->un.elsreq64.myID = vport->fc_myDID;
223
224 /* For ELS_REQUEST64_CR, use the VPI by default */
James Smartda0436e2009-05-22 14:51:39 -0400225 icmd->ulpContext = vport->vpi + phba->vpi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500226 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500227 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
228 if (elscmd == ELS_CMD_ECHO)
229 icmd->ulpCt_l = 0; /* context = invalid RPI */
230 else
231 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500232 }
233
dea31012005-04-17 16:05:31 -0500234 bpl = (struct ulp_bde64 *) pbuflist->virt;
235 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
236 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
237 bpl->tus.f.bdeSize = cmdSize;
238 bpl->tus.f.bdeFlags = 0;
239 bpl->tus.w = le32_to_cpu(bpl->tus.w);
240
241 if (expectRsp) {
242 bpl++;
243 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
244 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
245 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400246 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500247 bpl->tus.w = le32_to_cpu(bpl->tus.w);
248 }
249
James Smartfa4066b2008-01-11 01:53:27 -0500250 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400251 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500252 if (!elsiocb->context1)
253 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400254 elsiocb->context2 = pcmd;
255 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500256 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500257 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500258 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
259
260 if (prsp) {
261 list_add(&prsp->list, &pcmd->list);
262 }
dea31012005-04-17 16:05:31 -0500263 if (expectRsp) {
264 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400265 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
266 "0116 Xmit ELS command x%x to remote "
267 "NPORT x%x I/O tag: x%x, port state: x%x\n",
268 elscmd, did, elsiocb->iotag,
269 vport->port_state);
dea31012005-04-17 16:05:31 -0500270 } else {
271 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400272 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
273 "0117 Xmit ELS response x%x to remote "
274 "NPORT x%x I/O tag: x%x, size: x%x\n",
275 elscmd, ndlp->nlp_DID, elsiocb->iotag,
276 cmdSize);
dea31012005-04-17 16:05:31 -0500277 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500278 return elsiocb;
dea31012005-04-17 16:05:31 -0500279
James Smartfa4066b2008-01-11 01:53:27 -0500280els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500281 if (expectRsp)
282 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500283 kfree(pbuflist);
284
285els_iocb_free_prsp_exit:
286 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
287 kfree(prsp);
288
289els_iocb_free_pcmb_exit:
290 kfree(pcmd);
291 lpfc_sli_release_iocbq(phba, elsiocb);
292 return NULL;
293}
dea31012005-04-17 16:05:31 -0500294
James Smarte59058c2008-08-24 21:49:00 -0400295/**
James Smart3621a712009-04-06 18:47:14 -0400296 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400297 * @vport: pointer to a host virtual N_Port data structure.
298 *
299 * This routine issues a fabric registration login for a @vport. An
300 * active ndlp node with Fabric_DID must already exist for this @vport.
301 * The routine invokes two mailbox commands to carry out fabric registration
302 * login through the HBA firmware: the first mailbox command requests the
303 * HBA to perform link configuration for the @vport; and the second mailbox
304 * command requests the HBA to perform the actual fabric registration login
305 * with the @vport.
306 *
307 * Return code
308 * 0 - successfully issued fabric registration login for @vport
309 * -ENXIO -- failed to issue fabric registration login for @vport
310 **/
James Smart3772a992009-05-22 14:50:54 -0400311int
James Smart92d7f7b2007-06-17 19:56:38 -0500312lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
313{
314 struct lpfc_hba *phba = vport->phba;
315 LPFC_MBOXQ_t *mbox;
316 struct lpfc_dmabuf *mp;
317 struct lpfc_nodelist *ndlp;
318 struct serv_parm *sp;
319 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400320 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500321
322 sp = &phba->fc_fabparam;
323 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500324 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400325 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500326 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400327 }
James Smart92d7f7b2007-06-17 19:56:38 -0500328
329 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400330 if (!mbox) {
331 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500332 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400333 }
James Smart92d7f7b2007-06-17 19:56:38 -0500334
335 vport->port_state = LPFC_FABRIC_CFG_LINK;
336 lpfc_config_link(phba, mbox);
337 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
338 mbox->vport = vport;
339
James Smart0b727fe2007-10-27 13:37:25 -0400340 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400341 if (rc == MBX_NOT_FINISHED) {
342 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500343 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400344 }
James Smart92d7f7b2007-06-17 19:56:38 -0500345
346 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400347 if (!mbox) {
348 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500349 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400350 }
James Smart3772a992009-05-22 14:50:54 -0400351 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0);
James Smart98c9ea52007-10-27 13:37:33 -0400352 if (rc) {
353 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500354 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400355 }
James Smart92d7f7b2007-06-17 19:56:38 -0500356
357 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
358 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500359 /* increment the reference count on ndlp to hold reference
360 * for the callback routine.
361 */
James Smart92d7f7b2007-06-17 19:56:38 -0500362 mbox->context2 = lpfc_nlp_get(ndlp);
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 = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500367 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400368 }
James Smart92d7f7b2007-06-17 19:56:38 -0500369
370 return 0;
371
372fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500373 /* decrement the reference count on ndlp just incremented
374 * for the failed mbox command.
375 */
James Smart92d7f7b2007-06-17 19:56:38 -0500376 lpfc_nlp_put(ndlp);
377 mp = (struct lpfc_dmabuf *) mbox->context1;
378 lpfc_mbuf_free(phba, mp->virt, mp->phys);
379 kfree(mp);
380fail_free_mbox:
381 mempool_free(mbox, phba->mbox_mem_pool);
382
383fail:
384 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400385 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400386 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500387 return -ENXIO;
388}
389
James Smarte59058c2008-08-24 21:49:00 -0400390/**
James Smart6fb120a2009-05-22 14:52:59 -0400391 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
392 * @vport: pointer to a host virtual N_Port data structure.
393 *
394 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
395 * the @vport. This mailbox command is necessary for FCoE only.
396 *
397 * Return code
398 * 0 - successfully issued REG_VFI for @vport
399 * A failure code otherwise.
400 **/
401static int
402lpfc_issue_reg_vfi(struct lpfc_vport *vport)
403{
404 struct lpfc_hba *phba = vport->phba;
405 LPFC_MBOXQ_t *mboxq;
406 struct lpfc_nodelist *ndlp;
407 struct serv_parm *sp;
408 struct lpfc_dmabuf *dmabuf;
409 int rc = 0;
410
411 sp = &phba->fc_fabparam;
412 ndlp = lpfc_findnode_did(vport, Fabric_DID);
413 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
414 rc = -ENODEV;
415 goto fail;
416 }
417
418 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
419 if (!dmabuf) {
420 rc = -ENOMEM;
421 goto fail;
422 }
423 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
424 if (!dmabuf->virt) {
425 rc = -ENOMEM;
426 goto fail_free_dmabuf;
427 }
428 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
429 if (!mboxq) {
430 rc = -ENOMEM;
431 goto fail_free_coherent;
432 }
433 vport->port_state = LPFC_FABRIC_CFG_LINK;
434 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
435 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
436 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
437 mboxq->vport = vport;
438 mboxq->context1 = dmabuf;
439 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
440 if (rc == MBX_NOT_FINISHED) {
441 rc = -ENXIO;
442 goto fail_free_mbox;
443 }
444 return 0;
445
446fail_free_mbox:
447 mempool_free(mboxq, phba->mbox_mem_pool);
448fail_free_coherent:
449 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
450fail_free_dmabuf:
451 kfree(dmabuf);
452fail:
453 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
454 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
455 "0289 Issue Register VFI failed: Err %d\n", rc);
456 return rc;
457}
458
459/**
James Smart3621a712009-04-06 18:47:14 -0400460 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400461 * @vport: pointer to a host virtual N_Port data structure.
462 * @ndlp: pointer to a node-list data structure.
463 * @sp: pointer to service parameter data structure.
464 * @irsp: pointer to the IOCB within the lpfc response IOCB.
465 *
466 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
467 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
468 * port in a fabric topology. It properly sets up the parameters to the @ndlp
469 * from the IOCB response. It also check the newly assigned N_Port ID to the
470 * @vport against the previously assigned N_Port ID. If it is different from
471 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
472 * is invoked on all the remaining nodes with the @vport to unregister the
473 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
474 * is invoked to register login to the fabric.
475 *
476 * Return code
477 * 0 - Success (currently, always return 0)
478 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500479static int
James Smart2e0fef82007-06-17 19:56:36 -0500480lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
481 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500482{
James Smart2e0fef82007-06-17 19:56:36 -0500483 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
484 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500485 struct lpfc_nodelist *np;
486 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500487
James Smart2e0fef82007-06-17 19:56:36 -0500488 spin_lock_irq(shost->host_lock);
489 vport->fc_flag |= FC_FABRIC;
490 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500491
492 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
493 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
494 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
495
496 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
497
498 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500499 spin_lock_irq(shost->host_lock);
500 vport->fc_flag |= FC_PUBLIC_LOOP;
501 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500502 } else {
503 /*
504 * If we are a N-port connected to a Fabric, fixup sparam's so
505 * logins to devices on remote loops work.
506 */
James Smart2e0fef82007-06-17 19:56:36 -0500507 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500508 }
509
James Smart2e0fef82007-06-17 19:56:36 -0500510 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500511 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500512 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500513 ndlp->nlp_class_sup = 0;
514 if (sp->cls1.classValid)
515 ndlp->nlp_class_sup |= FC_COS_CLASS1;
516 if (sp->cls2.classValid)
517 ndlp->nlp_class_sup |= FC_COS_CLASS2;
518 if (sp->cls3.classValid)
519 ndlp->nlp_class_sup |= FC_COS_CLASS3;
520 if (sp->cls4.classValid)
521 ndlp->nlp_class_sup |= FC_COS_CLASS4;
522 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
523 sp->cmn.bbRcvSizeLsb;
524 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
525
James Smart92d7f7b2007-06-17 19:56:38 -0500526 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
527 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400528 lpfc_printf_vlog(vport, KERN_WARNING,
529 LOG_ELS | LOG_VPORT,
530 "1816 FLOGI NPIV supported, "
531 "response data 0x%x\n",
532 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500533 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500534 } else {
535 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400536 to call reg_vnpid atleast for the physcial host */
537 lpfc_printf_vlog(vport, KERN_WARNING,
538 LOG_ELS | LOG_VPORT,
539 "1817 Fabric does not support NPIV "
540 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500541 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
542 }
543 }
544
545 if ((vport->fc_prevDID != vport->fc_myDID) &&
546 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
547
548 /* If our NportID changed, we need to ensure all
549 * remaining NPORTs get unreg_login'ed.
550 */
551 list_for_each_entry_safe(np, next_np,
552 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400553 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500554 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500555 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
556 !(np->nlp_flag & NLP_NPR_ADISC))
557 continue;
558 spin_lock_irq(shost->host_lock);
559 np->nlp_flag &= ~NLP_NPR_ADISC;
560 spin_unlock_irq(shost->host_lock);
561 lpfc_unreg_rpi(vport, np);
562 }
563 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
564 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500565 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500566 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500567 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500568 }
569 }
570
James Smart6fb120a2009-05-22 14:52:59 -0400571 if (phba->sli_rev < LPFC_SLI_REV4) {
572 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
573 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
574 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
575 lpfc_register_new_vport(phba, vport, ndlp);
576 else
577 lpfc_issue_fabric_reglogin(vport);
578 } else {
579 ndlp->nlp_type |= NLP_FABRIC;
580 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
581 if (vport->vfi_state & LPFC_VFI_REGISTERED) {
582 lpfc_start_fdiscs(phba);
583 lpfc_do_scr_ns_plogi(phba, vport);
584 } else
585 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500586 }
dea31012005-04-17 16:05:31 -0500587 return 0;
dea31012005-04-17 16:05:31 -0500588}
James Smarte59058c2008-08-24 21:49:00 -0400589/**
James Smart3621a712009-04-06 18:47:14 -0400590 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400591 * @vport: pointer to a host virtual N_Port data structure.
592 * @ndlp: pointer to a node-list data structure.
593 * @sp: pointer to service parameter data structure.
594 *
595 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
596 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
597 * in a point-to-point topology. First, the @vport's N_Port Name is compared
598 * with the received N_Port Name: if the @vport's N_Port Name is greater than
599 * the received N_Port Name lexicographically, this node shall assign local
600 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
601 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
602 * this node shall just wait for the remote node to issue PLOGI and assign
603 * N_Port IDs.
604 *
605 * Return code
606 * 0 - Success
607 * -ENXIO - Fail
608 **/
dea31012005-04-17 16:05:31 -0500609static int
James Smart2e0fef82007-06-17 19:56:36 -0500610lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
611 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500612{
James Smart2e0fef82007-06-17 19:56:36 -0500613 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
614 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500615 LPFC_MBOXQ_t *mbox;
616 int rc;
617
James Smart2e0fef82007-06-17 19:56:36 -0500618 spin_lock_irq(shost->host_lock);
619 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
620 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500621
622 phba->fc_edtov = FF_DEF_EDTOV;
623 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500624 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500625 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500626 if (rc >= 0) {
627 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500628 spin_lock_irq(shost->host_lock);
629 vport->fc_flag |= FC_PT2PT_PLOGI;
630 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500631
632 /*
633 * N_Port ID cannot be 0, set our to LocalID the other
634 * side will be RemoteID.
635 */
636
637 /* not equal */
638 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500639 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500640
641 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
642 if (!mbox)
643 goto fail;
644
645 lpfc_config_link(phba, mbox);
646
647 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500648 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400649 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500650 if (rc == MBX_NOT_FINISHED) {
651 mempool_free(mbox, phba->mbox_mem_pool);
652 goto fail;
653 }
James Smarte47c9092008-02-08 18:49:26 -0500654 /* Decrement ndlp reference count indicating that ndlp can be
655 * safely released when other references to it are done.
656 */
James Smart329f9bc2007-04-25 09:53:01 -0400657 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500658
James Smart2e0fef82007-06-17 19:56:36 -0500659 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500660 if (!ndlp) {
661 /*
662 * Cannot find existing Fabric ndlp, so allocate a
663 * new one
664 */
665 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
666 if (!ndlp)
667 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500668 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500669 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
670 ndlp = lpfc_enable_node(vport, ndlp,
671 NLP_STE_UNUSED_NODE);
672 if(!ndlp)
673 goto fail;
dea31012005-04-17 16:05:31 -0500674 }
675
676 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500677 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500678 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500679 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500680 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500681 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
682 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500683 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500684 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500685 } else
686 /* This side will wait for the PLOGI, decrement ndlp reference
687 * count indicating that ndlp can be released when other
688 * references to it are done.
689 */
James Smart329f9bc2007-04-25 09:53:01 -0400690 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500691
James Smart09372822008-01-11 01:52:54 -0500692 /* If we are pt2pt with another NPort, force NPIV off! */
693 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
694
James Smart2e0fef82007-06-17 19:56:36 -0500695 spin_lock_irq(shost->host_lock);
696 vport->fc_flag |= FC_PT2PT;
697 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500698
699 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500700 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500701 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500702fail:
dea31012005-04-17 16:05:31 -0500703 return -ENXIO;
704}
705
James Smarte59058c2008-08-24 21:49:00 -0400706/**
James Smart3621a712009-04-06 18:47:14 -0400707 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400708 * @phba: pointer to lpfc hba data structure.
709 * @cmdiocb: pointer to lpfc command iocb data structure.
710 * @rspiocb: pointer to lpfc response iocb data structure.
711 *
712 * This routine is the top-level completion callback function for issuing
713 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
714 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
715 * retry has been made (either immediately or delayed with lpfc_els_retry()
716 * returning 1), the command IOCB will be released and function returned.
717 * If the retry attempt has been given up (possibly reach the maximum
718 * number of retries), one additional decrement of ndlp reference shall be
719 * invoked before going out after releasing the command IOCB. This will
720 * actually release the remote node (Note, lpfc_els_free_iocb() will also
721 * invoke one decrement of ndlp reference count). If no error reported in
722 * the IOCB status, the command Port ID field is used to determine whether
723 * this is a point-to-point topology or a fabric topology: if the Port ID
724 * field is assigned, it is a fabric topology; otherwise, it is a
725 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
726 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
727 * specific topology completion conditions.
728 **/
dea31012005-04-17 16:05:31 -0500729static void
James Smart329f9bc2007-04-25 09:53:01 -0400730lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
731 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500732{
James Smart2e0fef82007-06-17 19:56:36 -0500733 struct lpfc_vport *vport = cmdiocb->vport;
734 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500735 IOCB_t *irsp = &rspiocb->iocb;
736 struct lpfc_nodelist *ndlp = cmdiocb->context1;
737 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
738 struct serv_parm *sp;
739 int rc;
740
741 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500742 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500743 /* One additional decrement on node reference count to
744 * trigger the release of the node
745 */
James Smart329f9bc2007-04-25 09:53:01 -0400746 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500747 goto out;
748 }
749
James Smart858c9f62007-06-17 19:56:39 -0500750 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
751 "FLOGI cmpl: status:x%x/x%x state:x%x",
752 irsp->ulpStatus, irsp->un.ulpWord[4],
753 vport->port_state);
754
dea31012005-04-17 16:05:31 -0500755 if (irsp->ulpStatus) {
756 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500757 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500758 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500759
dea31012005-04-17 16:05:31 -0500760 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500761 spin_lock_irq(shost->host_lock);
762 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
763 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500764
James Smart329f9bc2007-04-25 09:53:01 -0400765 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500766 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
767 * alpa map would take too long otherwise.
768 */
769 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400770 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500771 }
772
773 /* FLOGI failure */
James Smarte8b62012007-08-02 11:10:09 -0400774 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
775 "0100 FLOGI failure Data: x%x x%x "
776 "x%x\n",
777 irsp->ulpStatus, irsp->un.ulpWord[4],
778 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500779 goto flogifail;
780 }
781
782 /*
783 * The FLogI succeeded. Sync the data for the CPU before
784 * accessing it.
785 */
786 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
787
788 sp = prsp->virt + sizeof(uint32_t);
789
790 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400791 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
792 "0101 FLOGI completes sucessfully "
793 "Data: x%x x%x x%x x%x\n",
794 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
795 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500796
James Smart2e0fef82007-06-17 19:56:36 -0500797 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500798 /*
799 * If Common Service Parameters indicate Nport
800 * we are point to point, if Fport we are Fabric.
801 */
802 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500803 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500804 else
James Smart2e0fef82007-06-17 19:56:36 -0500805 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500806
807 if (!rc)
808 goto out;
809 }
810
811flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400812 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500813
James Smart858c9f62007-06-17 19:56:39 -0500814 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500815 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500816 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500817
818 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500819 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400820 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
821 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
822 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
823 (phba->link_state != LPFC_CLEAR_LA)) {
824 /* If FLOGI failed enable link interrupt. */
825 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500826 }
dea31012005-04-17 16:05:31 -0500827out:
828 lpfc_els_free_iocb(phba, cmdiocb);
829}
830
James Smarte59058c2008-08-24 21:49:00 -0400831/**
James Smart3621a712009-04-06 18:47:14 -0400832 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400833 * @vport: pointer to a host virtual N_Port data structure.
834 * @ndlp: pointer to a node-list data structure.
835 * @retry: number of retries to the command IOCB.
836 *
837 * This routine issues a Fabric Login (FLOGI) Request ELS command
838 * for a @vport. The initiator service parameters are put into the payload
839 * of the FLOGI Request IOCB and the top-level callback function pointer
840 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
841 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
842 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
843 *
844 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
845 * will be incremented by 1 for holding the ndlp and the reference to ndlp
846 * will be stored into the context1 field of the IOCB for the completion
847 * callback function to the FLOGI ELS command.
848 *
849 * Return code
850 * 0 - successfully issued flogi iocb for @vport
851 * 1 - failed to issue flogi iocb for @vport
852 **/
dea31012005-04-17 16:05:31 -0500853static int
James Smart2e0fef82007-06-17 19:56:36 -0500854lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500855 uint8_t retry)
856{
James Smart2e0fef82007-06-17 19:56:36 -0500857 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500858 struct serv_parm *sp;
859 IOCB_t *icmd;
860 struct lpfc_iocbq *elsiocb;
861 struct lpfc_sli_ring *pring;
862 uint8_t *pcmd;
863 uint16_t cmdsize;
864 uint32_t tmo;
865 int rc;
866
867 pring = &phba->sli.ring[LPFC_ELS_RING];
868
James Smart92d7f7b2007-06-17 19:56:38 -0500869 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500870 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
871 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500872
James Smart488d1462006-03-07 15:02:37 -0500873 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500874 return 1;
dea31012005-04-17 16:05:31 -0500875
876 icmd = &elsiocb->iocb;
877 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
878
879 /* For FLOGI request, remainder of payload is service parameters */
880 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500881 pcmd += sizeof(uint32_t);
882 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500883 sp = (struct serv_parm *) pcmd;
884
885 /* Setup CSPs accordingly for Fabric */
886 sp->cmn.e_d_tov = 0;
887 sp->cmn.w2.r_a_tov = 0;
888 sp->cls1.classValid = 0;
889 sp->cls2.seqDelivery = 1;
890 sp->cls3.seqDelivery = 1;
891 if (sp->cmn.fcphLow < FC_PH3)
892 sp->cmn.fcphLow = FC_PH3;
893 if (sp->cmn.fcphHigh < FC_PH3)
894 sp->cmn.fcphHigh = FC_PH3;
895
James Smart6fb120a2009-05-22 14:52:59 -0400896 if (phba->sli_rev == LPFC_SLI_REV4) {
897 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
898 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
899 /* FLOGI needs to be 3 for WQE FCFI */
900 /* Set the fcfi to the fcfi we registered with */
901 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
902 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -0500903 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500904 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
905 icmd->ulpCt_h = 1;
906 icmd->ulpCt_l = 0;
907 }
908
James Smart858c9f62007-06-17 19:56:39 -0500909 if (phba->fc_topology != TOPOLOGY_LOOP) {
910 icmd->un.elsreq64.myID = 0;
911 icmd->un.elsreq64.fl = 1;
912 }
913
dea31012005-04-17 16:05:31 -0500914 tmo = phba->fc_ratov;
915 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500916 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500917 phba->fc_ratov = tmo;
918
919 phba->fc_stat.elsXmitFLOGI++;
920 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -0500921
922 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
923 "Issue FLOGI: opt:x%x",
924 phba->sli3_options, 0, 0);
925
James Smart92d7f7b2007-06-17 19:56:38 -0500926 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500927 if (rc == IOCB_ERROR) {
928 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500929 return 1;
dea31012005-04-17 16:05:31 -0500930 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500931 return 0;
dea31012005-04-17 16:05:31 -0500932}
933
James Smarte59058c2008-08-24 21:49:00 -0400934/**
James Smart3621a712009-04-06 18:47:14 -0400935 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -0400936 * @phba: pointer to lpfc hba data structure.
937 *
938 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
939 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
940 * list and issues an abort IOCB commond on each outstanding IOCB that
941 * contains a active Fabric_DID ndlp. Note that this function is to issue
942 * the abort IOCB command on all the outstanding IOCBs, thus when this
943 * function returns, it does not guarantee all the IOCBs are actually aborted.
944 *
945 * Return code
946 * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0)
947 **/
dea31012005-04-17 16:05:31 -0500948int
James Smart2e0fef82007-06-17 19:56:36 -0500949lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500950{
951 struct lpfc_sli_ring *pring;
952 struct lpfc_iocbq *iocb, *next_iocb;
953 struct lpfc_nodelist *ndlp;
954 IOCB_t *icmd;
955
956 /* Abort outstanding I/O on NPort <nlp_DID> */
957 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400958 "0201 Abort outstanding I/O on NPort x%x\n",
959 Fabric_DID);
dea31012005-04-17 16:05:31 -0500960
961 pring = &phba->sli.ring[LPFC_ELS_RING];
962
963 /*
964 * Check the txcmplq for an iocb that matches the nport the driver is
965 * searching for.
966 */
James Smart2e0fef82007-06-17 19:56:36 -0500967 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500968 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
969 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500970 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
971 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -0500972 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -0400973 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
974 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -0400975 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -0500976 }
977 }
James Smart2e0fef82007-06-17 19:56:36 -0500978 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500979
980 return 0;
981}
982
James Smarte59058c2008-08-24 21:49:00 -0400983/**
James Smart3621a712009-04-06 18:47:14 -0400984 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400985 * @vport: pointer to a host virtual N_Port data structure.
986 *
987 * This routine issues an initial Fabric Login (FLOGI) for the @vport
988 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
989 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
990 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
991 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
992 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
993 * @vport.
994 *
995 * Return code
996 * 0 - failed to issue initial flogi for @vport
997 * 1 - successfully issued initial flogi for @vport
998 **/
dea31012005-04-17 16:05:31 -0500999int
James Smart2e0fef82007-06-17 19:56:36 -05001000lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001001{
James Smart2e0fef82007-06-17 19:56:36 -05001002 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001003 struct lpfc_nodelist *ndlp;
1004
James Smart98c9ea52007-10-27 13:37:33 -04001005 vport->port_state = LPFC_FLOGI;
1006 lpfc_set_disctmo(vport);
1007
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001008 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001009 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001010 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001011 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001012 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1013 if (!ndlp)
1014 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001015 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001016 /* Set the node type */
1017 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001018 /* Put ndlp onto node list */
1019 lpfc_enqueue_node(vport, ndlp);
1020 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1021 /* re-setup ndlp without removing from node list */
1022 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1023 if (!ndlp)
1024 return 0;
dea31012005-04-17 16:05:31 -05001025 }
James Smart87af33f2007-10-27 13:37:43 -04001026
James Smarte47c9092008-02-08 18:49:26 -05001027 if (lpfc_issue_els_flogi(vport, ndlp, 0))
James Smartfa4066b2008-01-11 01:53:27 -05001028 /* This decrement of reference count to node shall kick off
1029 * the release of the node.
1030 */
James Smart329f9bc2007-04-25 09:53:01 -04001031 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001032
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001033 return 1;
dea31012005-04-17 16:05:31 -05001034}
1035
James Smarte59058c2008-08-24 21:49:00 -04001036/**
James Smart3621a712009-04-06 18:47:14 -04001037 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001038 * @vport: pointer to a host virtual N_Port data structure.
1039 *
1040 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1041 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1042 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1043 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1044 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1045 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1046 * @vport.
1047 *
1048 * Return code
1049 * 0 - failed to issue initial fdisc for @vport
1050 * 1 - successfully issued initial fdisc for @vport
1051 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001052int
1053lpfc_initial_fdisc(struct lpfc_vport *vport)
1054{
1055 struct lpfc_hba *phba = vport->phba;
1056 struct lpfc_nodelist *ndlp;
1057
1058 /* First look for the Fabric ndlp */
1059 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1060 if (!ndlp) {
1061 /* Cannot find existing Fabric ndlp, so allocate a new one */
1062 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1063 if (!ndlp)
1064 return 0;
1065 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001066 /* Put ndlp onto node list */
1067 lpfc_enqueue_node(vport, ndlp);
1068 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1069 /* re-setup ndlp without removing from node list */
1070 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1071 if (!ndlp)
1072 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001073 }
James Smarte47c9092008-02-08 18:49:26 -05001074
James Smart92d7f7b2007-06-17 19:56:38 -05001075 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001076 /* decrement node reference count to trigger the release of
1077 * the node.
1078 */
James Smart92d7f7b2007-06-17 19:56:38 -05001079 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001080 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001081 }
1082 return 1;
1083}
James Smart87af33f2007-10-27 13:37:43 -04001084
James Smarte59058c2008-08-24 21:49:00 -04001085/**
James Smart3621a712009-04-06 18:47:14 -04001086 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001087 * @vport: pointer to a host virtual N_Port data structure.
1088 *
1089 * This routine checks whether there are more remaining Port Logins
1090 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1091 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1092 * to issue ELS PLOGIs up to the configured discover threads with the
1093 * @vport (@vport->cfg_discovery_threads). The function also decrement
1094 * the @vport's num_disc_node by 1 if it is not already 0.
1095 **/
James Smart87af33f2007-10-27 13:37:43 -04001096void
James Smart2e0fef82007-06-17 19:56:36 -05001097lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001098{
1099 int sentplogi;
1100
James Smart2e0fef82007-06-17 19:56:36 -05001101 if (vport->num_disc_nodes)
1102 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001103
1104 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001105 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1106 "0232 Continue discovery with %d PLOGIs to go "
1107 "Data: x%x x%x x%x\n",
1108 vport->num_disc_nodes, vport->fc_plogi_cnt,
1109 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001110 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001111 if (vport->fc_flag & FC_NLP_MORE)
1112 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1113 sentplogi = lpfc_els_disc_plogi(vport);
1114
dea31012005-04-17 16:05:31 -05001115 return;
1116}
1117
James Smarte59058c2008-08-24 21:49:00 -04001118/**
James Smart3621a712009-04-06 18:47:14 -04001119 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001120 * @phba: pointer to lpfc hba data structure.
1121 * @prsp: pointer to response IOCB payload.
1122 * @ndlp: pointer to a node-list data structure.
1123 *
1124 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1125 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1126 * The following cases are considered N_Port confirmed:
1127 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1128 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1129 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1130 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1131 * 1) if there is a node on vport list other than the @ndlp with the same
1132 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1133 * on that node to release the RPI associated with the node; 2) if there is
1134 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1135 * into, a new node shall be allocated (or activated). In either case, the
1136 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1137 * be released and the new_ndlp shall be put on to the vport node list and
1138 * its pointer returned as the confirmed node.
1139 *
1140 * Note that before the @ndlp got "released", the keepDID from not-matching
1141 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1142 * of the @ndlp. This is because the release of @ndlp is actually to put it
1143 * into an inactive state on the vport node list and the vport node list
1144 * management algorithm does not allow two node with a same DID.
1145 *
1146 * Return code
1147 * pointer to the PLOGI N_Port @ndlp
1148 **/
James Smart488d1462006-03-07 15:02:37 -05001149static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001150lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001151 struct lpfc_nodelist *ndlp)
1152{
James Smart2e0fef82007-06-17 19:56:36 -05001153 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001154 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001155 struct lpfc_rport_data *rdata;
1156 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001157 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001158 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001159 uint32_t rc, keepDID = 0;
James Smart488d1462006-03-07 15:02:37 -05001160
James Smart2fb9bd82006-12-02 13:33:57 -05001161 /* Fabric nodes can have the same WWPN so we don't bother searching
1162 * by WWPN. Just return the ndlp that was given to us.
1163 */
1164 if (ndlp->nlp_type & NLP_FABRIC)
1165 return ndlp;
1166
James Smart92d7f7b2007-06-17 19:56:38 -05001167 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001168 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001169
James Smart685f0bf2007-04-25 09:53:08 -04001170 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001171 * we have for that ndlp. If not, we have some work to do.
1172 */
James Smart2e0fef82007-06-17 19:56:36 -05001173 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001174
James Smarte47c9092008-02-08 18:49:26 -05001175 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001176 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001177
1178 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001179 rc = memcmp(&ndlp->nlp_portname, name,
1180 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001181 if (!rc)
1182 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001183 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1184 if (!new_ndlp)
1185 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001186 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001187 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001188 rc = memcmp(&ndlp->nlp_portname, name,
1189 sizeof(struct lpfc_name));
1190 if (!rc)
1191 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001192 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1193 NLP_STE_UNUSED_NODE);
1194 if (!new_ndlp)
1195 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001196 keepDID = new_ndlp->nlp_DID;
1197 } else
1198 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001199
James Smart2e0fef82007-06-17 19:56:36 -05001200 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001201 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001202 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001203
1204 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1205 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1206 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1207
James Smarte47c9092008-02-08 18:49:26 -05001208 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001209 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001210
James Smart2e0fef82007-06-17 19:56:36 -05001211 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001212 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1213 /* The new_ndlp is replacing ndlp totally, so we need
1214 * to put ndlp on UNUSED list and try to free it.
1215 */
James Smart0ff10d42008-01-11 01:52:36 -05001216
1217 /* Fix up the rport accordingly */
1218 rport = ndlp->rport;
1219 if (rport) {
1220 rdata = rport->dd_data;
1221 if (rdata->pnode == ndlp) {
1222 lpfc_nlp_put(ndlp);
1223 ndlp->rport = NULL;
1224 rdata->pnode = lpfc_nlp_get(new_ndlp);
1225 new_ndlp->rport = rport;
1226 }
1227 new_ndlp->nlp_type = ndlp->nlp_type;
1228 }
James Smart58da1ff2008-04-07 10:15:56 -04001229 /* We shall actually free the ndlp with both nlp_DID and
1230 * nlp_portname fields equals 0 to avoid any ndlp on the
1231 * nodelist never to be used.
1232 */
1233 if (ndlp->nlp_DID == 0) {
1234 spin_lock_irq(&phba->ndlp_lock);
1235 NLP_SET_FREE_REQ(ndlp);
1236 spin_unlock_irq(&phba->ndlp_lock);
1237 }
James Smart0ff10d42008-01-11 01:52:36 -05001238
James Smart58da1ff2008-04-07 10:15:56 -04001239 /* Two ndlps cannot have the same did on the nodelist */
1240 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001241 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001242 }
James Smart92795652006-07-06 15:50:02 -04001243 else {
James Smart2e0fef82007-06-17 19:56:36 -05001244 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001245 /* Two ndlps cannot have the same did */
1246 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001247 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -04001248 }
James Smart488d1462006-03-07 15:02:37 -05001249 return new_ndlp;
1250}
1251
James Smarte59058c2008-08-24 21:49:00 -04001252/**
James Smart3621a712009-04-06 18:47:14 -04001253 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001254 * @vport: pointer to a host virtual N_Port data structure.
1255 *
1256 * This routine checks whether more Registration State Change
1257 * Notifications (RSCNs) came in while the discovery state machine was in
1258 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1259 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1260 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1261 * handling the RSCNs.
1262 **/
James Smart87af33f2007-10-27 13:37:43 -04001263void
1264lpfc_end_rscn(struct lpfc_vport *vport)
1265{
1266 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1267
1268 if (vport->fc_flag & FC_RSCN_MODE) {
1269 /*
1270 * Check to see if more RSCNs came in while we were
1271 * processing this one.
1272 */
1273 if (vport->fc_rscn_id_cnt ||
1274 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1275 lpfc_els_handle_rscn(vport);
1276 else {
1277 spin_lock_irq(shost->host_lock);
1278 vport->fc_flag &= ~FC_RSCN_MODE;
1279 spin_unlock_irq(shost->host_lock);
1280 }
1281 }
1282}
1283
James Smarte59058c2008-08-24 21:49:00 -04001284/**
James Smart3621a712009-04-06 18:47:14 -04001285 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001286 * @phba: pointer to lpfc hba data structure.
1287 * @cmdiocb: pointer to lpfc command iocb data structure.
1288 * @rspiocb: pointer to lpfc response iocb data structure.
1289 *
1290 * This routine is the completion callback function for issuing the Port
1291 * Login (PLOGI) command. For PLOGI completion, there must be an active
1292 * ndlp on the vport node list that matches the remote node ID from the
1293 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1294 * ignored and command IOCB released. The PLOGI response IOCB status is
1295 * checked for error conditons. If there is error status reported, PLOGI
1296 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1297 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1298 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1299 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1300 * there are additional N_Port nodes with the vport that need to perform
1301 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1302 * PLOGIs.
1303 **/
dea31012005-04-17 16:05:31 -05001304static void
James Smart2e0fef82007-06-17 19:56:36 -05001305lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1306 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001307{
James Smart2e0fef82007-06-17 19:56:36 -05001308 struct lpfc_vport *vport = cmdiocb->vport;
1309 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001310 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001311 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001312 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001313 int disc, rc, did, type;
1314
dea31012005-04-17 16:05:31 -05001315 /* we pass cmdiocb to state machine which needs rspiocb as well */
1316 cmdiocb->context_un.rsp_iocb = rspiocb;
1317
1318 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001319 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1320 "PLOGI cmpl: status:x%x/x%x did:x%x",
1321 irsp->ulpStatus, irsp->un.ulpWord[4],
1322 irsp->un.elsreq64.remoteID);
1323
James Smart2e0fef82007-06-17 19:56:36 -05001324 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001325 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001326 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1327 "0136 PLOGI completes to NPort x%x "
1328 "with no ndlp. Data: x%x x%x x%x\n",
1329 irsp->un.elsreq64.remoteID,
1330 irsp->ulpStatus, irsp->un.ulpWord[4],
1331 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001332 goto out;
James Smarted957682007-06-17 19:56:37 -05001333 }
dea31012005-04-17 16:05:31 -05001334
1335 /* Since ndlp can be freed in the disc state machine, note if this node
1336 * is being used during discovery.
1337 */
James Smart2e0fef82007-06-17 19:56:36 -05001338 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001339 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001340 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001341 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001342 rc = 0;
1343
1344 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001345 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1346 "0102 PLOGI completes to NPort x%x "
1347 "Data: x%x x%x x%x x%x x%x\n",
1348 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1349 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001350 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001351 if (lpfc_els_chk_latt(vport)) {
1352 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001353 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001354 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001355 goto out;
1356 }
1357
1358 /* ndlp could be freed in DSM, save these values now */
1359 type = ndlp->nlp_type;
1360 did = ndlp->nlp_DID;
1361
1362 if (irsp->ulpStatus) {
1363 /* Check for retry */
1364 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1365 /* ELS command is being retried */
1366 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001367 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001368 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001369 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001370 }
1371 goto out;
1372 }
dea31012005-04-17 16:05:31 -05001373 /* PLOGI failed */
1374 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001375 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001376 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001377 else
James Smart2e0fef82007-06-17 19:56:36 -05001378 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001379 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001380 } else {
1381 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001382 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001383 cmdiocb->context2)->list.next,
1384 struct lpfc_dmabuf, list);
1385 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001386 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001387 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001388 }
1389
James Smart2e0fef82007-06-17 19:56:36 -05001390 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001391 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001392 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001393
James Smart2e0fef82007-06-17 19:56:36 -05001394 if (vport->num_disc_nodes == 0) {
1395 spin_lock_irq(shost->host_lock);
1396 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1397 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001398
James Smart2e0fef82007-06-17 19:56:36 -05001399 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001400 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001401 }
1402 }
1403
1404out:
1405 lpfc_els_free_iocb(phba, cmdiocb);
1406 return;
1407}
1408
James Smarte59058c2008-08-24 21:49:00 -04001409/**
James Smart3621a712009-04-06 18:47:14 -04001410 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001411 * @vport: pointer to a host virtual N_Port data structure.
1412 * @did: destination port identifier.
1413 * @retry: number of retries to the command IOCB.
1414 *
1415 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1416 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1417 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1418 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1419 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1420 *
1421 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1422 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1423 * will be stored into the context1 field of the IOCB for the completion
1424 * callback function to the PLOGI ELS command.
1425 *
1426 * Return code
1427 * 0 - Successfully issued a plogi for @vport
1428 * 1 - failed to issue a plogi for @vport
1429 **/
dea31012005-04-17 16:05:31 -05001430int
James Smart2e0fef82007-06-17 19:56:36 -05001431lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001432{
James Smart2e0fef82007-06-17 19:56:36 -05001433 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001434 struct serv_parm *sp;
1435 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001436 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001437 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001438 struct lpfc_sli *psli;
1439 uint8_t *pcmd;
1440 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001441 int ret;
dea31012005-04-17 16:05:31 -05001442
1443 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001444
James Smart98c9ea52007-10-27 13:37:33 -04001445 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001446 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1447 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001448
James Smarte47c9092008-02-08 18:49:26 -05001449 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001450 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001451 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001452 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001453 if (!elsiocb)
1454 return 1;
dea31012005-04-17 16:05:31 -05001455
1456 icmd = &elsiocb->iocb;
1457 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1458
1459 /* For PLOGI request, remainder of payload is service parameters */
1460 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001461 pcmd += sizeof(uint32_t);
1462 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001463 sp = (struct serv_parm *) pcmd;
1464
1465 if (sp->cmn.fcphLow < FC_PH_4_3)
1466 sp->cmn.fcphLow = FC_PH_4_3;
1467
1468 if (sp->cmn.fcphHigh < FC_PH3)
1469 sp->cmn.fcphHigh = FC_PH3;
1470
James Smart858c9f62007-06-17 19:56:39 -05001471 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1472 "Issue PLOGI: did:x%x",
1473 did, 0, 0);
1474
dea31012005-04-17 16:05:31 -05001475 phba->fc_stat.elsXmitPLOGI++;
1476 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001477 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001478
1479 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001480 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001481 return 1;
dea31012005-04-17 16:05:31 -05001482 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001483 return 0;
dea31012005-04-17 16:05:31 -05001484}
1485
James Smarte59058c2008-08-24 21:49:00 -04001486/**
James Smart3621a712009-04-06 18:47:14 -04001487 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001488 * @phba: pointer to lpfc hba data structure.
1489 * @cmdiocb: pointer to lpfc command iocb data structure.
1490 * @rspiocb: pointer to lpfc response iocb data structure.
1491 *
1492 * This routine is the completion callback function for a Process Login
1493 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1494 * status. If there is error status reported, PRLI retry shall be attempted
1495 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1496 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1497 * ndlp to mark the PRLI completion.
1498 **/
dea31012005-04-17 16:05:31 -05001499static void
James Smart2e0fef82007-06-17 19:56:36 -05001500lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1501 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001502{
James Smart2e0fef82007-06-17 19:56:36 -05001503 struct lpfc_vport *vport = cmdiocb->vport;
1504 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001505 IOCB_t *irsp;
1506 struct lpfc_sli *psli;
1507 struct lpfc_nodelist *ndlp;
1508
1509 psli = &phba->sli;
1510 /* we pass cmdiocb to state machine which needs rspiocb as well */
1511 cmdiocb->context_un.rsp_iocb = rspiocb;
1512
1513 irsp = &(rspiocb->iocb);
1514 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001515 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001516 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001517 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001518
James Smart858c9f62007-06-17 19:56:39 -05001519 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1520 "PRLI cmpl: status:x%x/x%x did:x%x",
1521 irsp->ulpStatus, irsp->un.ulpWord[4],
1522 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001523 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001524 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1525 "0103 PRLI completes to NPort x%x "
1526 "Data: x%x x%x x%x x%x\n",
1527 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1528 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001529
James Smart2e0fef82007-06-17 19:56:36 -05001530 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001531 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001532 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001533 goto out;
1534
1535 if (irsp->ulpStatus) {
1536 /* Check for retry */
1537 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1538 /* ELS command is being retried */
1539 goto out;
1540 }
1541 /* PRLI failed */
1542 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001543 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001544 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001545 else
James Smart2e0fef82007-06-17 19:56:36 -05001546 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001547 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001548 } else
dea31012005-04-17 16:05:31 -05001549 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001550 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001551 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001552out:
1553 lpfc_els_free_iocb(phba, cmdiocb);
1554 return;
1555}
1556
James Smarte59058c2008-08-24 21:49:00 -04001557/**
James Smart3621a712009-04-06 18:47:14 -04001558 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001559 * @vport: pointer to a host virtual N_Port data structure.
1560 * @ndlp: pointer to a node-list data structure.
1561 * @retry: number of retries to the command IOCB.
1562 *
1563 * This routine issues a Process Login (PRLI) ELS command for the
1564 * @vport. The PRLI service parameters are set up in the payload of the
1565 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1566 * is put to the IOCB completion callback func field before invoking the
1567 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1568 *
1569 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1570 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1571 * will be stored into the context1 field of the IOCB for the completion
1572 * callback function to the PRLI ELS command.
1573 *
1574 * Return code
1575 * 0 - successfully issued prli iocb command for @vport
1576 * 1 - failed to issue prli iocb command for @vport
1577 **/
dea31012005-04-17 16:05:31 -05001578int
James Smart2e0fef82007-06-17 19:56:36 -05001579lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001580 uint8_t retry)
1581{
James Smart2e0fef82007-06-17 19:56:36 -05001582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1583 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001584 PRLI *npr;
1585 IOCB_t *icmd;
1586 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001587 uint8_t *pcmd;
1588 uint16_t cmdsize;
1589
James Smart92d7f7b2007-06-17 19:56:38 -05001590 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001591 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1592 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001593 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001594 return 1;
dea31012005-04-17 16:05:31 -05001595
1596 icmd = &elsiocb->iocb;
1597 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1598
1599 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001600 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001601 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001602 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001603
1604 /* For PRLI, remainder of payload is PRLI parameter page */
1605 npr = (PRLI *) pcmd;
1606 /*
1607 * If our firmware version is 3.20 or later,
1608 * set the following bits for FC-TAPE support.
1609 */
1610 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1611 npr->ConfmComplAllowed = 1;
1612 npr->Retry = 1;
1613 npr->TaskRetryIdReq = 1;
1614 }
1615 npr->estabImagePair = 1;
1616 npr->readXferRdyDis = 1;
1617
1618 /* For FCP support */
1619 npr->prliType = PRLI_FCP_TYPE;
1620 npr->initiatorFunc = 1;
1621
James Smart858c9f62007-06-17 19:56:39 -05001622 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1623 "Issue PRLI: did:x%x",
1624 ndlp->nlp_DID, 0, 0);
1625
dea31012005-04-17 16:05:31 -05001626 phba->fc_stat.elsXmitPRLI++;
1627 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001628 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001629 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001630 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001631 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1632 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001633 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001634 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001635 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001636 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001637 return 1;
dea31012005-04-17 16:05:31 -05001638 }
James Smart2e0fef82007-06-17 19:56:36 -05001639 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001640 return 0;
dea31012005-04-17 16:05:31 -05001641}
1642
James Smarte59058c2008-08-24 21:49:00 -04001643/**
James Smart3621a712009-04-06 18:47:14 -04001644 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001645 * @vport: pointer to a host virtual N_Port data structure.
1646 *
1647 * This routine performs Registration State Change Notification (RSCN)
1648 * discovery for a @vport. If the @vport's node port recovery count is not
1649 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1650 * the nodes that need recovery. If none of the PLOGI were needed through
1651 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1652 * invoked to check and handle possible more RSCN came in during the period
1653 * of processing the current ones.
1654 **/
1655static void
1656lpfc_rscn_disc(struct lpfc_vport *vport)
1657{
1658 lpfc_can_disctmo(vport);
1659
1660 /* RSCN discovery */
1661 /* go thru NPR nodes and issue ELS PLOGIs */
1662 if (vport->fc_npr_cnt)
1663 if (lpfc_els_disc_plogi(vport))
1664 return;
1665
1666 lpfc_end_rscn(vport);
1667}
1668
1669/**
James Smart3621a712009-04-06 18:47:14 -04001670 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001671 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1672 *
1673 * This function is called when the final ADISC is completed during discovery.
1674 * This function handles clearing link attention or issuing reg_vpi depending
1675 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1676 * discovery.
1677 * This function is called with no locks held.
1678 **/
1679static void
1680lpfc_adisc_done(struct lpfc_vport *vport)
1681{
1682 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1683 struct lpfc_hba *phba = vport->phba;
1684
1685 /*
1686 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1687 * and continue discovery.
1688 */
1689 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04001690 !(vport->fc_flag & FC_RSCN_MODE) &&
1691 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04001692 lpfc_issue_reg_vpi(phba, vport);
1693 return;
1694 }
1695 /*
1696 * For SLI2, we need to set port_state to READY
1697 * and continue discovery.
1698 */
1699 if (vport->port_state < LPFC_VPORT_READY) {
1700 /* If we get here, there is nothing to ADISC */
1701 if (vport->port_type == LPFC_PHYSICAL_PORT)
1702 lpfc_issue_clear_la(phba, vport);
1703 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1704 vport->num_disc_nodes = 0;
1705 /* go thru NPR list, issue ELS PLOGIs */
1706 if (vport->fc_npr_cnt)
1707 lpfc_els_disc_plogi(vport);
1708 if (!vport->num_disc_nodes) {
1709 spin_lock_irq(shost->host_lock);
1710 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1711 spin_unlock_irq(shost->host_lock);
1712 lpfc_can_disctmo(vport);
1713 lpfc_end_rscn(vport);
1714 }
1715 }
1716 vport->port_state = LPFC_VPORT_READY;
1717 } else
1718 lpfc_rscn_disc(vport);
1719}
1720
1721/**
James Smart3621a712009-04-06 18:47:14 -04001722 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001723 * @vport: pointer to a host virtual N_Port data structure.
1724 *
1725 * This routine determines whether there are more ndlps on a @vport
1726 * node list need to have Address Discover (ADISC) issued. If so, it will
1727 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1728 * remaining nodes which need to have ADISC sent.
1729 **/
James Smart0ff10d42008-01-11 01:52:36 -05001730void
James Smart2e0fef82007-06-17 19:56:36 -05001731lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001732{
1733 int sentadisc;
1734
James Smart2e0fef82007-06-17 19:56:36 -05001735 if (vport->num_disc_nodes)
1736 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001737 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001738 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1739 "0210 Continue discovery with %d ADISCs to go "
1740 "Data: x%x x%x x%x\n",
1741 vport->num_disc_nodes, vport->fc_adisc_cnt,
1742 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001743 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001744 if (vport->fc_flag & FC_NLP_MORE) {
1745 lpfc_set_disctmo(vport);
1746 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1747 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001748 }
James Smart90160e02008-08-24 21:49:45 -04001749 if (!vport->num_disc_nodes)
1750 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001751 return;
1752}
1753
James Smarte59058c2008-08-24 21:49:00 -04001754/**
James Smart3621a712009-04-06 18:47:14 -04001755 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04001756 * @phba: pointer to lpfc hba data structure.
1757 * @cmdiocb: pointer to lpfc command iocb data structure.
1758 * @rspiocb: pointer to lpfc response iocb data structure.
1759 *
1760 * This routine is the completion function for issuing the Address Discover
1761 * (ADISC) command. It first checks to see whether link went down during
1762 * the discovery process. If so, the node will be marked as node port
1763 * recovery for issuing discover IOCB by the link attention handler and
1764 * exit. Otherwise, the response status is checked. If error was reported
1765 * in the response status, the ADISC command shall be retried by invoking
1766 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1767 * the response status, the state machine is invoked to set transition
1768 * with respect to NLP_EVT_CMPL_ADISC event.
1769 **/
dea31012005-04-17 16:05:31 -05001770static void
James Smart2e0fef82007-06-17 19:56:36 -05001771lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1772 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001773{
James Smart2e0fef82007-06-17 19:56:36 -05001774 struct lpfc_vport *vport = cmdiocb->vport;
1775 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001776 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001777 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001778 int disc;
dea31012005-04-17 16:05:31 -05001779
1780 /* we pass cmdiocb to state machine which needs rspiocb as well */
1781 cmdiocb->context_un.rsp_iocb = rspiocb;
1782
1783 irsp = &(rspiocb->iocb);
1784 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001785
James Smart858c9f62007-06-17 19:56:39 -05001786 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1787 "ADISC cmpl: status:x%x/x%x did:x%x",
1788 irsp->ulpStatus, irsp->un.ulpWord[4],
1789 ndlp->nlp_DID);
1790
dea31012005-04-17 16:05:31 -05001791 /* Since ndlp can be freed in the disc state machine, note if this node
1792 * is being used during discovery.
1793 */
James Smart2e0fef82007-06-17 19:56:36 -05001794 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001795 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001796 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001797 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001798 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001799 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1800 "0104 ADISC completes to NPort x%x "
1801 "Data: x%x x%x x%x x%x x%x\n",
1802 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1803 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001804 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001805 if (lpfc_els_chk_latt(vport)) {
1806 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001807 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001808 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001809 goto out;
1810 }
1811
1812 if (irsp->ulpStatus) {
1813 /* Check for retry */
1814 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1815 /* ELS command is being retried */
1816 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001817 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001818 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001819 spin_unlock_irq(shost->host_lock);
1820 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001821 }
1822 goto out;
1823 }
1824 /* ADISC failed */
1825 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001826 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001827 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001828 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001829 } else
dea31012005-04-17 16:05:31 -05001830 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001831 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001832 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001833
James Smart90160e02008-08-24 21:49:45 -04001834 /* Check to see if there are more ADISCs to be sent */
1835 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05001836 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001837out:
1838 lpfc_els_free_iocb(phba, cmdiocb);
1839 return;
1840}
1841
James Smarte59058c2008-08-24 21:49:00 -04001842/**
James Smart3621a712009-04-06 18:47:14 -04001843 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04001844 * @vport: pointer to a virtual N_Port data structure.
1845 * @ndlp: pointer to a node-list data structure.
1846 * @retry: number of retries to the command IOCB.
1847 *
1848 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1849 * @vport. It prepares the payload of the ADISC ELS command, updates the
1850 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1851 * to issue the ADISC ELS command.
1852 *
1853 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1854 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1855 * will be stored into the context1 field of the IOCB for the completion
1856 * callback function to the ADISC ELS command.
1857 *
1858 * Return code
1859 * 0 - successfully issued adisc
1860 * 1 - failed to issue adisc
1861 **/
dea31012005-04-17 16:05:31 -05001862int
James Smart2e0fef82007-06-17 19:56:36 -05001863lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001864 uint8_t retry)
1865{
James Smart2e0fef82007-06-17 19:56:36 -05001866 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1867 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001868 ADISC *ap;
1869 IOCB_t *icmd;
1870 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001871 uint8_t *pcmd;
1872 uint16_t cmdsize;
1873
James Smart92d7f7b2007-06-17 19:56:38 -05001874 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001875 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1876 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001877 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001878 return 1;
dea31012005-04-17 16:05:31 -05001879
1880 icmd = &elsiocb->iocb;
1881 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1882
1883 /* For ADISC request, remainder of payload is service parameters */
1884 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001885 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001886
1887 /* Fill in ADISC payload */
1888 ap = (ADISC *) pcmd;
1889 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05001890 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1891 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001892 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001893
James Smart858c9f62007-06-17 19:56:39 -05001894 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1895 "Issue ADISC: did:x%x",
1896 ndlp->nlp_DID, 0, 0);
1897
dea31012005-04-17 16:05:31 -05001898 phba->fc_stat.elsXmitADISC++;
1899 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05001900 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001901 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001902 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001903 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1904 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001905 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001906 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001907 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001908 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001909 return 1;
dea31012005-04-17 16:05:31 -05001910 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001911 return 0;
dea31012005-04-17 16:05:31 -05001912}
1913
James Smarte59058c2008-08-24 21:49:00 -04001914/**
James Smart3621a712009-04-06 18:47:14 -04001915 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04001916 * @phba: pointer to lpfc hba data structure.
1917 * @cmdiocb: pointer to lpfc command iocb data structure.
1918 * @rspiocb: pointer to lpfc response iocb data structure.
1919 *
1920 * This routine is the completion function for issuing the ELS Logout (LOGO)
1921 * command. If no error status was reported from the LOGO response, the
1922 * state machine of the associated ndlp shall be invoked for transition with
1923 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
1924 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
1925 **/
dea31012005-04-17 16:05:31 -05001926static void
James Smart2e0fef82007-06-17 19:56:36 -05001927lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1928 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001929{
James Smart2e0fef82007-06-17 19:56:36 -05001930 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1931 struct lpfc_vport *vport = ndlp->vport;
1932 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001933 IOCB_t *irsp;
1934 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001935
1936 psli = &phba->sli;
1937 /* we pass cmdiocb to state machine which needs rspiocb as well */
1938 cmdiocb->context_un.rsp_iocb = rspiocb;
1939
1940 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001941 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001942 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001943 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001944
James Smart858c9f62007-06-17 19:56:39 -05001945 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1946 "LOGO cmpl: status:x%x/x%x did:x%x",
1947 irsp->ulpStatus, irsp->un.ulpWord[4],
1948 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001949 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001950 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1951 "0105 LOGO completes to NPort x%x "
1952 "Data: x%x x%x x%x x%x\n",
1953 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1954 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001955 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001956 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001957 goto out;
1958
James Smart92d7f7b2007-06-17 19:56:38 -05001959 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1960 /* NLP_EVT_DEVICE_RM should unregister the RPI
1961 * which should abort all outstanding IOs.
1962 */
1963 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1964 NLP_EVT_DEVICE_RM);
1965 goto out;
1966 }
1967
dea31012005-04-17 16:05:31 -05001968 if (irsp->ulpStatus) {
1969 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001970 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001971 /* ELS command is being retried */
1972 goto out;
dea31012005-04-17 16:05:31 -05001973 /* LOGO failed */
1974 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001975 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001976 goto out;
James Smart858c9f62007-06-17 19:56:39 -05001977 else
James Smart2e0fef82007-06-17 19:56:36 -05001978 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001979 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05001980 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001981 /* Good status, call state machine.
1982 * This will unregister the rpi if needed.
1983 */
James Smart2e0fef82007-06-17 19:56:36 -05001984 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001985 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001986out:
1987 lpfc_els_free_iocb(phba, cmdiocb);
1988 return;
1989}
1990
James Smarte59058c2008-08-24 21:49:00 -04001991/**
James Smart3621a712009-04-06 18:47:14 -04001992 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04001993 * @vport: pointer to a virtual N_Port data structure.
1994 * @ndlp: pointer to a node-list data structure.
1995 * @retry: number of retries to the command IOCB.
1996 *
1997 * This routine constructs and issues an ELS Logout (LOGO) iocb command
1998 * to a remote node, referred by an @ndlp on a @vport. It constructs the
1999 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2000 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2001 *
2002 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2003 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2004 * will be stored into the context1 field of the IOCB for the completion
2005 * callback function to the LOGO ELS command.
2006 *
2007 * Return code
2008 * 0 - successfully issued logo
2009 * 1 - failed to issue logo
2010 **/
dea31012005-04-17 16:05:31 -05002011int
James Smart2e0fef82007-06-17 19:56:36 -05002012lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002013 uint8_t retry)
2014{
James Smart2e0fef82007-06-17 19:56:36 -05002015 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2016 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002017 IOCB_t *icmd;
2018 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002019 uint8_t *pcmd;
2020 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002021 int rc;
dea31012005-04-17 16:05:31 -05002022
James Smart98c9ea52007-10-27 13:37:33 -04002023 spin_lock_irq(shost->host_lock);
2024 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2025 spin_unlock_irq(shost->host_lock);
2026 return 0;
2027 }
2028 spin_unlock_irq(shost->host_lock);
2029
James Smart92d7f7b2007-06-17 19:56:38 -05002030 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002031 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2032 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002033 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002034 return 1;
dea31012005-04-17 16:05:31 -05002035
2036 icmd = &elsiocb->iocb;
2037 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2038 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002039 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002040
2041 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002042 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002043 pcmd += sizeof(uint32_t);
2044 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002045
James Smart858c9f62007-06-17 19:56:39 -05002046 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2047 "Issue LOGO: did:x%x",
2048 ndlp->nlp_DID, 0, 0);
2049
dea31012005-04-17 16:05:31 -05002050 phba->fc_stat.elsXmitLOGO++;
2051 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002052 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002053 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002054 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002055 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002056
2057 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002058 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002059 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002060 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002061 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002062 return 1;
dea31012005-04-17 16:05:31 -05002063 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002064 return 0;
dea31012005-04-17 16:05:31 -05002065}
2066
James Smarte59058c2008-08-24 21:49:00 -04002067/**
James Smart3621a712009-04-06 18:47:14 -04002068 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002069 * @phba: pointer to lpfc hba data structure.
2070 * @cmdiocb: pointer to lpfc command iocb data structure.
2071 * @rspiocb: pointer to lpfc response iocb data structure.
2072 *
2073 * This routine is a generic completion callback function for ELS commands.
2074 * Specifically, it is the callback function which does not need to perform
2075 * any command specific operations. It is currently used by the ELS command
2076 * issuing routines for the ELS State Change Request (SCR),
2077 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2078 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2079 * certain debug loggings, this callback function simply invokes the
2080 * lpfc_els_chk_latt() routine to check whether link went down during the
2081 * discovery process.
2082 **/
dea31012005-04-17 16:05:31 -05002083static void
James Smart2e0fef82007-06-17 19:56:36 -05002084lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2085 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002086{
James Smart2e0fef82007-06-17 19:56:36 -05002087 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002088 IOCB_t *irsp;
2089
2090 irsp = &rspiocb->iocb;
2091
James Smart858c9f62007-06-17 19:56:39 -05002092 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2093 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2094 irsp->ulpStatus, irsp->un.ulpWord[4],
2095 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002096 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002097 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2098 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2099 irsp->ulpIoTag, irsp->ulpStatus,
2100 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002101 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002102 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002103 lpfc_els_free_iocb(phba, cmdiocb);
2104 return;
2105}
2106
James Smarte59058c2008-08-24 21:49:00 -04002107/**
James Smart3621a712009-04-06 18:47:14 -04002108 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002109 * @vport: pointer to a host virtual N_Port data structure.
2110 * @nportid: N_Port identifier to the remote node.
2111 * @retry: number of retries to the command IOCB.
2112 *
2113 * This routine issues a State Change Request (SCR) to a fabric node
2114 * on a @vport. The remote node @nportid is passed into the function. It
2115 * first search the @vport node list to find the matching ndlp. If no such
2116 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2117 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2118 * routine is invoked to send the SCR IOCB.
2119 *
2120 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2121 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2122 * will be stored into the context1 field of the IOCB for the completion
2123 * callback function to the SCR ELS command.
2124 *
2125 * Return code
2126 * 0 - Successfully issued scr command
2127 * 1 - Failed to issue scr command
2128 **/
dea31012005-04-17 16:05:31 -05002129int
James Smart2e0fef82007-06-17 19:56:36 -05002130lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002131{
James Smart2e0fef82007-06-17 19:56:36 -05002132 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002133 IOCB_t *icmd;
2134 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002135 struct lpfc_sli *psli;
2136 uint8_t *pcmd;
2137 uint16_t cmdsize;
2138 struct lpfc_nodelist *ndlp;
2139
2140 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002141 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002142
James Smarte47c9092008-02-08 18:49:26 -05002143 ndlp = lpfc_findnode_did(vport, nportid);
2144 if (!ndlp) {
2145 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2146 if (!ndlp)
2147 return 1;
2148 lpfc_nlp_init(vport, ndlp, nportid);
2149 lpfc_enqueue_node(vport, ndlp);
2150 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2151 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2152 if (!ndlp)
2153 return 1;
2154 }
dea31012005-04-17 16:05:31 -05002155
James Smart2e0fef82007-06-17 19:56:36 -05002156 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2157 ndlp->nlp_DID, ELS_CMD_SCR);
2158
James Smart488d1462006-03-07 15:02:37 -05002159 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002160 /* This will trigger the release of the node just
2161 * allocated
2162 */
James Smart329f9bc2007-04-25 09:53:01 -04002163 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002164 return 1;
dea31012005-04-17 16:05:31 -05002165 }
2166
2167 icmd = &elsiocb->iocb;
2168 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2169
2170 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002171 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002172
2173 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002174 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002175 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2176
James Smart858c9f62007-06-17 19:56:39 -05002177 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2178 "Issue SCR: did:x%x",
2179 ndlp->nlp_DID, 0, 0);
2180
dea31012005-04-17 16:05:31 -05002181 phba->fc_stat.elsXmitSCR++;
2182 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002183 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2184 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002185 /* The additional lpfc_nlp_put will cause the following
2186 * lpfc_els_free_iocb routine to trigger the rlease of
2187 * the node.
2188 */
James Smart329f9bc2007-04-25 09:53:01 -04002189 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002190 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002191 return 1;
dea31012005-04-17 16:05:31 -05002192 }
James Smartfa4066b2008-01-11 01:53:27 -05002193 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2194 * trigger the release of node.
2195 */
James Smart329f9bc2007-04-25 09:53:01 -04002196 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002197 return 0;
dea31012005-04-17 16:05:31 -05002198}
2199
James Smarte59058c2008-08-24 21:49:00 -04002200/**
James Smart3621a712009-04-06 18:47:14 -04002201 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002202 * @vport: pointer to a host virtual N_Port data structure.
2203 * @nportid: N_Port identifier to the remote node.
2204 * @retry: number of retries to the command IOCB.
2205 *
2206 * This routine issues a Fibre Channel Address Resolution Response
2207 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2208 * is passed into the function. It first search the @vport node list to find
2209 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2210 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2211 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2212 *
2213 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2214 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2215 * will be stored into the context1 field of the IOCB for the completion
2216 * callback function to the PARPR ELS command.
2217 *
2218 * Return code
2219 * 0 - Successfully issued farpr command
2220 * 1 - Failed to issue farpr command
2221 **/
dea31012005-04-17 16:05:31 -05002222static int
James Smart2e0fef82007-06-17 19:56:36 -05002223lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002224{
James Smart2e0fef82007-06-17 19:56:36 -05002225 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002226 IOCB_t *icmd;
2227 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002228 struct lpfc_sli *psli;
2229 FARP *fp;
2230 uint8_t *pcmd;
2231 uint32_t *lp;
2232 uint16_t cmdsize;
2233 struct lpfc_nodelist *ondlp;
2234 struct lpfc_nodelist *ndlp;
2235
2236 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002237 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002238
James Smarte47c9092008-02-08 18:49:26 -05002239 ndlp = lpfc_findnode_did(vport, nportid);
2240 if (!ndlp) {
2241 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2242 if (!ndlp)
2243 return 1;
2244 lpfc_nlp_init(vport, ndlp, nportid);
2245 lpfc_enqueue_node(vport, ndlp);
2246 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2247 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2248 if (!ndlp)
2249 return 1;
2250 }
James Smart2e0fef82007-06-17 19:56:36 -05002251
2252 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2253 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002254 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002255 /* This will trigger the release of the node just
2256 * allocated
2257 */
James Smart329f9bc2007-04-25 09:53:01 -04002258 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002259 return 1;
dea31012005-04-17 16:05:31 -05002260 }
2261
2262 icmd = &elsiocb->iocb;
2263 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2264
2265 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002266 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002267
2268 /* Fill in FARPR payload */
2269 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002270 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002271 lp = (uint32_t *) pcmd;
2272 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002273 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002274 fp->Rflags = 0;
2275 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2276
James Smart92d7f7b2007-06-17 19:56:38 -05002277 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2278 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002279 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002280 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002281 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002282 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002283 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002284 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002285 }
2286
James Smart858c9f62007-06-17 19:56:39 -05002287 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2288 "Issue FARPR: did:x%x",
2289 ndlp->nlp_DID, 0, 0);
2290
dea31012005-04-17 16:05:31 -05002291 phba->fc_stat.elsXmitFARPR++;
2292 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002293 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2294 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002295 /* The additional lpfc_nlp_put will cause the following
2296 * lpfc_els_free_iocb routine to trigger the release of
2297 * the node.
2298 */
James Smart329f9bc2007-04-25 09:53:01 -04002299 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002300 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002301 return 1;
dea31012005-04-17 16:05:31 -05002302 }
James Smartfa4066b2008-01-11 01:53:27 -05002303 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2304 * trigger the release of the node.
2305 */
James Smart329f9bc2007-04-25 09:53:01 -04002306 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002307 return 0;
dea31012005-04-17 16:05:31 -05002308}
2309
James Smarte59058c2008-08-24 21:49:00 -04002310/**
James Smart3621a712009-04-06 18:47:14 -04002311 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002312 * @vport: pointer to a host virtual N_Port data structure.
2313 * @nlp: pointer to a node-list data structure.
2314 *
2315 * This routine cancels the timer with a delayed IOCB-command retry for
2316 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2317 * removes the ELS retry event if it presents. In addition, if the
2318 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2319 * commands are sent for the @vport's nodes that require issuing discovery
2320 * ADISC.
2321 **/
dea31012005-04-17 16:05:31 -05002322void
James Smart2e0fef82007-06-17 19:56:36 -05002323lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002324{
James Smart2e0fef82007-06-17 19:56:36 -05002325 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002326 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002327
James Smart0d2b6b82008-06-14 22:52:47 -04002328 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2329 return;
James Smart2e0fef82007-06-17 19:56:36 -05002330 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002331 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002332 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002333 del_timer_sync(&nlp->nlp_delayfunc);
2334 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002335 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002336 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002337 /* Decrement nlp reference count held for the delayed retry */
2338 evtp = &nlp->els_retry_evt;
2339 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2340 }
James Smartfdcebe22006-03-07 15:04:01 -05002341 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002342 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002343 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002344 spin_unlock_irq(shost->host_lock);
2345 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002346 if (vport->port_state < LPFC_VPORT_READY) {
2347 /* Check if there are more ADISCs to be sent */
2348 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002349 } else {
2350 /* Check if there are more PLOGIs to be sent */
2351 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002352 if (vport->num_disc_nodes == 0) {
2353 spin_lock_irq(shost->host_lock);
2354 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2355 spin_unlock_irq(shost->host_lock);
2356 lpfc_can_disctmo(vport);
2357 lpfc_end_rscn(vport);
2358 }
James Smartfdcebe22006-03-07 15:04:01 -05002359 }
2360 }
2361 }
2362 return;
2363}
2364
James Smarte59058c2008-08-24 21:49:00 -04002365/**
James Smart3621a712009-04-06 18:47:14 -04002366 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002367 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2368 *
2369 * This routine is invoked by the ndlp delayed-function timer to check
2370 * whether there is any pending ELS retry event(s) with the node. If not, it
2371 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2372 * adds the delayed events to the HBA work list and invokes the
2373 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2374 * event. Note that lpfc_nlp_get() is called before posting the event to
2375 * the work list to hold reference count of ndlp so that it guarantees the
2376 * reference to ndlp will still be available when the worker thread gets
2377 * to the event associated with the ndlp.
2378 **/
James Smartfdcebe22006-03-07 15:04:01 -05002379void
dea31012005-04-17 16:05:31 -05002380lpfc_els_retry_delay(unsigned long ptr)
2381{
James Smart2e0fef82007-06-17 19:56:36 -05002382 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2383 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002384 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002385 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002386 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002387
James Smart92d7f7b2007-06-17 19:56:38 -05002388 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002389 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002390 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002391 return;
2392 }
2393
James Smartfa4066b2008-01-11 01:53:27 -05002394 /* We need to hold the node by incrementing the reference
2395 * count until the queued work is done
2396 */
2397 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002398 if (evtp->evt_arg1) {
2399 evtp->evt = LPFC_EVT_ELS_RETRY;
2400 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002401 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002402 }
James Smart92d7f7b2007-06-17 19:56:38 -05002403 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002404 return;
2405}
2406
James Smarte59058c2008-08-24 21:49:00 -04002407/**
James Smart3621a712009-04-06 18:47:14 -04002408 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002409 * @ndlp: pointer to a node-list data structure.
2410 *
2411 * This routine is the worker-thread handler for processing the @ndlp delayed
2412 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2413 * the last ELS command from the associated ndlp and invokes the proper ELS
2414 * function according to the delayed ELS command to retry the command.
2415 **/
dea31012005-04-17 16:05:31 -05002416void
2417lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2418{
James Smart2e0fef82007-06-17 19:56:36 -05002419 struct lpfc_vport *vport = ndlp->vport;
2420 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2421 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002422
James Smart2e0fef82007-06-17 19:56:36 -05002423 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002424 did = ndlp->nlp_DID;
2425 cmd = ndlp->nlp_last_elscmd;
2426 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002427
2428 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002429 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002430 return;
2431 }
2432
2433 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002434 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002435 /*
2436 * If a discovery event readded nlp_delayfunc after timer
2437 * firing and before processing the timer, cancel the
2438 * nlp_delayfunc.
2439 */
2440 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002441 retry = ndlp->nlp_retry;
2442
2443 switch (cmd) {
2444 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002445 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002446 break;
2447 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002448 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002449 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002450 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002451 }
dea31012005-04-17 16:05:31 -05002452 break;
2453 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002454 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002455 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002456 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002457 }
dea31012005-04-17 16:05:31 -05002458 break;
2459 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002460 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002461 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002462 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002463 }
dea31012005-04-17 16:05:31 -05002464 break;
2465 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002466 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002467 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002468 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002469 }
dea31012005-04-17 16:05:31 -05002470 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002471 case ELS_CMD_FDISC:
2472 lpfc_issue_els_fdisc(vport, ndlp, retry);
2473 break;
dea31012005-04-17 16:05:31 -05002474 }
2475 return;
2476}
2477
James Smarte59058c2008-08-24 21:49:00 -04002478/**
James Smart3621a712009-04-06 18:47:14 -04002479 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002480 * @phba: pointer to lpfc hba data structure.
2481 * @cmdiocb: pointer to lpfc command iocb data structure.
2482 * @rspiocb: pointer to lpfc response iocb data structure.
2483 *
2484 * This routine makes a retry decision on an ELS command IOCB, which has
2485 * failed. The following ELS IOCBs use this function for retrying the command
2486 * when previously issued command responsed with error status: FLOGI, PLOGI,
2487 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2488 * returned error status, it makes the decision whether a retry shall be
2489 * issued for the command, and whether a retry shall be made immediately or
2490 * delayed. In the former case, the corresponding ELS command issuing-function
2491 * is called to retry the command. In the later case, the ELS command shall
2492 * be posted to the ndlp delayed event and delayed function timer set to the
2493 * ndlp for the delayed command issusing.
2494 *
2495 * Return code
2496 * 0 - No retry of els command is made
2497 * 1 - Immediate or delayed retry of els command is made
2498 **/
dea31012005-04-17 16:05:31 -05002499static int
James Smart2e0fef82007-06-17 19:56:36 -05002500lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2501 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002502{
James Smart2e0fef82007-06-17 19:56:36 -05002503 struct lpfc_vport *vport = cmdiocb->vport;
2504 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2505 IOCB_t *irsp = &rspiocb->iocb;
2506 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2507 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002508 uint32_t *elscmd;
2509 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002510 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002511 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002512 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002513 uint32_t did;
dea31012005-04-17 16:05:31 -05002514
James Smart488d1462006-03-07 15:02:37 -05002515
dea31012005-04-17 16:05:31 -05002516 /* Note: context2 may be 0 for internal driver abort
2517 * of delays ELS command.
2518 */
2519
2520 if (pcmd && pcmd->virt) {
2521 elscmd = (uint32_t *) (pcmd->virt);
2522 cmd = *elscmd++;
2523 }
2524
James Smarte47c9092008-02-08 18:49:26 -05002525 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002526 did = ndlp->nlp_DID;
2527 else {
2528 /* We should only hit this case for retrying PLOGI */
2529 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002530 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002531 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2532 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002533 return 1;
2534 }
2535
James Smart858c9f62007-06-17 19:56:39 -05002536 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2537 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2538 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2539
dea31012005-04-17 16:05:31 -05002540 switch (irsp->ulpStatus) {
2541 case IOSTAT_FCP_RSP_ERROR:
2542 case IOSTAT_REMOTE_STOP:
2543 break;
2544
2545 case IOSTAT_LOCAL_REJECT:
2546 switch ((irsp->un.ulpWord[4] & 0xff)) {
2547 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002548 if (cmd == ELS_CMD_FLOGI) {
2549 if (PCI_DEVICE_ID_HORNET ==
2550 phba->pcidev->device) {
2551 phba->fc_topology = TOPOLOGY_LOOP;
2552 phba->pport->fc_myDID = 0;
2553 phba->alpa_map[0] = 0;
2554 phba->alpa_map[1] = 0;
2555 }
2556 }
James Smart2e0fef82007-06-17 19:56:36 -05002557 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002558 delay = 1000;
dea31012005-04-17 16:05:31 -05002559 retry = 1;
2560 break;
2561
James Smart92d7f7b2007-06-17 19:56:38 -05002562 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002563 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2564 "0124 Retry illegal cmd x%x "
2565 "retry:x%x delay:x%x\n",
2566 cmd, cmdiocb->retry, delay);
2567 retry = 1;
2568 /* All command's retry policy */
2569 maxretry = 8;
2570 if (cmdiocb->retry > 2)
2571 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002572 break;
2573
dea31012005-04-17 16:05:31 -05002574 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002575 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002576 retry = 1;
2577 if (cmdiocb->retry > 100)
2578 delay = 100;
2579 maxretry = 250;
2580 break;
2581
2582 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002583 delay = 100;
dea31012005-04-17 16:05:31 -05002584 retry = 1;
2585 break;
2586
James Smart858c9f62007-06-17 19:56:39 -05002587 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002588 case IOERR_INVALID_RPI:
2589 retry = 1;
2590 break;
2591 }
2592 break;
2593
2594 case IOSTAT_NPORT_RJT:
2595 case IOSTAT_FABRIC_RJT:
2596 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2597 retry = 1;
2598 break;
2599 }
2600 break;
2601
2602 case IOSTAT_NPORT_BSY:
2603 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002604 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002605 retry = 1;
2606 break;
2607
2608 case IOSTAT_LS_RJT:
2609 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2610 /* Added for Vendor specifc support
2611 * Just keep retrying for these Rsn / Exp codes
2612 */
2613 switch (stat.un.b.lsRjtRsnCode) {
2614 case LSRJT_UNABLE_TPC:
2615 if (stat.un.b.lsRjtRsnCodeExp ==
2616 LSEXP_CMD_IN_PROGRESS) {
2617 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002618 delay = 1000;
dea31012005-04-17 16:05:31 -05002619 maxretry = 48;
2620 }
2621 retry = 1;
2622 break;
2623 }
2624 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002625 delay = 1000;
dea31012005-04-17 16:05:31 -05002626 maxretry = lpfc_max_els_tries + 1;
2627 retry = 1;
2628 break;
2629 }
James Smart92d7f7b2007-06-17 19:56:38 -05002630 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2631 (cmd == ELS_CMD_FDISC) &&
2632 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002633 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2634 "0125 FDISC Failed (x%x). "
2635 "Fabric out of resources\n",
2636 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002637 lpfc_vport_set_state(vport,
2638 FC_VPORT_NO_FABRIC_RSCS);
2639 }
dea31012005-04-17 16:05:31 -05002640 break;
2641
2642 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002643 if ((cmd == ELS_CMD_PLOGI) ||
2644 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002645 delay = 1000;
dea31012005-04-17 16:05:31 -05002646 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002647 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002648 /* FDISC retry policy */
2649 maxretry = 48;
2650 if (cmdiocb->retry >= 32)
2651 delay = 1000;
dea31012005-04-17 16:05:31 -05002652 }
2653 retry = 1;
2654 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002655
2656 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002657 /* There are some cases where switches return this
2658 * error when they are not ready and should be returning
2659 * Logical Busy. We should delay every time.
2660 */
2661 if (cmd == ELS_CMD_FDISC &&
2662 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2663 maxretry = 3;
2664 delay = 1000;
2665 retry = 1;
2666 break;
2667 }
James Smart92d7f7b2007-06-17 19:56:38 -05002668 case LSRJT_PROTOCOL_ERR:
2669 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2670 (cmd == ELS_CMD_FDISC) &&
2671 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2672 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2673 ) {
James Smarte8b62012007-08-02 11:10:09 -04002674 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002675 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002676 "Fabric Detected Bad WWN\n",
2677 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002678 lpfc_vport_set_state(vport,
2679 FC_VPORT_FABRIC_REJ_WWN);
2680 }
2681 break;
dea31012005-04-17 16:05:31 -05002682 }
2683 break;
2684
2685 case IOSTAT_INTERMED_RSP:
2686 case IOSTAT_BA_RJT:
2687 break;
2688
2689 default:
2690 break;
2691 }
2692
James Smart488d1462006-03-07 15:02:37 -05002693 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002694 retry = 1;
dea31012005-04-17 16:05:31 -05002695
James Smart98c9ea52007-10-27 13:37:33 -04002696 if ((cmd == ELS_CMD_FLOGI) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002697 (phba->fc_topology != TOPOLOGY_LOOP) &&
2698 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002699 /* FLOGI retry policy */
2700 retry = 1;
2701 maxretry = 48;
2702 if (cmdiocb->retry >= 32)
2703 delay = 1000;
2704 }
2705
dea31012005-04-17 16:05:31 -05002706 if ((++cmdiocb->retry) >= maxretry) {
2707 phba->fc_stat.elsRetryExceeded++;
2708 retry = 0;
2709 }
2710
James Smarted957682007-06-17 19:56:37 -05002711 if ((vport->load_flag & FC_UNLOADING) != 0)
2712 retry = 0;
2713
dea31012005-04-17 16:05:31 -05002714 if (retry) {
2715
2716 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002717 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2718 "0107 Retry ELS command x%x to remote "
2719 "NPORT x%x Data: x%x x%x\n",
2720 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002721
James Smart858c9f62007-06-17 19:56:39 -05002722 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2723 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2724 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2725 /* Don't reset timer for no resources */
2726
dea31012005-04-17 16:05:31 -05002727 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002728 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002729 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002730 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002731 }
2732
2733 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002734 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002735 phba->fc_stat.elsDelayRetry++;
2736 ndlp->nlp_retry = cmdiocb->retry;
2737
James Smart92d7f7b2007-06-17 19:56:38 -05002738 /* delay is specified in milliseconds */
2739 mod_timer(&ndlp->nlp_delayfunc,
2740 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002741 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002742 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002743 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002744
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002745 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002746 if (cmd == ELS_CMD_PRLI)
2747 lpfc_nlp_set_state(vport, ndlp,
2748 NLP_STE_REG_LOGIN_ISSUE);
2749 else
2750 lpfc_nlp_set_state(vport, ndlp,
2751 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002752 ndlp->nlp_last_elscmd = cmd;
2753
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002754 return 1;
dea31012005-04-17 16:05:31 -05002755 }
2756 switch (cmd) {
2757 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002758 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002759 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002760 case ELS_CMD_FDISC:
2761 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2762 return 1;
dea31012005-04-17 16:05:31 -05002763 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002764 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002765 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002766 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002767 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002768 }
James Smart2e0fef82007-06-17 19:56:36 -05002769 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002770 return 1;
dea31012005-04-17 16:05:31 -05002771 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002772 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002773 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2774 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002775 return 1;
dea31012005-04-17 16:05:31 -05002776 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002777 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002778 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2779 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002780 return 1;
dea31012005-04-17 16:05:31 -05002781 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002782 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002783 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2784 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002785 return 1;
dea31012005-04-17 16:05:31 -05002786 }
2787 }
dea31012005-04-17 16:05:31 -05002788 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002789 if (logerr) {
2790 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2791 "0137 No retry ELS command x%x to remote "
2792 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2793 cmd, did, irsp->ulpStatus,
2794 irsp->un.ulpWord[4]);
2795 }
2796 else {
2797 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002798 "0108 No retry ELS command x%x to remote "
2799 "NPORT x%x Retried:%d Error:x%x/%x\n",
2800 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2801 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002802 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002803 return 0;
dea31012005-04-17 16:05:31 -05002804}
2805
James Smarte59058c2008-08-24 21:49:00 -04002806/**
James Smart3621a712009-04-06 18:47:14 -04002807 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04002808 * @phba: pointer to lpfc hba data structure.
2809 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2810 *
2811 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2812 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2813 * checks to see whether there is a lpfc DMA buffer associated with the
2814 * response of the command IOCB. If so, it will be released before releasing
2815 * the lpfc DMA buffer associated with the IOCB itself.
2816 *
2817 * Return code
2818 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2819 **/
James Smart09372822008-01-11 01:52:54 -05002820static int
James Smart87af33f2007-10-27 13:37:43 -04002821lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2822{
2823 struct lpfc_dmabuf *buf_ptr;
2824
James Smarte59058c2008-08-24 21:49:00 -04002825 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04002826 if (!list_empty(&buf_ptr1->list)) {
2827 list_remove_head(&buf_ptr1->list, buf_ptr,
2828 struct lpfc_dmabuf,
2829 list);
2830 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2831 kfree(buf_ptr);
2832 }
2833 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2834 kfree(buf_ptr1);
2835 return 0;
2836}
2837
James Smarte59058c2008-08-24 21:49:00 -04002838/**
James Smart3621a712009-04-06 18:47:14 -04002839 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04002840 * @phba: pointer to lpfc hba data structure.
2841 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2842 *
2843 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2844 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2845 * pool.
2846 *
2847 * Return code
2848 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2849 **/
James Smart09372822008-01-11 01:52:54 -05002850static int
James Smart87af33f2007-10-27 13:37:43 -04002851lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2852{
2853 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2854 kfree(buf_ptr);
2855 return 0;
2856}
2857
James Smarte59058c2008-08-24 21:49:00 -04002858/**
James Smart3621a712009-04-06 18:47:14 -04002859 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04002860 * @phba: pointer to lpfc hba data structure.
2861 * @elsiocb: pointer to lpfc els command iocb data structure.
2862 *
2863 * This routine frees a command IOCB and its associated resources. The
2864 * command IOCB data structure contains the reference to various associated
2865 * resources, these fields must be set to NULL if the associated reference
2866 * not present:
2867 * context1 - reference to ndlp
2868 * context2 - reference to cmd
2869 * context2->next - reference to rsp
2870 * context3 - reference to bpl
2871 *
2872 * It first properly decrements the reference count held on ndlp for the
2873 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
2874 * set, it invokes the lpfc_els_free_data() routine to release the Direct
2875 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
2876 * adds the DMA buffer the @phba data structure for the delayed release.
2877 * If reference to the Buffer Pointer List (BPL) is present, the
2878 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
2879 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
2880 * invoked to release the IOCB data structure back to @phba IOCBQ list.
2881 *
2882 * Return code
2883 * 0 - Success (currently, always return 0)
2884 **/
James Smart87af33f2007-10-27 13:37:43 -04002885int
James Smart329f9bc2007-04-25 09:53:01 -04002886lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05002887{
2888 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04002889 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002890
James Smarta8adb832007-10-27 13:37:53 -04002891 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
2892 if (ndlp) {
2893 if (ndlp->nlp_flag & NLP_DEFER_RM) {
2894 lpfc_nlp_put(ndlp);
2895
2896 /* If the ndlp is not being used by another discovery
2897 * thread, free it.
2898 */
2899 if (!lpfc_nlp_not_used(ndlp)) {
2900 /* If ndlp is being used by another discovery
2901 * thread, just clear NLP_DEFER_RM
2902 */
2903 ndlp->nlp_flag &= ~NLP_DEFER_RM;
2904 }
2905 }
2906 else
2907 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002908 elsiocb->context1 = NULL;
2909 }
dea31012005-04-17 16:05:31 -05002910 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2911 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05002912 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
2913 /* Firmware could still be in progress of DMAing
2914 * payload, so don't free data buffer till after
2915 * a hbeat.
2916 */
2917 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
2918 buf_ptr = elsiocb->context2;
2919 elsiocb->context2 = NULL;
2920 if (buf_ptr) {
2921 buf_ptr1 = NULL;
2922 spin_lock_irq(&phba->hbalock);
2923 if (!list_empty(&buf_ptr->list)) {
2924 list_remove_head(&buf_ptr->list,
2925 buf_ptr1, struct lpfc_dmabuf,
2926 list);
2927 INIT_LIST_HEAD(&buf_ptr1->list);
2928 list_add_tail(&buf_ptr1->list,
2929 &phba->elsbuf);
2930 phba->elsbuf_cnt++;
2931 }
2932 INIT_LIST_HEAD(&buf_ptr->list);
2933 list_add_tail(&buf_ptr->list, &phba->elsbuf);
2934 phba->elsbuf_cnt++;
2935 spin_unlock_irq(&phba->hbalock);
2936 }
2937 } else {
2938 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2939 lpfc_els_free_data(phba, buf_ptr1);
2940 }
dea31012005-04-17 16:05:31 -05002941 }
2942
2943 if (elsiocb->context3) {
2944 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04002945 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05002946 }
James Bottomley604a3e32005-10-29 10:28:33 -05002947 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05002948 return 0;
2949}
2950
James Smarte59058c2008-08-24 21:49:00 -04002951/**
James Smart3621a712009-04-06 18:47:14 -04002952 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04002953 * @phba: pointer to lpfc hba data structure.
2954 * @cmdiocb: pointer to lpfc command iocb data structure.
2955 * @rspiocb: pointer to lpfc response iocb data structure.
2956 *
2957 * This routine is the completion callback function to the Logout (LOGO)
2958 * Accept (ACC) Response ELS command. This routine is invoked to indicate
2959 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
2960 * release the ndlp if it has the last reference remaining (reference count
2961 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
2962 * field to NULL to inform the following lpfc_els_free_iocb() routine no
2963 * ndlp reference count needs to be decremented. Otherwise, the ndlp
2964 * reference use-count shall be decremented by the lpfc_els_free_iocb()
2965 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
2966 * IOCB data structure.
2967 **/
dea31012005-04-17 16:05:31 -05002968static void
James Smart2e0fef82007-06-17 19:56:36 -05002969lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2970 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002971{
James Smart2e0fef82007-06-17 19:56:36 -05002972 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2973 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05002974 IOCB_t *irsp;
2975
2976 irsp = &rspiocb->iocb;
2977 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2978 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2979 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002980 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002981 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2982 "0109 ACC to LOGO completes to NPort x%x "
2983 "Data: x%x x%x x%x\n",
2984 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2985 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04002986
2987 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
2988 /* NPort Recovery mode or node is just allocated */
2989 if (!lpfc_nlp_not_used(ndlp)) {
2990 /* If the ndlp is being used by another discovery
2991 * thread, just unregister the RPI.
2992 */
2993 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05002994 } else {
2995 /* Indicate the node has already released, should
2996 * not reference to it from within lpfc_els_free_iocb.
2997 */
2998 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04002999 }
dea31012005-04-17 16:05:31 -05003000 }
3001 lpfc_els_free_iocb(phba, cmdiocb);
3002 return;
3003}
3004
James Smarte59058c2008-08-24 21:49:00 -04003005/**
James Smart3621a712009-04-06 18:47:14 -04003006 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003007 * @phba: pointer to lpfc hba data structure.
3008 * @pmb: pointer to the driver internal queue element for mailbox command.
3009 *
3010 * This routine is the completion callback function for unregister default
3011 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3012 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3013 * decrements the ndlp reference count held for this completion callback
3014 * function. After that, it invokes the lpfc_nlp_not_used() to check
3015 * whether there is only one reference left on the ndlp. If so, it will
3016 * perform one more decrement and trigger the release of the ndlp.
3017 **/
James Smart858c9f62007-06-17 19:56:39 -05003018void
3019lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3020{
3021 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3022 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3023
James Smart6fb120a2009-05-22 14:52:59 -04003024 /*
3025 * This routine is used to register and unregister in previous SLI
3026 * modes.
3027 */
3028 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3029 (phba->sli_rev == LPFC_SLI_REV4))
3030 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3031
James Smart858c9f62007-06-17 19:56:39 -05003032 pmb->context1 = NULL;
3033 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3034 kfree(mp);
3035 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003036 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003037 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003038 /* This is the end of the default RPI cleanup logic for this
3039 * ndlp. If no other discovery threads are using this ndlp.
3040 * we should free all resources associated with it.
3041 */
3042 lpfc_nlp_not_used(ndlp);
3043 }
James Smart3772a992009-05-22 14:50:54 -04003044
James Smart858c9f62007-06-17 19:56:39 -05003045 return;
3046}
3047
James Smarte59058c2008-08-24 21:49:00 -04003048/**
James Smart3621a712009-04-06 18:47:14 -04003049 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003050 * @phba: pointer to lpfc hba data structure.
3051 * @cmdiocb: pointer to lpfc command iocb data structure.
3052 * @rspiocb: pointer to lpfc response iocb data structure.
3053 *
3054 * This routine is the completion callback function for ELS Response IOCB
3055 * command. In normal case, this callback function just properly sets the
3056 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3057 * field in the command IOCB is not NULL, the referred mailbox command will
3058 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3059 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3060 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3061 * routine shall be invoked trying to release the ndlp if no other threads
3062 * are currently referring it.
3063 **/
dea31012005-04-17 16:05:31 -05003064static void
James Smart858c9f62007-06-17 19:56:39 -05003065lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003066 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003067{
James Smart2e0fef82007-06-17 19:56:36 -05003068 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3069 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3070 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003071 IOCB_t *irsp;
3072 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003073 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003074 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003075 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003076
James Smart33ccf8d2006-08-17 11:57:58 -04003077 irsp = &rspiocb->iocb;
3078
dea31012005-04-17 16:05:31 -05003079 if (cmdiocb->context_un.mbox)
3080 mbox = cmdiocb->context_un.mbox;
3081
James Smartfa4066b2008-01-11 01:53:27 -05003082 /* First determine if this is a LS_RJT cmpl. Note, this callback
3083 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3084 */
James Smart87af33f2007-10-27 13:37:43 -04003085 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003086 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3087 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003088 /* A LS_RJT associated with Default RPI cleanup has its own
3089 * seperate code path.
James Smart87af33f2007-10-27 13:37:43 -04003090 */
3091 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3092 ls_rjt = 1;
3093 }
3094
dea31012005-04-17 16:05:31 -05003095 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003096 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003097 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003098 mp = (struct lpfc_dmabuf *) mbox->context1;
3099 if (mp) {
3100 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3101 kfree(mp);
3102 }
James Smart329f9bc2007-04-25 09:53:01 -04003103 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003104 }
James Smart58da1ff2008-04-07 10:15:56 -04003105 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3106 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003107 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003108 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003109 /* Indicate the node has already released,
3110 * should not reference to it from within
3111 * the routine lpfc_els_free_iocb.
3112 */
3113 cmdiocb->context1 = NULL;
3114 }
dea31012005-04-17 16:05:31 -05003115 goto out;
3116 }
3117
James Smart858c9f62007-06-17 19:56:39 -05003118 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003119 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003120 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003121 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003122 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003123 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3124 "0110 ELS response tag x%x completes "
3125 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3126 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3127 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3128 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3129 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003130 if (mbox) {
3131 if ((rspiocb->iocb.ulpStatus == 0)
3132 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003133 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003134 /* Increment reference count to ndlp to hold the
3135 * reference to ndlp for the callback function.
3136 */
James Smart329f9bc2007-04-25 09:53:01 -04003137 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003138 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003139 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3140 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3141 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3142 }
3143 else {
3144 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3145 ndlp->nlp_prev_state = ndlp->nlp_state;
3146 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003147 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003148 }
James Smart0b727fe2007-10-27 13:37:25 -04003149 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003150 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003151 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003152 else
3153 /* Decrement the ndlp reference count we
3154 * set for this failed mailbox command.
3155 */
3156 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003157
3158 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3159 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3160 "0138 ELS rsp: Cannot issue reg_login for x%x "
3161 "Data: x%x x%x x%x\n",
3162 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3163 ndlp->nlp_rpi);
3164
James Smartfa4066b2008-01-11 01:53:27 -05003165 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003166 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003167 /* Indicate node has already been released,
3168 * should not reference to it from within
3169 * the routine lpfc_els_free_iocb.
3170 */
3171 cmdiocb->context1 = NULL;
3172 }
dea31012005-04-17 16:05:31 -05003173 } else {
James Smart858c9f62007-06-17 19:56:39 -05003174 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3175 if (!lpfc_error_lost_link(irsp) &&
3176 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003177 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003178 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003179 /* Indicate node has already been
3180 * released, should not reference
3181 * to it from within the routine
3182 * lpfc_els_free_iocb.
3183 */
3184 cmdiocb->context1 = NULL;
3185 }
dea31012005-04-17 16:05:31 -05003186 }
3187 }
James Smart14691152006-12-02 13:34:28 -05003188 mp = (struct lpfc_dmabuf *) mbox->context1;
3189 if (mp) {
3190 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3191 kfree(mp);
3192 }
3193 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003194 }
3195out:
James Smart58da1ff2008-04-07 10:15:56 -04003196 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003197 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003198 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003199 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003200
3201 /* If the node is not being used by another discovery thread,
3202 * and we are sending a reject, we are done with it.
3203 * Release driver reference count here and free associated
3204 * resources.
3205 */
3206 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003207 if (lpfc_nlp_not_used(ndlp))
3208 /* Indicate node has already been released,
3209 * should not reference to it from within
3210 * the routine lpfc_els_free_iocb.
3211 */
3212 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003213 }
James Smart87af33f2007-10-27 13:37:43 -04003214
dea31012005-04-17 16:05:31 -05003215 lpfc_els_free_iocb(phba, cmdiocb);
3216 return;
3217}
3218
James Smarte59058c2008-08-24 21:49:00 -04003219/**
James Smart3621a712009-04-06 18:47:14 -04003220 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003221 * @vport: pointer to a host virtual N_Port data structure.
3222 * @flag: the els command code to be accepted.
3223 * @oldiocb: pointer to the original lpfc command iocb data structure.
3224 * @ndlp: pointer to a node-list data structure.
3225 * @mbox: pointer to the driver internal queue element for mailbox command.
3226 *
3227 * This routine prepares and issues an Accept (ACC) response IOCB
3228 * command. It uses the @flag to properly set up the IOCB field for the
3229 * specific ACC response command to be issued and invokes the
3230 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3231 * @mbox pointer is passed in, it will be put into the context_un.mbox
3232 * field of the IOCB for the completion callback function to issue the
3233 * mailbox command to the HBA later when callback is invoked.
3234 *
3235 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3236 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3237 * will be stored into the context1 field of the IOCB for the completion
3238 * callback function to the corresponding response ELS IOCB command.
3239 *
3240 * Return code
3241 * 0 - Successfully issued acc response
3242 * 1 - Failed to issue acc response
3243 **/
dea31012005-04-17 16:05:31 -05003244int
James Smart2e0fef82007-06-17 19:56:36 -05003245lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3246 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003247 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003248{
James Smart2e0fef82007-06-17 19:56:36 -05003249 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3250 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003251 IOCB_t *icmd;
3252 IOCB_t *oldcmd;
3253 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003254 struct lpfc_sli *psli;
3255 uint8_t *pcmd;
3256 uint16_t cmdsize;
3257 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003258 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003259
3260 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003261 oldcmd = &oldiocb->iocb;
3262
3263 switch (flag) {
3264 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003265 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003266 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3267 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003268 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003269 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003270 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003271 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003272 return 1;
dea31012005-04-17 16:05:31 -05003273 }
James Smart2e0fef82007-06-17 19:56:36 -05003274
dea31012005-04-17 16:05:31 -05003275 icmd = &elsiocb->iocb;
3276 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3277 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3278 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003279 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003280
3281 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3282 "Issue ACC: did:x%x flg:x%x",
3283 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003284 break;
3285 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003286 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003287 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3288 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003289 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003290 return 1;
James Smart488d1462006-03-07 15:02:37 -05003291
dea31012005-04-17 16:05:31 -05003292 icmd = &elsiocb->iocb;
3293 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3294 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3295
3296 if (mbox)
3297 elsiocb->context_un.mbox = mbox;
3298
3299 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003300 pcmd += sizeof(uint32_t);
3301 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003302
3303 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3304 "Issue ACC PLOGI: did:x%x flg:x%x",
3305 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003306 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003307 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003308 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003309 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003310 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3311 if (!elsiocb)
3312 return 1;
3313
3314 icmd = &elsiocb->iocb;
3315 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3316 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3317
3318 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003319 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003320 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3321 els_pkt_ptr = (ELS_PKT *) pcmd;
3322 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003323
3324 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3325 "Issue ACC PRLO: did:x%x flg:x%x",
3326 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003327 break;
dea31012005-04-17 16:05:31 -05003328 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003329 return 1;
dea31012005-04-17 16:05:31 -05003330 }
dea31012005-04-17 16:05:31 -05003331 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003332 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3333 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3334 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3335 elsiocb->iotag, elsiocb->iocb.ulpContext,
3336 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3337 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003338 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003339 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003340 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003341 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003342 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3343 } else {
James Smart858c9f62007-06-17 19:56:39 -05003344 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003345 }
3346
3347 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003348 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003349 if (rc == IOCB_ERROR) {
3350 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003351 return 1;
dea31012005-04-17 16:05:31 -05003352 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003353 return 0;
dea31012005-04-17 16:05:31 -05003354}
3355
James Smarte59058c2008-08-24 21:49:00 -04003356/**
James Smart3621a712009-04-06 18:47:14 -04003357 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003358 * @vport: pointer to a virtual N_Port data structure.
3359 * @rejectError:
3360 * @oldiocb: pointer to the original lpfc command iocb data structure.
3361 * @ndlp: pointer to a node-list data structure.
3362 * @mbox: pointer to the driver internal queue element for mailbox command.
3363 *
3364 * This routine prepares and issue an Reject (RJT) response IOCB
3365 * command. If a @mbox pointer is passed in, it will be put into the
3366 * context_un.mbox field of the IOCB for the completion callback function
3367 * to issue to the HBA later.
3368 *
3369 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3370 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3371 * will be stored into the context1 field of the IOCB for the completion
3372 * callback function to the reject response ELS IOCB command.
3373 *
3374 * Return code
3375 * 0 - Successfully issued reject response
3376 * 1 - Failed to issue reject response
3377 **/
dea31012005-04-17 16:05:31 -05003378int
James Smart2e0fef82007-06-17 19:56:36 -05003379lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003380 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3381 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003382{
James Smart2e0fef82007-06-17 19:56:36 -05003383 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003384 IOCB_t *icmd;
3385 IOCB_t *oldcmd;
3386 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003387 struct lpfc_sli *psli;
3388 uint8_t *pcmd;
3389 uint16_t cmdsize;
3390 int rc;
3391
3392 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003393 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003394 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3395 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003396 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003397 return 1;
dea31012005-04-17 16:05:31 -05003398
3399 icmd = &elsiocb->iocb;
3400 oldcmd = &oldiocb->iocb;
3401 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3402 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3403
3404 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003405 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003406 *((uint32_t *) (pcmd)) = rejectError;
3407
James Smart51ef4c22007-08-02 11:10:31 -04003408 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003409 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003410
dea31012005-04-17 16:05:31 -05003411 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003412 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3413 "0129 Xmit ELS RJT x%x response tag x%x "
3414 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3415 "rpi x%x\n",
3416 rejectError, elsiocb->iotag,
3417 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3418 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003419 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3420 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3421 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3422
dea31012005-04-17 16:05:31 -05003423 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003424 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003425 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003426
dea31012005-04-17 16:05:31 -05003427 if (rc == IOCB_ERROR) {
3428 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003429 return 1;
dea31012005-04-17 16:05:31 -05003430 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003431 return 0;
dea31012005-04-17 16:05:31 -05003432}
3433
James Smarte59058c2008-08-24 21:49:00 -04003434/**
James Smart3621a712009-04-06 18:47:14 -04003435 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003436 * @vport: pointer to a virtual N_Port data structure.
3437 * @oldiocb: pointer to the original lpfc command iocb data structure.
3438 * @ndlp: pointer to a node-list data structure.
3439 *
3440 * This routine prepares and issues an Accept (ACC) response to Address
3441 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3442 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3443 *
3444 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3445 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3446 * will be stored into the context1 field of the IOCB for the completion
3447 * callback function to the ADISC Accept response ELS IOCB command.
3448 *
3449 * Return code
3450 * 0 - Successfully issued acc adisc response
3451 * 1 - Failed to issue adisc acc response
3452 **/
dea31012005-04-17 16:05:31 -05003453int
James Smart2e0fef82007-06-17 19:56:36 -05003454lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3455 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003456{
James Smart2e0fef82007-06-17 19:56:36 -05003457 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003458 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003459 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003460 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003461 uint8_t *pcmd;
3462 uint16_t cmdsize;
3463 int rc;
3464
James Smart92d7f7b2007-06-17 19:56:38 -05003465 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003466 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3467 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003468 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003469 return 1;
dea31012005-04-17 16:05:31 -05003470
dea31012005-04-17 16:05:31 -05003471 icmd = &elsiocb->iocb;
3472 oldcmd = &oldiocb->iocb;
3473 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003474
3475 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003476 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3477 "0130 Xmit ADISC ACC response iotag x%x xri: "
3478 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3479 elsiocb->iotag, elsiocb->iocb.ulpContext,
3480 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3481 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003482 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3483
3484 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003485 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003486
3487 ap = (ADISC *) (pcmd);
3488 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003489 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3490 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003491 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003492
James Smart858c9f62007-06-17 19:56:39 -05003493 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3494 "Issue ACC ADISC: did:x%x flg:x%x",
3495 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3496
dea31012005-04-17 16:05:31 -05003497 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003498 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003499 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003500 if (rc == IOCB_ERROR) {
3501 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003502 return 1;
dea31012005-04-17 16:05:31 -05003503 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003504 return 0;
dea31012005-04-17 16:05:31 -05003505}
3506
James Smarte59058c2008-08-24 21:49:00 -04003507/**
James Smart3621a712009-04-06 18:47:14 -04003508 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003509 * @vport: pointer to a virtual N_Port data structure.
3510 * @oldiocb: pointer to the original lpfc command iocb data structure.
3511 * @ndlp: pointer to a node-list data structure.
3512 *
3513 * This routine prepares and issues an Accept (ACC) response to Process
3514 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3515 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3516 *
3517 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3518 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3519 * will be stored into the context1 field of the IOCB for the completion
3520 * callback function to the PRLI Accept response ELS IOCB command.
3521 *
3522 * Return code
3523 * 0 - Successfully issued acc prli response
3524 * 1 - Failed to issue acc prli response
3525 **/
dea31012005-04-17 16:05:31 -05003526int
James Smart2e0fef82007-06-17 19:56:36 -05003527lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003528 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003529{
James Smart2e0fef82007-06-17 19:56:36 -05003530 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003531 PRLI *npr;
3532 lpfc_vpd_t *vpd;
3533 IOCB_t *icmd;
3534 IOCB_t *oldcmd;
3535 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003536 struct lpfc_sli *psli;
3537 uint8_t *pcmd;
3538 uint16_t cmdsize;
3539 int rc;
3540
3541 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003542
James Smart92d7f7b2007-06-17 19:56:38 -05003543 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003544 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003545 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003546 if (!elsiocb)
3547 return 1;
dea31012005-04-17 16:05:31 -05003548
dea31012005-04-17 16:05:31 -05003549 icmd = &elsiocb->iocb;
3550 oldcmd = &oldiocb->iocb;
3551 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003552 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003553 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3554 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3555 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3556 elsiocb->iotag, elsiocb->iocb.ulpContext,
3557 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3558 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003559 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3560
3561 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003562 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003563
3564 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003565 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003566
3567 npr = (PRLI *) pcmd;
3568 vpd = &phba->vpd;
3569 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003570 * If the remote port is a target and our firmware version is 3.20 or
3571 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003572 */
James Smart0d2b6b82008-06-14 22:52:47 -04003573 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3574 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003575 npr->ConfmComplAllowed = 1;
3576 npr->Retry = 1;
3577 npr->TaskRetryIdReq = 1;
3578 }
3579
3580 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3581 npr->estabImagePair = 1;
3582 npr->readXferRdyDis = 1;
3583 npr->ConfmComplAllowed = 1;
3584
3585 npr->prliType = PRLI_FCP_TYPE;
3586 npr->initiatorFunc = 1;
3587
James Smart858c9f62007-06-17 19:56:39 -05003588 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3589 "Issue ACC PRLI: did:x%x flg:x%x",
3590 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3591
dea31012005-04-17 16:05:31 -05003592 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003593 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003594
James Smart3772a992009-05-22 14:50:54 -04003595 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003596 if (rc == IOCB_ERROR) {
3597 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003598 return 1;
dea31012005-04-17 16:05:31 -05003599 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003600 return 0;
dea31012005-04-17 16:05:31 -05003601}
3602
James Smarte59058c2008-08-24 21:49:00 -04003603/**
James Smart3621a712009-04-06 18:47:14 -04003604 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003605 * @vport: pointer to a virtual N_Port data structure.
3606 * @format: rnid command format.
3607 * @oldiocb: pointer to the original lpfc command iocb data structure.
3608 * @ndlp: pointer to a node-list data structure.
3609 *
3610 * This routine issues a Request Node Identification Data (RNID) Accept
3611 * (ACC) response. It constructs the RNID ACC response command according to
3612 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3613 * issue the response. Note that this command does not need to hold the ndlp
3614 * reference count for the callback. So, the ndlp reference count taken by
3615 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3616 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3617 * there is no ndlp reference available.
3618 *
3619 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3620 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3621 * will be stored into the context1 field of the IOCB for the completion
3622 * callback function. However, for the RNID Accept Response ELS command,
3623 * this is undone later by this routine after the IOCB is allocated.
3624 *
3625 * Return code
3626 * 0 - Successfully issued acc rnid response
3627 * 1 - Failed to issue acc rnid response
3628 **/
dea31012005-04-17 16:05:31 -05003629static int
James Smart2e0fef82007-06-17 19:56:36 -05003630lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003631 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003632{
James Smart2e0fef82007-06-17 19:56:36 -05003633 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003634 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003635 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003636 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003637 struct lpfc_sli *psli;
3638 uint8_t *pcmd;
3639 uint16_t cmdsize;
3640 int rc;
3641
3642 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003643 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3644 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003645 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003646 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003647
James Smart2e0fef82007-06-17 19:56:36 -05003648 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3649 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003650 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003651 return 1;
dea31012005-04-17 16:05:31 -05003652
dea31012005-04-17 16:05:31 -05003653 icmd = &elsiocb->iocb;
3654 oldcmd = &oldiocb->iocb;
3655 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003656 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003657 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3658 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3659 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003660 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003661 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003662 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003663
James Smart92d7f7b2007-06-17 19:56:38 -05003664 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003665 rn = (RNID *) (pcmd);
3666 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003667 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3668 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3669 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003670 switch (format) {
3671 case 0:
3672 rn->SpecificLen = 0;
3673 break;
3674 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003675 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003676 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003677 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003678 rn->un.topologyDisc.unitType = RNID_HBA;
3679 rn->un.topologyDisc.physPort = 0;
3680 rn->un.topologyDisc.attachedNodes = 0;
3681 break;
3682 default:
3683 rn->CommonLen = 0;
3684 rn->SpecificLen = 0;
3685 break;
3686 }
3687
James Smart858c9f62007-06-17 19:56:39 -05003688 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3689 "Issue ACC RNID: did:x%x flg:x%x",
3690 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3691
dea31012005-04-17 16:05:31 -05003692 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003693 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003694 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003695 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3696 * it could be freed */
3697
James Smart3772a992009-05-22 14:50:54 -04003698 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003699 if (rc == IOCB_ERROR) {
3700 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003701 return 1;
dea31012005-04-17 16:05:31 -05003702 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003703 return 0;
dea31012005-04-17 16:05:31 -05003704}
3705
James Smarte59058c2008-08-24 21:49:00 -04003706/**
James Smart3621a712009-04-06 18:47:14 -04003707 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04003708 * @vport: pointer to a host virtual N_Port data structure.
3709 *
3710 * This routine issues Address Discover (ADISC) ELS commands to those
3711 * N_Ports which are in node port recovery state and ADISC has not been issued
3712 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3713 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3714 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3715 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3716 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3717 * IOCBs quit for later pick up. On the other hand, after walking through
3718 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3719 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3720 * no more ADISC need to be sent.
3721 *
3722 * Return code
3723 * The number of N_Ports with adisc issued.
3724 **/
dea31012005-04-17 16:05:31 -05003725int
James Smart2e0fef82007-06-17 19:56:36 -05003726lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003727{
James Smart2e0fef82007-06-17 19:56:36 -05003728 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003729 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003730 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003731
James Smart685f0bf2007-04-25 09:53:08 -04003732 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05003733 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003734 if (!NLP_CHK_NODE_ACT(ndlp))
3735 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003736 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3737 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3738 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003739 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003740 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05003741 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003742 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003743 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3744 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003745 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05003746 vport->num_disc_nodes++;
3747 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003748 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003749 spin_lock_irq(shost->host_lock);
3750 vport->fc_flag |= FC_NLP_MORE;
3751 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003752 break;
dea31012005-04-17 16:05:31 -05003753 }
3754 }
3755 }
3756 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003757 spin_lock_irq(shost->host_lock);
3758 vport->fc_flag &= ~FC_NLP_MORE;
3759 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003760 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003761 return sentadisc;
dea31012005-04-17 16:05:31 -05003762}
3763
James Smarte59058c2008-08-24 21:49:00 -04003764/**
James Smart3621a712009-04-06 18:47:14 -04003765 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04003766 * @vport: pointer to a host virtual N_Port data structure.
3767 *
3768 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3769 * which are in node port recovery state, with a @vport. Each time an ELS
3770 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3771 * the per @vport number of discover count (num_disc_nodes) shall be
3772 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3773 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3774 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3775 * later pick up. On the other hand, after walking through all the ndlps with
3776 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3777 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3778 * PLOGI need to be sent.
3779 *
3780 * Return code
3781 * The number of N_Ports with plogi issued.
3782 **/
dea31012005-04-17 16:05:31 -05003783int
James Smart2e0fef82007-06-17 19:56:36 -05003784lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003785{
James Smart2e0fef82007-06-17 19:56:36 -05003786 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003787 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003788 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05003789
James Smart2e0fef82007-06-17 19:56:36 -05003790 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3791 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003792 if (!NLP_CHK_NODE_ACT(ndlp))
3793 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003794 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3795 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3796 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
3797 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
3798 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003799 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3800 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003801 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05003802 vport->num_disc_nodes++;
3803 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003804 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003805 spin_lock_irq(shost->host_lock);
3806 vport->fc_flag |= FC_NLP_MORE;
3807 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003808 break;
dea31012005-04-17 16:05:31 -05003809 }
3810 }
3811 }
James Smart87af33f2007-10-27 13:37:43 -04003812 if (sentplogi) {
3813 lpfc_set_disctmo(vport);
3814 }
3815 else {
James Smart2e0fef82007-06-17 19:56:36 -05003816 spin_lock_irq(shost->host_lock);
3817 vport->fc_flag &= ~FC_NLP_MORE;
3818 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003819 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003820 return sentplogi;
dea31012005-04-17 16:05:31 -05003821}
3822
James Smarte59058c2008-08-24 21:49:00 -04003823/**
James Smart3621a712009-04-06 18:47:14 -04003824 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04003825 * @vport: pointer to a host virtual N_Port data structure.
3826 *
3827 * This routine cleans up any Registration State Change Notification
3828 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3829 * @vport together with the host_lock is used to prevent multiple thread
3830 * trying to access the RSCN array on a same @vport at the same time.
3831 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003832void
James Smart2e0fef82007-06-17 19:56:36 -05003833lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003834{
James Smart2e0fef82007-06-17 19:56:36 -05003835 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3836 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003837 int i;
3838
James Smart7f5f3d02008-02-08 18:50:14 -05003839 spin_lock_irq(shost->host_lock);
3840 if (vport->fc_rscn_flush) {
3841 /* Another thread is walking fc_rscn_id_list on this vport */
3842 spin_unlock_irq(shost->host_lock);
3843 return;
3844 }
3845 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3846 vport->fc_rscn_flush = 1;
3847 spin_unlock_irq(shost->host_lock);
3848
James Smart2e0fef82007-06-17 19:56:36 -05003849 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003850 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05003851 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05003852 }
James Smart2e0fef82007-06-17 19:56:36 -05003853 spin_lock_irq(shost->host_lock);
3854 vport->fc_rscn_id_cnt = 0;
3855 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
3856 spin_unlock_irq(shost->host_lock);
3857 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05003858 /* Indicate we are done walking this fc_rscn_id_list */
3859 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05003860}
3861
James Smarte59058c2008-08-24 21:49:00 -04003862/**
James Smart3621a712009-04-06 18:47:14 -04003863 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04003864 * @vport: pointer to a host virtual N_Port data structure.
3865 * @did: remote destination port identifier.
3866 *
3867 * This routine checks whether there is any pending Registration State
3868 * Configuration Notification (RSCN) to a @did on @vport.
3869 *
3870 * Return code
3871 * None zero - The @did matched with a pending rscn
3872 * 0 - not able to match @did with a pending rscn
3873 **/
dea31012005-04-17 16:05:31 -05003874int
James Smart2e0fef82007-06-17 19:56:36 -05003875lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05003876{
3877 D_ID ns_did;
3878 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05003879 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05003880 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05003881 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003882
3883 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05003884
3885 /* Never match fabric nodes for RSCNs */
3886 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05003887 return 0;
dea31012005-04-17 16:05:31 -05003888
3889 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05003890 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003891 return did;
dea31012005-04-17 16:05:31 -05003892
James Smart7f5f3d02008-02-08 18:50:14 -05003893 spin_lock_irq(shost->host_lock);
3894 if (vport->fc_rscn_flush) {
3895 /* Another thread is walking fc_rscn_id_list on this vport */
3896 spin_unlock_irq(shost->host_lock);
3897 return 0;
3898 }
3899 /* Indicate we are walking fc_rscn_id_list on this vport */
3900 vport->fc_rscn_flush = 1;
3901 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003902 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003903 lp = vport->fc_rscn_id_list[i]->virt;
3904 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3905 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05003906 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05003907 rscn_did.un.word = be32_to_cpu(*lp++);
3908 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05003909 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
3910 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04003911 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
3912 && (ns_did.un.b.area == rscn_did.un.b.area)
3913 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05003914 goto return_did_out;
dea31012005-04-17 16:05:31 -05003915 break;
James Smarteaf15d52008-12-04 22:39:29 -05003916 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05003917 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
3918 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05003919 goto return_did_out;
dea31012005-04-17 16:05:31 -05003920 break;
James Smarteaf15d52008-12-04 22:39:29 -05003921 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05003922 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05003923 goto return_did_out;
dea31012005-04-17 16:05:31 -05003924 break;
James Smarteaf15d52008-12-04 22:39:29 -05003925 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05003926 goto return_did_out;
dea31012005-04-17 16:05:31 -05003927 }
3928 }
James Smart92d7f7b2007-06-17 19:56:38 -05003929 }
James Smart7f5f3d02008-02-08 18:50:14 -05003930 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3931 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003932 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05003933return_did_out:
3934 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3935 vport->fc_rscn_flush = 0;
3936 return did;
dea31012005-04-17 16:05:31 -05003937}
3938
James Smarte59058c2008-08-24 21:49:00 -04003939/**
James Smart3621a712009-04-06 18:47:14 -04003940 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04003941 * @vport: pointer to a host virtual N_Port data structure.
3942 *
3943 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
3944 * state machine for a @vport's nodes that are with pending RSCN (Registration
3945 * State Change Notification).
3946 *
3947 * Return code
3948 * 0 - Successful (currently alway return 0)
3949 **/
dea31012005-04-17 16:05:31 -05003950static int
James Smart2e0fef82007-06-17 19:56:36 -05003951lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003952{
James Smart685f0bf2007-04-25 09:53:08 -04003953 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05003954
James Smart0d2b6b82008-06-14 22:52:47 -04003955 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05003956 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003957 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04003958 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
3959 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05003960 continue;
James Smart2e0fef82007-06-17 19:56:36 -05003961 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04003962 NLP_EVT_DEVICE_RECOVERY);
3963 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05003964 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003965 return 0;
dea31012005-04-17 16:05:31 -05003966}
3967
James Smarte59058c2008-08-24 21:49:00 -04003968/**
James Smart3621a712009-04-06 18:47:14 -04003969 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05003970 * @vport: pointer to a host virtual N_Port data structure.
3971 * @cmdiocb: pointer to lpfc command iocb data structure.
3972 *
3973 * lpfc_send_rscn_event sends an RSCN netlink event to management
3974 * applications.
3975 */
3976static void
3977lpfc_send_rscn_event(struct lpfc_vport *vport,
3978 struct lpfc_iocbq *cmdiocb)
3979{
3980 struct lpfc_dmabuf *pcmd;
3981 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3982 uint32_t *payload_ptr;
3983 uint32_t payload_len;
3984 struct lpfc_rscn_event_header *rscn_event_data;
3985
3986 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3987 payload_ptr = (uint32_t *) pcmd->virt;
3988 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
3989
3990 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
3991 payload_len, GFP_KERNEL);
3992 if (!rscn_event_data) {
3993 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3994 "0147 Failed to allocate memory for RSCN event\n");
3995 return;
3996 }
3997 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
3998 rscn_event_data->payload_length = payload_len;
3999 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4000 payload_len);
4001
4002 fc_host_post_vendor_event(shost,
4003 fc_get_event_number(),
4004 sizeof(struct lpfc_els_event_header) + payload_len,
4005 (char *)rscn_event_data,
4006 LPFC_NL_VENDOR_ID);
4007
4008 kfree(rscn_event_data);
4009}
4010
4011/**
James Smart3621a712009-04-06 18:47:14 -04004012 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004013 * @vport: pointer to a host virtual N_Port data structure.
4014 * @cmdiocb: pointer to lpfc command iocb data structure.
4015 * @ndlp: pointer to a node-list data structure.
4016 *
4017 * This routine processes an unsolicited RSCN (Registration State Change
4018 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4019 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4020 * discover state machine is about to begin discovery, it just accepts the
4021 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4022 * contains N_Port IDs for other vports on this HBA, it just accepts the
4023 * RSCN and ignore processing it. If the state machine is in the recovery
4024 * state, the fc_rscn_id_list of this @vport is walked and the
4025 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4026 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4027 * routine is invoked to handle the RSCN event.
4028 *
4029 * Return code
4030 * 0 - Just sent the acc response
4031 * 1 - Sent the acc response and waited for name server completion
4032 **/
dea31012005-04-17 16:05:31 -05004033static int
James Smart2e0fef82007-06-17 19:56:36 -05004034lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004035 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004036{
James Smart2e0fef82007-06-17 19:56:36 -05004037 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4038 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004039 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004040 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004041 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004042 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004043 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004044 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004045 int i;
dea31012005-04-17 16:05:31 -05004046
4047 icmd = &cmdiocb->iocb;
4048 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4049 lp = (uint32_t *) pcmd->virt;
4050
James Smart92d7f7b2007-06-17 19:56:38 -05004051 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4052 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004053 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004054 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4055 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004056 vport->fc_flag, payload_len, *lp,
4057 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004058
4059 /* Send an RSCN event to the management application */
4060 lpfc_send_rscn_event(vport, cmdiocb);
4061
James Smartd2873e42006-08-18 17:46:43 -04004062 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004063 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004064 FCH_EVT_RSCN, lp[i]);
4065
dea31012005-04-17 16:05:31 -05004066 /* If we are about to begin discovery, just ACC the RSCN.
4067 * Discovery processing will satisfy it.
4068 */
James Smart2e0fef82007-06-17 19:56:36 -05004069 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004070 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4071 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4072 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4073
James Smart51ef4c22007-08-02 11:10:31 -04004074 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004075 return 0;
dea31012005-04-17 16:05:31 -05004076 }
4077
James Smart92d7f7b2007-06-17 19:56:38 -05004078 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4079 * just ACC and ignore it.
4080 */
4081 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004082 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004083 i = payload_len;
4084 datap = lp;
4085 while (i > 0) {
4086 nportid = *datap++;
4087 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4088 i -= sizeof(uint32_t);
4089 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004090 if (lpfc_find_vport_by_did(phba, nportid))
4091 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004092 }
4093 if (rscn_id == hba_id) {
4094 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004095 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004096 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004097 "Data: x%x x%x x%x x%x\n",
4098 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004099 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004100 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4101 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4102 ndlp->nlp_DID, vport->port_state,
4103 ndlp->nlp_flag);
4104
James Smart92d7f7b2007-06-17 19:56:38 -05004105 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004106 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004107 return 0;
4108 }
4109 }
4110
James Smart7f5f3d02008-02-08 18:50:14 -05004111 spin_lock_irq(shost->host_lock);
4112 if (vport->fc_rscn_flush) {
4113 /* Another thread is walking fc_rscn_id_list on this vport */
4114 spin_unlock_irq(shost->host_lock);
4115 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart58da1ff2008-04-07 10:15:56 -04004116 /* Send back ACC */
4117 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004118 return 0;
4119 }
4120 /* Indicate we are walking fc_rscn_id_list on this vport */
4121 vport->fc_rscn_flush = 1;
4122 spin_unlock_irq(shost->host_lock);
4123 /* Get the array count after sucessfully have the token */
4124 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004125 /* If we are already processing an RSCN, save the received
4126 * RSCN payload buffer, cmdiocb->context2 to process later.
4127 */
James Smart2e0fef82007-06-17 19:56:36 -05004128 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004129 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4130 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4131 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4132
James Smart09372822008-01-11 01:52:54 -05004133 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004134 vport->fc_flag |= FC_RSCN_DEFERRED;
4135 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004136 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004137 vport->fc_flag |= FC_RSCN_MODE;
4138 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004139 if (rscn_cnt) {
4140 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4141 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4142 }
4143 if ((rscn_cnt) &&
4144 (payload_len + length <= LPFC_BPL_SIZE)) {
4145 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004146 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004147 memcpy(((uint8_t *)cmd) + length, lp,
4148 payload_len);
4149 } else {
4150 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4151 vport->fc_rscn_id_cnt++;
4152 /* If we zero, cmdiocb->context2, the calling
4153 * routine will not try to free it.
4154 */
4155 cmdiocb->context2 = NULL;
4156 }
dea31012005-04-17 16:05:31 -05004157 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004158 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4159 "0235 Deferred RSCN "
4160 "Data: x%x x%x x%x\n",
4161 vport->fc_rscn_id_cnt, vport->fc_flag,
4162 vport->port_state);
dea31012005-04-17 16:05:31 -05004163 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004164 vport->fc_flag |= FC_RSCN_DISCOVERY;
4165 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004166 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004167 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4168 "0234 ReDiscovery RSCN "
4169 "Data: x%x x%x x%x\n",
4170 vport->fc_rscn_id_cnt, vport->fc_flag,
4171 vport->port_state);
dea31012005-04-17 16:05:31 -05004172 }
James Smart7f5f3d02008-02-08 18:50:14 -05004173 /* Indicate we are done walking fc_rscn_id_list on this vport */
4174 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004175 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004176 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004177 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004178 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004179 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004180 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004181 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004182 return 0;
dea31012005-04-17 16:05:31 -05004183 }
James Smart858c9f62007-06-17 19:56:39 -05004184 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4185 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4186 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4187
James Smart2e0fef82007-06-17 19:56:36 -05004188 spin_lock_irq(shost->host_lock);
4189 vport->fc_flag |= FC_RSCN_MODE;
4190 spin_unlock_irq(shost->host_lock);
4191 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004192 /* Indicate we are done walking fc_rscn_id_list on this vport */
4193 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004194 /*
4195 * If we zero, cmdiocb->context2, the calling routine will
4196 * not try to free it.
4197 */
4198 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004199 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004200 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004201 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004202 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004203 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004204 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004205}
4206
James Smarte59058c2008-08-24 21:49:00 -04004207/**
James Smart3621a712009-04-06 18:47:14 -04004208 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004209 * @vport: pointer to a host virtual N_Port data structure.
4210 *
4211 * This routine handles the Registration State Configuration Notification
4212 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4213 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4214 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4215 * NameServer shall be issued. If CT command to the NameServer fails to be
4216 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4217 * RSCN activities with the @vport.
4218 *
4219 * Return code
4220 * 0 - Cleaned up rscn on the @vport
4221 * 1 - Wait for plogi to name server before proceed
4222 **/
dea31012005-04-17 16:05:31 -05004223int
James Smart2e0fef82007-06-17 19:56:36 -05004224lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004225{
4226 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004227 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004228
James Smart92d7f7b2007-06-17 19:56:38 -05004229 /* Ignore RSCN if the port is being torn down. */
4230 if (vport->load_flag & FC_UNLOADING) {
4231 lpfc_els_flush_rscn(vport);
4232 return 0;
4233 }
4234
dea31012005-04-17 16:05:31 -05004235 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004236 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004237
4238 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004239 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4240 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4241 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4242 vport->port_state);
dea31012005-04-17 16:05:31 -05004243
4244 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004245 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004246 vport->num_disc_nodes = 0;
4247
James Smart2e0fef82007-06-17 19:56:36 -05004248 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004249 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4250 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004251 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004252 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004253 /* Wait for NameServer query cmpl before we can
4254 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004255 return 1;
dea31012005-04-17 16:05:31 -05004256 } else {
4257 /* If login to NameServer does not exist, issue one */
4258 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004259 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004260 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004261 /* Wait for NameServer login cmpl before we can
4262 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004263 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004264
James Smarte47c9092008-02-08 18:49:26 -05004265 if (ndlp) {
4266 ndlp = lpfc_enable_node(vport, ndlp,
4267 NLP_STE_PLOGI_ISSUE);
4268 if (!ndlp) {
4269 lpfc_els_flush_rscn(vport);
4270 return 0;
4271 }
4272 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004273 } else {
James Smarte47c9092008-02-08 18:49:26 -05004274 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4275 if (!ndlp) {
4276 lpfc_els_flush_rscn(vport);
4277 return 0;
4278 }
James Smart2e0fef82007-06-17 19:56:36 -05004279 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004280 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004281 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004282 }
James Smarte47c9092008-02-08 18:49:26 -05004283 ndlp->nlp_type |= NLP_FABRIC;
4284 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4285 /* Wait for NameServer login cmpl before we can
4286 * continue
4287 */
4288 return 1;
dea31012005-04-17 16:05:31 -05004289 }
4290
James Smart2e0fef82007-06-17 19:56:36 -05004291 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004292 return 0;
dea31012005-04-17 16:05:31 -05004293}
4294
James Smarte59058c2008-08-24 21:49:00 -04004295/**
James Smart3621a712009-04-06 18:47:14 -04004296 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004297 * @vport: pointer to a host virtual N_Port data structure.
4298 * @cmdiocb: pointer to lpfc command iocb data structure.
4299 * @ndlp: pointer to a node-list data structure.
4300 *
4301 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4302 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4303 * point topology. As an unsolicited FLOGI should not be received in a loop
4304 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4305 * lpfc_check_sparm() routine is invoked to check the parameters in the
4306 * unsolicited FLOGI. If parameters validation failed, the routine
4307 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4308 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4309 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4310 * will initiate PLOGI. The higher lexicographical value party shall has
4311 * higher priority (as the winning port) and will initiate PLOGI and
4312 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4313 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4314 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4315 *
4316 * Return code
4317 * 0 - Successfully processed the unsolicited flogi
4318 * 1 - Failed to process the unsolicited flogi
4319 **/
dea31012005-04-17 16:05:31 -05004320static int
James Smart2e0fef82007-06-17 19:56:36 -05004321lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004322 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004323{
James Smart2e0fef82007-06-17 19:56:36 -05004324 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4325 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004326 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4327 uint32_t *lp = (uint32_t *) pcmd->virt;
4328 IOCB_t *icmd = &cmdiocb->iocb;
4329 struct serv_parm *sp;
4330 LPFC_MBOXQ_t *mbox;
4331 struct ls_rjt stat;
4332 uint32_t cmd, did;
4333 int rc;
4334
4335 cmd = *lp++;
4336 sp = (struct serv_parm *) lp;
4337
4338 /* FLOGI received */
4339
James Smart2e0fef82007-06-17 19:56:36 -05004340 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004341
4342 if (phba->fc_topology == TOPOLOGY_LOOP) {
4343 /* We should never receive a FLOGI in loop mode, ignore it */
4344 did = icmd->un.elsreq64.remoteID;
4345
4346 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4347 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004348 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4349 "0113 An FLOGI ELS command x%x was "
4350 "received from DID x%x in Loop Mode\n",
4351 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004352 return 1;
dea31012005-04-17 16:05:31 -05004353 }
4354
4355 did = Fabric_DID;
4356
James Smart2e0fef82007-06-17 19:56:36 -05004357 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
dea31012005-04-17 16:05:31 -05004358 /* For a FLOGI we accept, then if our portname is greater
4359 * then the remote portname we initiate Nport login.
4360 */
4361
James Smart2e0fef82007-06-17 19:56:36 -05004362 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004363 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004364
4365 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004366 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4367 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004368 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004369
dea31012005-04-17 16:05:31 -05004370 lpfc_linkdown(phba);
4371 lpfc_init_link(phba, mbox,
4372 phba->cfg_topology,
4373 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004374 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004375 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004376 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004377 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004378 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004379 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004380 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004381 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004382 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004383 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004384 spin_lock_irq(shost->host_lock);
4385 vport->fc_flag |= FC_PT2PT_PLOGI;
4386 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004387 }
James Smart2e0fef82007-06-17 19:56:36 -05004388 spin_lock_irq(shost->host_lock);
4389 vport->fc_flag |= FC_PT2PT;
4390 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4391 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004392 } else {
4393 /* Reject this request because invalid parameters */
4394 stat.un.b.lsRjtRsvd0 = 0;
4395 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4396 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4397 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004398 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4399 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004400 return 1;
dea31012005-04-17 16:05:31 -05004401 }
4402
4403 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004404 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004405
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004406 return 0;
dea31012005-04-17 16:05:31 -05004407}
4408
James Smarte59058c2008-08-24 21:49:00 -04004409/**
James Smart3621a712009-04-06 18:47:14 -04004410 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004411 * @vport: pointer to a host virtual N_Port data structure.
4412 * @cmdiocb: pointer to lpfc command iocb data structure.
4413 * @ndlp: pointer to a node-list data structure.
4414 *
4415 * This routine processes Request Node Identification Data (RNID) IOCB
4416 * received as an ELS unsolicited event. Only when the RNID specified format
4417 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4418 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4419 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4420 * rejected by invoking the lpfc_els_rsp_reject() routine.
4421 *
4422 * Return code
4423 * 0 - Successfully processed rnid iocb (currently always return 0)
4424 **/
dea31012005-04-17 16:05:31 -05004425static int
James Smart2e0fef82007-06-17 19:56:36 -05004426lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4427 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004428{
4429 struct lpfc_dmabuf *pcmd;
4430 uint32_t *lp;
4431 IOCB_t *icmd;
4432 RNID *rn;
4433 struct ls_rjt stat;
4434 uint32_t cmd, did;
4435
4436 icmd = &cmdiocb->iocb;
4437 did = icmd->un.elsreq64.remoteID;
4438 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4439 lp = (uint32_t *) pcmd->virt;
4440
4441 cmd = *lp++;
4442 rn = (RNID *) lp;
4443
4444 /* RNID received */
4445
4446 switch (rn->Format) {
4447 case 0:
4448 case RNID_TOPOLOGY_DISC:
4449 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004450 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004451 break;
4452 default:
4453 /* Reject this request because format not supported */
4454 stat.un.b.lsRjtRsvd0 = 0;
4455 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4456 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4457 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004458 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4459 NULL);
dea31012005-04-17 16:05:31 -05004460 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004461 return 0;
dea31012005-04-17 16:05:31 -05004462}
4463
James Smarte59058c2008-08-24 21:49:00 -04004464/**
James Smart3621a712009-04-06 18:47:14 -04004465 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004466 * @vport: pointer to a host virtual N_Port data structure.
4467 * @cmdiocb: pointer to lpfc command iocb data structure.
4468 * @ndlp: pointer to a node-list data structure.
4469 *
4470 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4471 * received as an ELS unsolicited event. Currently, this function just invokes
4472 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4473 *
4474 * Return code
4475 * 0 - Successfully processed lirr iocb (currently always return 0)
4476 **/
dea31012005-04-17 16:05:31 -05004477static int
James Smart2e0fef82007-06-17 19:56:36 -05004478lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4479 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004480{
4481 struct ls_rjt stat;
4482
4483 /* For now, unconditionally reject this command */
4484 stat.un.b.lsRjtRsvd0 = 0;
4485 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4486 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4487 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004488 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004489 return 0;
4490}
4491
James Smarte59058c2008-08-24 21:49:00 -04004492/**
James Smart3621a712009-04-06 18:47:14 -04004493 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004494 * @phba: pointer to lpfc hba data structure.
4495 * @pmb: pointer to the driver internal queue element for mailbox command.
4496 *
4497 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4498 * mailbox command. This callback function is to actually send the Accept
4499 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4500 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4501 * mailbox command, constructs the RPS response with the link statistics
4502 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4503 * response to the RPS.
4504 *
4505 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4506 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4507 * will be stored into the context1 field of the IOCB for the completion
4508 * callback function to the RPS Accept Response ELS IOCB command.
4509 *
4510 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004511static void
James Smart329f9bc2007-04-25 09:53:01 -04004512lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004513{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004514 MAILBOX_t *mb;
4515 IOCB_t *icmd;
4516 RPS_RSP *rps_rsp;
4517 uint8_t *pcmd;
4518 struct lpfc_iocbq *elsiocb;
4519 struct lpfc_nodelist *ndlp;
4520 uint16_t xri, status;
4521 uint32_t cmdsize;
4522
James Smart04c68492009-05-22 14:52:52 -04004523 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004524
4525 ndlp = (struct lpfc_nodelist *) pmb->context2;
4526 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004527 pmb->context1 = NULL;
4528 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004529
4530 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004531 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004532 return;
4533 }
4534
4535 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004536 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004537 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4538 lpfc_max_els_tries, ndlp,
4539 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004540
4541 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004542 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004543
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004544 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004545 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004546
4547 icmd = &elsiocb->iocb;
4548 icmd->ulpContext = xri;
4549
4550 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4551 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004552 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004553 rps_rsp = (RPS_RSP *)pcmd;
4554
4555 if (phba->fc_topology != TOPOLOGY_LOOP)
4556 status = 0x10;
4557 else
4558 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004559 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004560 status |= 0x4;
4561
4562 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004563 rps_rsp->portStatus = cpu_to_be16(status);
4564 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4565 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4566 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4567 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4568 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4569 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004570 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004571 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4572 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4573 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4574 elsiocb->iotag, elsiocb->iocb.ulpContext,
4575 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4576 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004577 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004578 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004579 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004580 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004581 return;
4582}
4583
James Smarte59058c2008-08-24 21:49:00 -04004584/**
James Smart3621a712009-04-06 18:47:14 -04004585 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04004586 * @vport: pointer to a host virtual N_Port data structure.
4587 * @cmdiocb: pointer to lpfc command iocb data structure.
4588 * @ndlp: pointer to a node-list data structure.
4589 *
4590 * This routine processes Read Port Status (RPS) IOCB received as an
4591 * ELS unsolicited event. It first checks the remote port state. If the
4592 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4593 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4594 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4595 * for reading the HBA link statistics. It is for the callback function,
4596 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4597 * to actually sending out RPS Accept (ACC) response.
4598 *
4599 * Return codes
4600 * 0 - Successfully processed rps iocb (currently always return 0)
4601 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004602static int
James Smart2e0fef82007-06-17 19:56:36 -05004603lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4604 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004605{
James Smart2e0fef82007-06-17 19:56:36 -05004606 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004607 uint32_t *lp;
4608 uint8_t flag;
4609 LPFC_MBOXQ_t *mbox;
4610 struct lpfc_dmabuf *pcmd;
4611 RPS *rps;
4612 struct ls_rjt stat;
4613
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004614 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04004615 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4616 /* reject the unsolicited RPS request and done with it */
4617 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004618
4619 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4620 lp = (uint32_t *) pcmd->virt;
4621 flag = (be32_to_cpu(*lp++) & 0xf);
4622 rps = (RPS *) lp;
4623
4624 if ((flag == 0) ||
4625 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05004626 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004627 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05004628
James Smart92d7f7b2007-06-17 19:56:38 -05004629 printk("Fix me....\n");
4630 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05004631 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4632 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004633 lpfc_read_lnk_stat(phba, mbox);
4634 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05004635 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04004636 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004637 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004638 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05004639 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04004640 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004641 /* Mbox completion will send ELS Response */
4642 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05004643 /* Decrement reference count used for the failed mbox
4644 * command.
4645 */
James Smart329f9bc2007-04-25 09:53:01 -04004646 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004647 mempool_free(mbox, phba->mbox_mem_pool);
4648 }
4649 }
James Smart90160e02008-08-24 21:49:45 -04004650
4651reject_out:
4652 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004653 stat.un.b.lsRjtRsvd0 = 0;
4654 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4655 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4656 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004657 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004658 return 0;
4659}
4660
James Smarte59058c2008-08-24 21:49:00 -04004661/**
James Smart3621a712009-04-06 18:47:14 -04004662 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04004663 * @vport: pointer to a host virtual N_Port data structure.
4664 * @cmdsize: size of the ELS command.
4665 * @oldiocb: pointer to the original lpfc command iocb data structure.
4666 * @ndlp: pointer to a node-list data structure.
4667 *
4668 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4669 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4670 *
4671 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4672 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4673 * will be stored into the context1 field of the IOCB for the completion
4674 * callback function to the RPL Accept Response ELS command.
4675 *
4676 * Return code
4677 * 0 - Successfully issued ACC RPL ELS command
4678 * 1 - Failed to issue ACC RPL ELS command
4679 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004680static int
James Smart2e0fef82007-06-17 19:56:36 -05004681lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4682 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004683{
James Smart2e0fef82007-06-17 19:56:36 -05004684 struct lpfc_hba *phba = vport->phba;
4685 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004686 RPL_RSP rpl_rsp;
4687 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004688 uint8_t *pcmd;
4689
James Smart2e0fef82007-06-17 19:56:36 -05004690 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4691 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004692
James Smart488d1462006-03-07 15:02:37 -05004693 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004694 return 1;
James Smart488d1462006-03-07 15:02:37 -05004695
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004696 icmd = &elsiocb->iocb;
4697 oldcmd = &oldiocb->iocb;
4698 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4699
4700 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4701 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004702 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004703 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4704 pcmd += sizeof(uint16_t);
4705
4706 /* Setup the RPL ACC payload */
4707 rpl_rsp.listLen = be32_to_cpu(1);
4708 rpl_rsp.index = 0;
4709 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004710 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4711 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004712 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004713 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004714 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004715 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4716 "0120 Xmit ELS RPL ACC response tag x%x "
4717 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4718 "rpi x%x\n",
4719 elsiocb->iotag, elsiocb->iocb.ulpContext,
4720 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4721 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004722 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004723 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004724 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
4725 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004726 lpfc_els_free_iocb(phba, elsiocb);
4727 return 1;
4728 }
4729 return 0;
4730}
4731
James Smarte59058c2008-08-24 21:49:00 -04004732/**
James Smart3621a712009-04-06 18:47:14 -04004733 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04004734 * @vport: pointer to a host virtual N_Port data structure.
4735 * @cmdiocb: pointer to lpfc command iocb data structure.
4736 * @ndlp: pointer to a node-list data structure.
4737 *
4738 * This routine processes Read Port List (RPL) IOCB received as an ELS
4739 * unsolicited event. It first checks the remote port state. If the remote
4740 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4741 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4742 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4743 * to accept the RPL.
4744 *
4745 * Return code
4746 * 0 - Successfully processed rpl iocb (currently always return 0)
4747 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004748static int
James Smart2e0fef82007-06-17 19:56:36 -05004749lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4750 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004751{
4752 struct lpfc_dmabuf *pcmd;
4753 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004754 uint32_t maxsize;
4755 uint16_t cmdsize;
4756 RPL *rpl;
4757 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05004758
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004759 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4760 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04004761 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004762 stat.un.b.lsRjtRsvd0 = 0;
4763 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4764 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4765 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004766 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4767 NULL);
James Smart90160e02008-08-24 21:49:45 -04004768 /* rejected the unsolicited RPL request and done with it */
4769 return 0;
dea31012005-04-17 16:05:31 -05004770 }
4771
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004772 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4773 lp = (uint32_t *) pcmd->virt;
4774 rpl = (RPL *) (lp + 1);
4775
4776 maxsize = be32_to_cpu(rpl->maxsize);
4777
4778 /* We support only one port */
4779 if ((rpl->index == 0) &&
4780 ((maxsize == 0) ||
4781 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
4782 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004783 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004784 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
4785 }
James Smart2e0fef82007-06-17 19:56:36 -05004786 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004787
4788 return 0;
4789}
4790
James Smarte59058c2008-08-24 21:49:00 -04004791/**
James Smart3621a712009-04-06 18:47:14 -04004792 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04004793 * @vport: pointer to a virtual N_Port data structure.
4794 * @cmdiocb: pointer to lpfc command iocb data structure.
4795 * @ndlp: pointer to a node-list data structure.
4796 *
4797 * This routine processes Fibre Channel Address Resolution Protocol
4798 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4799 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4800 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4801 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4802 * remote PortName is compared against the FC PortName stored in the @vport
4803 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4804 * compared against the FC NodeName stored in the @vport data structure.
4805 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4806 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4807 * invoked to send out FARP Response to the remote node. Before sending the
4808 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4809 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4810 * routine is invoked to log into the remote port first.
4811 *
4812 * Return code
4813 * 0 - Either the FARP Match Mode not supported or successfully processed
4814 **/
dea31012005-04-17 16:05:31 -05004815static int
James Smart2e0fef82007-06-17 19:56:36 -05004816lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4817 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004818{
4819 struct lpfc_dmabuf *pcmd;
4820 uint32_t *lp;
4821 IOCB_t *icmd;
4822 FARP *fp;
4823 uint32_t cmd, cnt, did;
4824
4825 icmd = &cmdiocb->iocb;
4826 did = icmd->un.elsreq64.remoteID;
4827 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4828 lp = (uint32_t *) pcmd->virt;
4829
4830 cmd = *lp++;
4831 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05004832 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004833 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4834 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004835 /* We will only support match on WWPN or WWNN */
4836 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004837 return 0;
dea31012005-04-17 16:05:31 -05004838 }
4839
4840 cnt = 0;
4841 /* If this FARP command is searching for my portname */
4842 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05004843 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004844 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004845 cnt = 1;
4846 }
4847
4848 /* If this FARP command is searching for my nodename */
4849 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05004850 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05004851 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004852 cnt = 1;
4853 }
4854
4855 if (cnt) {
4856 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
4857 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
4858 /* Log back into the node before sending the FARP. */
4859 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004860 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004861 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04004862 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05004863 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05004864 }
4865
4866 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05004867 if (fp->Rflags & FARP_REQUEST_FARPR)
4868 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05004869 }
4870 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004871 return 0;
dea31012005-04-17 16:05:31 -05004872}
4873
James Smarte59058c2008-08-24 21:49:00 -04004874/**
James Smart3621a712009-04-06 18:47:14 -04004875 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04004876 * @vport: pointer to a host virtual N_Port data structure.
4877 * @cmdiocb: pointer to lpfc command iocb data structure.
4878 * @ndlp: pointer to a node-list data structure.
4879 *
4880 * This routine processes Fibre Channel Address Resolution Protocol
4881 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
4882 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
4883 * the FARP response request.
4884 *
4885 * Return code
4886 * 0 - Successfully processed FARPR IOCB (currently always return 0)
4887 **/
dea31012005-04-17 16:05:31 -05004888static int
James Smart2e0fef82007-06-17 19:56:36 -05004889lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4890 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004891{
4892 struct lpfc_dmabuf *pcmd;
4893 uint32_t *lp;
4894 IOCB_t *icmd;
4895 uint32_t cmd, did;
4896
4897 icmd = &cmdiocb->iocb;
4898 did = icmd->un.elsreq64.remoteID;
4899 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4900 lp = (uint32_t *) pcmd->virt;
4901
4902 cmd = *lp++;
4903 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004904 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4905 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004906 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04004907 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004908
4909 return 0;
4910}
4911
James Smarte59058c2008-08-24 21:49:00 -04004912/**
James Smart3621a712009-04-06 18:47:14 -04004913 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04004914 * @vport: pointer to a host virtual N_Port data structure.
4915 * @cmdiocb: pointer to lpfc command iocb data structure.
4916 * @fan_ndlp: pointer to a node-list data structure.
4917 *
4918 * This routine processes a Fabric Address Notification (FAN) IOCB
4919 * command received as an ELS unsolicited event. The FAN ELS command will
4920 * only be processed on a physical port (i.e., the @vport represents the
4921 * physical port). The fabric NodeName and PortName from the FAN IOCB are
4922 * compared against those in the phba data structure. If any of those is
4923 * different, the lpfc_initial_flogi() routine is invoked to initialize
4924 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
4925 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
4926 * is invoked to register login to the fabric.
4927 *
4928 * Return code
4929 * 0 - Successfully processed fan iocb (currently always return 0).
4930 **/
dea31012005-04-17 16:05:31 -05004931static int
James Smart2e0fef82007-06-17 19:56:36 -05004932lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4933 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05004934{
James Smart2e0fef82007-06-17 19:56:36 -05004935 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04004936 uint32_t *lp;
4937 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004938
James Smart0d2b6b82008-06-14 22:52:47 -04004939 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
4940 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
4941 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004942 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04004943 if ((vport == phba->pport) &&
4944 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004945 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04004946 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004947 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04004948 sizeof(struct lpfc_name)))) {
4949 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05004950 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04004951 } else {
4952 /* FAN verified - skip FLOGI */
4953 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04004954 if (phba->sli_rev < LPFC_SLI_REV4)
4955 lpfc_issue_fabric_reglogin(vport);
4956 else
4957 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05004958 }
dea31012005-04-17 16:05:31 -05004959 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004960 return 0;
dea31012005-04-17 16:05:31 -05004961}
4962
James Smarte59058c2008-08-24 21:49:00 -04004963/**
James Smart3621a712009-04-06 18:47:14 -04004964 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04004965 * @ptr: holder for the timer function associated data.
4966 *
4967 * This routine is invoked by the ELS timer after timeout. It posts the ELS
4968 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
4969 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
4970 * up the worker thread. It is for the worker thread to invoke the routine
4971 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
4972 **/
dea31012005-04-17 16:05:31 -05004973void
4974lpfc_els_timeout(unsigned long ptr)
4975{
James Smart2e0fef82007-06-17 19:56:36 -05004976 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
4977 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04004978 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05004979 unsigned long iflag;
4980
James Smart2e0fef82007-06-17 19:56:36 -05004981 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04004982 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
4983 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05004984 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04004985 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05004986
James Smart5e9d9b82008-06-14 22:52:53 -04004987 if (!tmo_posted)
4988 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05004989 return;
4990}
4991
James Smarte59058c2008-08-24 21:49:00 -04004992/**
James Smart3621a712009-04-06 18:47:14 -04004993 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04004994 * @vport: pointer to a virtual N_Port data structure.
4995 *
4996 * This routine is the actual handler function that processes an ELS timeout
4997 * event. It walks the ELS ring to get and abort all the IOCBs (except the
4998 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
4999 * invoking the lpfc_sli_issue_abort_iotag() routine.
5000 **/
dea31012005-04-17 16:05:31 -05005001void
James Smart2e0fef82007-06-17 19:56:36 -05005002lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005003{
James Smart2e0fef82007-06-17 19:56:36 -05005004 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005005 struct lpfc_sli_ring *pring;
5006 struct lpfc_iocbq *tmp_iocb, *piocb;
5007 IOCB_t *cmd = NULL;
5008 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005009 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005010 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005011 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05005012
James Smart2e0fef82007-06-17 19:56:36 -05005013 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005014 timeout = (uint32_t)(phba->fc_ratov << 1);
5015
5016 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005017
5018 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5019 cmd = &piocb->iocb;
5020
James Smart2e0fef82007-06-17 19:56:36 -05005021 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5022 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5023 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005024 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005025
5026 if (piocb->vport != vport)
5027 continue;
5028
dea31012005-04-17 16:05:31 -05005029 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005030 if (pcmd)
5031 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005032
James Smart92d7f7b2007-06-17 19:56:38 -05005033 if (els_command == ELS_CMD_FARP ||
5034 els_command == ELS_CMD_FARPR ||
5035 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005036 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005037
dea31012005-04-17 16:05:31 -05005038 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005039 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005040 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005041 else
dea31012005-04-17 16:05:31 -05005042 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005043 continue;
5044 }
5045
James Smart2e0fef82007-06-17 19:56:36 -05005046 remote_ID = 0xffffffff;
5047 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005048 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005049 else {
5050 struct lpfc_nodelist *ndlp;
5051 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005052 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005053 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005054 }
James Smarte8b62012007-08-02 11:10:09 -04005055 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5056 "0127 ELS timeout Data: x%x x%x x%x "
5057 "x%x\n", els_command,
5058 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04005059 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005060 }
James Smart2e0fef82007-06-17 19:56:36 -05005061 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005062
James Smart2e0fef82007-06-17 19:56:36 -05005063 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5064 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005065}
5066
James Smarte59058c2008-08-24 21:49:00 -04005067/**
James Smart3621a712009-04-06 18:47:14 -04005068 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005069 * @vport: pointer to a host virtual N_Port data structure.
5070 *
5071 * This routine is used to clean up all the outstanding ELS commands on a
5072 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5073 * routine. After that, it walks the ELS transmit queue to remove all the
5074 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5075 * the IOCBs with a non-NULL completion callback function, the callback
5076 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5077 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5078 * callback function, the IOCB will simply be released. Finally, it walks
5079 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5080 * completion queue IOCB that is associated with the @vport and is not
5081 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5082 * part of the discovery state machine) out to HBA by invoking the
5083 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5084 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5085 * the IOCBs are aborted when this function returns.
5086 **/
dea31012005-04-17 16:05:31 -05005087void
James Smart2e0fef82007-06-17 19:56:36 -05005088lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005089{
James Smart2534ba72007-04-25 09:52:20 -04005090 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005091 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005092 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005093 struct lpfc_iocbq *tmp_iocb, *piocb;
5094 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005095
5096 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005097
James Smart2e0fef82007-06-17 19:56:36 -05005098 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005099 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5100 cmd = &piocb->iocb;
5101
5102 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5103 continue;
5104 }
5105
5106 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005107 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5108 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5109 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5110 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005111 continue;
dea31012005-04-17 16:05:31 -05005112
James Smart2e0fef82007-06-17 19:56:36 -05005113 if (piocb->vport != vport)
5114 continue;
5115
James Smart2534ba72007-04-25 09:52:20 -04005116 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005117 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005118 }
5119
5120 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005121 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5122 continue;
5123 }
dea31012005-04-17 16:05:31 -05005124
James Smart2e0fef82007-06-17 19:56:36 -05005125 if (piocb->vport != vport)
5126 continue;
5127
James Smart07951072007-04-25 09:51:38 -04005128 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005129 }
James Smart2e0fef82007-06-17 19:56:36 -05005130 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005131
James Smarta257bf92009-04-06 18:48:10 -04005132 /* Cancell all the IOCBs from the completions list */
5133 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5134 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005135
dea31012005-04-17 16:05:31 -05005136 return;
5137}
5138
James Smarte59058c2008-08-24 21:49:00 -04005139/**
James Smart3621a712009-04-06 18:47:14 -04005140 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005141 * @phba: pointer to lpfc hba data structure.
5142 *
5143 * This routine is used to clean up all the outstanding ELS commands on a
5144 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5145 * routine. After that, it walks the ELS transmit queue to remove all the
5146 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5147 * the IOCBs with the completion callback function associated, the callback
5148 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5149 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5150 * callback function associated, the IOCB will simply be released. Finally,
5151 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5152 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5153 * management plane IOCBs that are not part of the discovery state machine)
5154 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5155 **/
James Smart549e55c2007-08-02 11:09:51 -04005156void
5157lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5158{
5159 LIST_HEAD(completions);
5160 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5161 struct lpfc_iocbq *tmp_iocb, *piocb;
5162 IOCB_t *cmd = NULL;
5163
5164 lpfc_fabric_abort_hba(phba);
5165 spin_lock_irq(&phba->hbalock);
5166 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5167 cmd = &piocb->iocb;
5168 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5169 continue;
5170 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5171 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5172 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5173 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5174 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5175 continue;
5176 list_move_tail(&piocb->list, &completions);
5177 pring->txq_cnt--;
5178 }
5179 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5180 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5181 continue;
5182 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5183 }
5184 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005185
5186 /* Cancel all the IOCBs from the completions list */
5187 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5188 IOERR_SLI_ABORTED);
5189
James Smart549e55c2007-08-02 11:09:51 -04005190 return;
5191}
5192
James Smarte59058c2008-08-24 21:49:00 -04005193/**
James Smart3621a712009-04-06 18:47:14 -04005194 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005195 * @phba: Pointer to hba context object.
5196 * @cmdiocbp: Pointer to command iocb which reported error.
5197 * @rspiocbp: Pointer to response iocb which reported error.
5198 *
5199 * This function sends an event when there is an ELS command
5200 * failure.
5201 **/
5202void
5203lpfc_send_els_failure_event(struct lpfc_hba *phba,
5204 struct lpfc_iocbq *cmdiocbp,
5205 struct lpfc_iocbq *rspiocbp)
5206{
5207 struct lpfc_vport *vport = cmdiocbp->vport;
5208 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5209 struct lpfc_lsrjt_event lsrjt_event;
5210 struct lpfc_fabric_event_header fabric_event;
5211 struct ls_rjt stat;
5212 struct lpfc_nodelist *ndlp;
5213 uint32_t *pcmd;
5214
5215 ndlp = cmdiocbp->context1;
5216 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5217 return;
5218
5219 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5220 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5221 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5222 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5223 sizeof(struct lpfc_name));
5224 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5225 sizeof(struct lpfc_name));
5226 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5227 cmdiocbp->context2)->virt);
5228 lsrjt_event.command = *pcmd;
5229 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5230 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5231 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5232 fc_host_post_vendor_event(shost,
5233 fc_get_event_number(),
5234 sizeof(lsrjt_event),
5235 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005236 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005237 return;
5238 }
5239 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5240 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5241 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5242 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5243 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5244 else
5245 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5246 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5247 sizeof(struct lpfc_name));
5248 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5249 sizeof(struct lpfc_name));
5250 fc_host_post_vendor_event(shost,
5251 fc_get_event_number(),
5252 sizeof(fabric_event),
5253 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005254 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005255 return;
5256 }
5257
5258}
5259
5260/**
James Smart3621a712009-04-06 18:47:14 -04005261 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04005262 * @vport: Pointer to vport object.
5263 * @ndlp: Pointer FC node object.
5264 * @cmd: ELS command code.
5265 *
5266 * This function posts an event when there is an incoming
5267 * unsolicited ELS command.
5268 **/
5269static void
5270lpfc_send_els_event(struct lpfc_vport *vport,
5271 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005272 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005273{
James Smartddcc50f2008-12-04 22:38:46 -05005274 struct lpfc_els_event_header *els_data = NULL;
5275 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005276 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5277
James Smartddcc50f2008-12-04 22:38:46 -05005278 if (*payload == ELS_CMD_LOGO) {
5279 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5280 if (!logo_data) {
5281 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5282 "0148 Failed to allocate memory "
5283 "for LOGO event\n");
5284 return;
5285 }
5286 els_data = &logo_data->header;
5287 } else {
5288 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5289 GFP_KERNEL);
5290 if (!els_data) {
5291 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5292 "0149 Failed to allocate memory "
5293 "for ELS event\n");
5294 return;
5295 }
5296 }
5297 els_data->event_type = FC_REG_ELS_EVENT;
5298 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005299 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005300 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005301 break;
5302 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005303 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005304 break;
5305 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005306 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5307 break;
5308 case ELS_CMD_LOGO:
5309 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5310 /* Copy the WWPN in the LOGO payload */
5311 memcpy(logo_data->logo_wwpn, &payload[2],
5312 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005313 break;
5314 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005315 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005316 return;
5317 }
James Smartddcc50f2008-12-04 22:38:46 -05005318 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5319 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5320 if (*payload == ELS_CMD_LOGO) {
5321 fc_host_post_vendor_event(shost,
5322 fc_get_event_number(),
5323 sizeof(struct lpfc_logo_event),
5324 (char *)logo_data,
5325 LPFC_NL_VENDOR_ID);
5326 kfree(logo_data);
5327 } else {
5328 fc_host_post_vendor_event(shost,
5329 fc_get_event_number(),
5330 sizeof(struct lpfc_els_event_header),
5331 (char *)els_data,
5332 LPFC_NL_VENDOR_ID);
5333 kfree(els_data);
5334 }
James Smartea2151b2008-09-07 11:52:10 -04005335
5336 return;
5337}
5338
5339
5340/**
James Smart3621a712009-04-06 18:47:14 -04005341 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04005342 * @phba: pointer to lpfc hba data structure.
5343 * @pring: pointer to a SLI ring.
5344 * @vport: pointer to a host virtual N_Port data structure.
5345 * @elsiocb: pointer to lpfc els command iocb data structure.
5346 *
5347 * This routine is used for processing the IOCB associated with a unsolicited
5348 * event. It first determines whether there is an existing ndlp that matches
5349 * the DID from the unsolicited IOCB. If not, it will create a new one with
5350 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5351 * IOCB is then used to invoke the proper routine and to set up proper state
5352 * of the discovery state machine.
5353 **/
James Smarted957682007-06-17 19:56:37 -05005354static void
5355lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005356 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005357{
James Smart87af33f2007-10-27 13:37:43 -04005358 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005359 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005360 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005361 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005362 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005363 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005364
James Smarte47c9092008-02-08 18:49:26 -05005365 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005366 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005367
dea31012005-04-17 16:05:31 -05005368 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005369 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5370 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005371 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005372 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005373
James Smart858c9f62007-06-17 19:56:39 -05005374 did = icmd->un.rcvels.remoteID;
5375 if (icmd->ulpStatus) {
5376 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5377 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5378 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005379 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005380 }
dea31012005-04-17 16:05:31 -05005381
5382 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005383 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005384 goto dropit;
dea31012005-04-17 16:05:31 -05005385
James Smart92d7f7b2007-06-17 19:56:38 -05005386 /* Ignore traffic recevied during vport shutdown. */
5387 if (vport->load_flag & FC_UNLOADING)
5388 goto dropit;
5389
James Smart2e0fef82007-06-17 19:56:36 -05005390 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005391 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005392 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005393 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005394 if (!ndlp)
dea31012005-04-17 16:05:31 -05005395 goto dropit;
dea31012005-04-17 16:05:31 -05005396
James Smart2e0fef82007-06-17 19:56:36 -05005397 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005398 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005399 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005400 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005401 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005402 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5403 ndlp = lpfc_enable_node(vport, ndlp,
5404 NLP_STE_UNUSED_NODE);
5405 if (!ndlp)
5406 goto dropit;
5407 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5408 newnode = 1;
5409 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5410 ndlp->nlp_type |= NLP_FABRIC;
5411 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5412 /* This is similar to the new node path */
5413 ndlp = lpfc_nlp_get(ndlp);
5414 if (!ndlp)
5415 goto dropit;
5416 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5417 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005418 }
dea31012005-04-17 16:05:31 -05005419
5420 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005421
James Smart329f9bc2007-04-25 09:53:01 -04005422 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005423 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005424
5425 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5426 cmd &= ELS_CMD_MASK;
5427 }
5428 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005429 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5430 "0112 ELS command x%x received from NPORT x%x "
5431 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005432 switch (cmd) {
5433 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005434 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5435 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5436 did, vport->port_state, ndlp->nlp_flag);
5437
dea31012005-04-17 16:05:31 -05005438 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005439 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5440
James Smartddcc50f2008-12-04 22:38:46 -05005441 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05005442 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05005443 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5444 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5445 rjt_err = LSRJT_UNABLE_TPC;
5446 break;
5447 }
5448 /* We get here, and drop thru, if we are PT2PT with
5449 * another NPort and the other side has initiated
5450 * the PLOGI before responding to our FLOGI.
5451 */
dea31012005-04-17 16:05:31 -05005452 }
James Smart87af33f2007-10-27 13:37:43 -04005453
5454 shost = lpfc_shost_from_vport(vport);
5455 spin_lock_irq(shost->host_lock);
5456 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5457 spin_unlock_irq(shost->host_lock);
5458
James Smart2e0fef82007-06-17 19:56:36 -05005459 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5460 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05005461
dea31012005-04-17 16:05:31 -05005462 break;
5463 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005464 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5465 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5466 did, vport->port_state, ndlp->nlp_flag);
5467
dea31012005-04-17 16:05:31 -05005468 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04005469 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005470 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005471 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005472 break;
5473 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05005474 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5475 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5476 did, vport->port_state, ndlp->nlp_flag);
5477
dea31012005-04-17 16:05:31 -05005478 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05005479 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005480 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005481 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005482 break;
5483 }
James Smart2e0fef82007-06-17 19:56:36 -05005484 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05005485 break;
5486 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05005487 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5488 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5489 did, vport->port_state, ndlp->nlp_flag);
5490
dea31012005-04-17 16:05:31 -05005491 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05005492 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005493 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005494 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005495 break;
5496 }
James Smart2e0fef82007-06-17 19:56:36 -05005497 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05005498 break;
5499 case ELS_CMD_RSCN:
5500 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04005501 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005502 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005503 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005504 break;
5505 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05005506 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5507 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5508 did, vport->port_state, ndlp->nlp_flag);
5509
James Smartddcc50f2008-12-04 22:38:46 -05005510 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05005511 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005512 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005513 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005514 break;
5515 }
James Smart2e0fef82007-06-17 19:56:36 -05005516 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5517 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05005518 break;
5519 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05005520 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5521 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5522 did, vport->port_state, ndlp->nlp_flag);
5523
dea31012005-04-17 16:05:31 -05005524 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005525 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005526 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005527 break;
5528 }
James Smart2e0fef82007-06-17 19:56:36 -05005529 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5530 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05005531 break;
5532 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05005533 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5534 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5535 did, vport->port_state, ndlp->nlp_flag);
5536
dea31012005-04-17 16:05:31 -05005537 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05005538 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005539 break;
5540 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05005541 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5542 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5543 did, vport->port_state, ndlp->nlp_flag);
5544
dea31012005-04-17 16:05:31 -05005545 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05005546 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005547 break;
5548 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05005549 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5550 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5551 did, vport->port_state, ndlp->nlp_flag);
5552
dea31012005-04-17 16:05:31 -05005553 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05005554 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005555 break;
dea31012005-04-17 16:05:31 -05005556 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05005557 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5558 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5559 did, vport->port_state, ndlp->nlp_flag);
5560
dea31012005-04-17 16:05:31 -05005561 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05005562 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005563 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005564 break;
5565 }
James Smart2e0fef82007-06-17 19:56:36 -05005566 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05005567 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005568 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05005569 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5570 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5571 did, vport->port_state, ndlp->nlp_flag);
5572
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005573 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05005574 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005575 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005576 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005577 break;
5578 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05005579 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5580 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5581 did, vport->port_state, ndlp->nlp_flag);
5582
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005583 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05005584 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005585 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005586 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005587 break;
5588 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05005589 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5590 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5591 did, vport->port_state, ndlp->nlp_flag);
5592
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005593 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05005594 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005595 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005596 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005597 break;
dea31012005-04-17 16:05:31 -05005598 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05005599 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5600 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5601 did, vport->port_state, ndlp->nlp_flag);
5602
dea31012005-04-17 16:05:31 -05005603 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05005604 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005605 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005606 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005607 break;
5608 default:
James Smart858c9f62007-06-17 19:56:39 -05005609 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5610 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5611 cmd, did, vport->port_state);
5612
dea31012005-04-17 16:05:31 -05005613 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05005614 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05005615
5616 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005617 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5618 "0115 Unknown ELS command x%x "
5619 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04005620 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005621 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005622 break;
5623 }
5624
5625 /* check if need to LS_RJT received ELS cmd */
5626 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05005627 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05005628 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04005629 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05005630 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5631 NULL);
dea31012005-04-17 16:05:31 -05005632 }
5633
James Smartd7c255b2008-08-24 21:50:00 -04005634 lpfc_nlp_put(elsiocb->context1);
5635 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05005636 return;
5637
5638dropit:
James Smart98c9ea52007-10-27 13:37:33 -04005639 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04005640 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5641 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05005642 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04005643 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05005644 phba->fc_stat.elsRcvDrop++;
5645}
5646
James Smarte59058c2008-08-24 21:49:00 -04005647/**
James Smart3621a712009-04-06 18:47:14 -04005648 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04005649 * @phba: pointer to lpfc hba data structure.
5650 * @vpi: host virtual N_Port identifier.
5651 *
5652 * This routine finds a vport on a HBA (referred by @phba) through a
5653 * @vpi. The function walks the HBA's vport list and returns the address
5654 * of the vport with the matching @vpi.
5655 *
5656 * Return code
5657 * NULL - No vport with the matching @vpi found
5658 * Otherwise - Address to the vport with the matching @vpi.
5659 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005660static struct lpfc_vport *
5661lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5662{
5663 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04005664 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05005665
James Smart549e55c2007-08-02 11:09:51 -04005666 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005667 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04005668 if (vport->vpi == vpi) {
5669 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005670 return vport;
James Smart549e55c2007-08-02 11:09:51 -04005671 }
James Smart92d7f7b2007-06-17 19:56:38 -05005672 }
James Smart549e55c2007-08-02 11:09:51 -04005673 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005674 return NULL;
5675}
James Smarted957682007-06-17 19:56:37 -05005676
James Smarte59058c2008-08-24 21:49:00 -04005677/**
James Smart3621a712009-04-06 18:47:14 -04005678 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04005679 * @phba: pointer to lpfc hba data structure.
5680 * @pring: pointer to a SLI ring.
5681 * @elsiocb: pointer to lpfc els iocb data structure.
5682 *
5683 * This routine is used to process an unsolicited event received from a SLI
5684 * (Service Level Interface) ring. The actual processing of the data buffer
5685 * associated with the unsolicited event is done by invoking the routine
5686 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5687 * SLI ring on which the unsolicited event was received.
5688 **/
James Smarted957682007-06-17 19:56:37 -05005689void
5690lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5691 struct lpfc_iocbq *elsiocb)
5692{
5693 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05005694 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05005695 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05005696 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5697 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05005698
James Smartd7c255b2008-08-24 21:50:00 -04005699 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005700 elsiocb->context2 = NULL;
5701 elsiocb->context3 = NULL;
5702
5703 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5704 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5705 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5706 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05005707 phba->fc_stat.NoRcvBuf++;
5708 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05005709 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04005710 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05005711 return;
5712 }
5713
James Smart92d7f7b2007-06-17 19:56:38 -05005714 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5715 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5716 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5717 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5718 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04005719 else
5720 vport = lpfc_find_vport_by_vpid(phba,
5721 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05005722 }
James Smart7f5f3d02008-02-08 18:50:14 -05005723 /* If there are no BDEs associated
5724 * with this IOCB, there is nothing to do.
5725 */
James Smarted957682007-06-17 19:56:37 -05005726 if (icmd->ulpBdeCount == 0)
5727 return;
5728
James Smart7f5f3d02008-02-08 18:50:14 -05005729 /* type of ELS cmd is first 32bit word
5730 * in packet
5731 */
James Smarted957682007-06-17 19:56:37 -05005732 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05005733 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05005734 } else {
5735 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
5736 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05005737 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
5738 paddr);
James Smarted957682007-06-17 19:56:37 -05005739 }
5740
James Smart92d7f7b2007-06-17 19:56:38 -05005741 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5742 /*
5743 * The different unsolicited event handlers would tell us
5744 * if they are done with "mp" by setting context2 to NULL.
5745 */
dea31012005-04-17 16:05:31 -05005746 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005747 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
5748 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05005749 }
James Smarted957682007-06-17 19:56:37 -05005750
5751 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05005752 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05005753 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005754 elsiocb->context2 = bdeBuf2;
5755 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05005756 /* free mp if we are done with it */
5757 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005758 lpfc_in_buf_free(phba, elsiocb->context2);
5759 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05005760 }
dea31012005-04-17 16:05:31 -05005761 }
dea31012005-04-17 16:05:31 -05005762}
James Smart92d7f7b2007-06-17 19:56:38 -05005763
James Smarte59058c2008-08-24 21:49:00 -04005764/**
James Smart3621a712009-04-06 18:47:14 -04005765 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04005766 * @phba: pointer to lpfc hba data structure.
5767 * @vport: pointer to a virtual N_Port data structure.
5768 *
5769 * This routine issues a Port Login (PLOGI) to the Name Server with
5770 * State Change Request (SCR) for a @vport. This routine will create an
5771 * ndlp for the Name Server associated to the @vport if such node does
5772 * not already exist. The PLOGI to Name Server is issued by invoking the
5773 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5774 * (FDMI) is configured to the @vport, a FDMI node will be created and
5775 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5776 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005777void
5778lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5779{
5780 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
5781
5782 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5783 if (!ndlp) {
5784 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5785 if (!ndlp) {
5786 if (phba->fc_topology == TOPOLOGY_LOOP) {
5787 lpfc_disc_start(vport);
5788 return;
5789 }
5790 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005791 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5792 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005793 return;
5794 }
5795 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005796 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5797 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5798 if (!ndlp) {
5799 if (phba->fc_topology == TOPOLOGY_LOOP) {
5800 lpfc_disc_start(vport);
5801 return;
5802 }
5803 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5804 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5805 "0348 NameServer login: node freed\n");
5806 return;
5807 }
James Smart92d7f7b2007-06-17 19:56:38 -05005808 }
James Smart58da1ff2008-04-07 10:15:56 -04005809 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05005810
5811 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5812
5813 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
5814 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005815 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5816 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005817 return;
5818 }
5819
James Smart3de2a652007-08-02 11:09:59 -04005820 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05005821 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
5822 GFP_KERNEL);
5823 if (ndlp_fdmi) {
5824 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
5825 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005826 lpfc_nlp_set_state(vport, ndlp_fdmi,
5827 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05005828 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
5829 0);
5830 }
5831 }
5832 return;
5833}
5834
James Smarte59058c2008-08-24 21:49:00 -04005835/**
James Smart3621a712009-04-06 18:47:14 -04005836 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04005837 * @phba: pointer to lpfc hba data structure.
5838 * @pmb: pointer to the driver internal queue element for mailbox command.
5839 *
5840 * This routine is the completion callback function to register new vport
5841 * mailbox command. If the new vport mailbox command completes successfully,
5842 * the fabric registration login shall be performed on physical port (the
5843 * new vport created is actually a physical port, with VPI 0) or the port
5844 * login to Name Server for State Change Request (SCR) will be performed
5845 * on virtual port (real virtual port, with VPI greater than 0).
5846 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005847static void
5848lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5849{
5850 struct lpfc_vport *vport = pmb->vport;
5851 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5852 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04005853 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05005854
James Smart09372822008-01-11 01:52:54 -05005855 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005856 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05005857 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005858
5859 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04005860 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5861 "0915 Register VPI failed: 0x%x\n",
5862 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05005863
5864 switch (mb->mbxStatus) {
5865 case 0x11: /* unsupported feature */
5866 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05005867 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05005868 /* giving up on vport registration */
5869 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5870 spin_lock_irq(shost->host_lock);
5871 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5872 spin_unlock_irq(shost->host_lock);
5873 lpfc_can_disctmo(vport);
5874 break;
5875 default:
5876 /* Try to recover from this error */
5877 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05005878 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005879 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05005880 spin_unlock_irq(shost->host_lock);
James Smart7f5f3d02008-02-08 18:50:14 -05005881 if (vport->port_type == LPFC_PHYSICAL_PORT)
5882 lpfc_initial_flogi(vport);
5883 else
5884 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005885 break;
5886 }
5887
5888 } else {
5889 if (vport == phba->pport)
James Smart6fb120a2009-05-22 14:52:59 -04005890 if (phba->sli_rev < LPFC_SLI_REV4)
5891 lpfc_issue_fabric_reglogin(vport);
5892 else
5893 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005894 else
5895 lpfc_do_scr_ns_plogi(phba, vport);
5896 }
James Smartfa4066b2008-01-11 01:53:27 -05005897
5898 /* Now, we decrement the ndlp reference count held for this
5899 * callback function
5900 */
5901 lpfc_nlp_put(ndlp);
5902
James Smart92d7f7b2007-06-17 19:56:38 -05005903 mempool_free(pmb, phba->mbox_mem_pool);
5904 return;
5905}
5906
James Smarte59058c2008-08-24 21:49:00 -04005907/**
James Smart3621a712009-04-06 18:47:14 -04005908 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04005909 * @phba: pointer to lpfc hba data structure.
5910 * @vport: pointer to a host virtual N_Port data structure.
5911 * @ndlp: pointer to a node-list data structure.
5912 *
5913 * This routine registers the @vport as a new virtual port with a HBA.
5914 * It is done through a registering vpi mailbox command.
5915 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01005916static void
James Smart92d7f7b2007-06-17 19:56:38 -05005917lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
5918 struct lpfc_nodelist *ndlp)
5919{
James Smart09372822008-01-11 01:52:54 -05005920 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005921 LPFC_MBOXQ_t *mbox;
5922
5923 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5924 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04005925 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005926 mbox->vport = vport;
5927 mbox->context2 = lpfc_nlp_get(ndlp);
5928 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04005929 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05005930 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05005931 /* mailbox command not success, decrement ndlp
5932 * reference count for this command
5933 */
5934 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005935 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05005936
James Smarte8b62012007-08-02 11:10:09 -04005937 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5938 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05005939 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05005940 }
5941 } else {
James Smarte8b62012007-08-02 11:10:09 -04005942 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5943 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05005944 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05005945 }
James Smartfa4066b2008-01-11 01:53:27 -05005946 return;
5947
5948mbox_err_exit:
5949 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5950 spin_lock_irq(shost->host_lock);
5951 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
5952 spin_unlock_irq(shost->host_lock);
5953 return;
James Smart92d7f7b2007-06-17 19:56:38 -05005954}
5955
James Smarte59058c2008-08-24 21:49:00 -04005956/**
James Smart3621a712009-04-06 18:47:14 -04005957 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04005958 * @phba: pointer to lpfc hba data structure.
5959 * @cmdiocb: pointer to lpfc command iocb data structure.
5960 * @rspiocb: pointer to lpfc response iocb data structure.
5961 *
5962 * This routine is the completion callback function to a Fabric Discover
5963 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
5964 * single threaded, each FDISC completion callback function will reset
5965 * the discovery timer for all vports such that the timers will not get
5966 * unnecessary timeout. The function checks the FDISC IOCB status. If error
5967 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
5968 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
5969 * assigned to the vport has been changed with the completion of the FDISC
5970 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
5971 * are unregistered from the HBA, and then the lpfc_register_new_vport()
5972 * routine is invoked to register new vport with the HBA. Otherwise, the
5973 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
5974 * Server for State Change Request (SCR).
5975 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005976static void
5977lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5978 struct lpfc_iocbq *rspiocb)
5979{
5980 struct lpfc_vport *vport = cmdiocb->vport;
5981 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5982 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
5983 struct lpfc_nodelist *np;
5984 struct lpfc_nodelist *next_np;
5985 IOCB_t *irsp = &rspiocb->iocb;
5986 struct lpfc_iocbq *piocb;
5987
James Smarte8b62012007-08-02 11:10:09 -04005988 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5989 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
5990 irsp->ulpStatus, irsp->un.ulpWord[4],
5991 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05005992 /* Since all FDISCs are being single threaded, we
5993 * must reset the discovery timer for ALL vports
5994 * waiting to send FDISC when one completes.
5995 */
5996 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
5997 lpfc_set_disctmo(piocb->vport);
5998 }
5999
James Smart858c9f62007-06-17 19:56:39 -05006000 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6001 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6002 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6003
James Smart92d7f7b2007-06-17 19:56:38 -05006004 if (irsp->ulpStatus) {
6005 /* Check for retry */
6006 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6007 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006008 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04006009 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04006010 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04006011 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04006012 goto fdisc_failed;
6013 }
James Smart92d7f7b2007-06-17 19:56:38 -05006014 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
6015 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smart92d7f7b2007-06-17 19:56:38 -05006016 lpfc_nlp_put(ndlp);
6017 /* giving up on FDISC. Cancel discovery timer */
6018 lpfc_can_disctmo(vport);
James Smartd7c255b2008-08-24 21:50:00 -04006019 spin_lock_irq(shost->host_lock);
6020 vport->fc_flag |= FC_FABRIC;
6021 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6022 vport->fc_flag |= FC_PUBLIC_LOOP;
6023 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006024
James Smartd7c255b2008-08-24 21:50:00 -04006025 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6026 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6027 if ((vport->fc_prevDID != vport->fc_myDID) &&
6028 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6029 /* If our NportID changed, we need to ensure all
6030 * remaining NPORTs get unreg_login'ed so we can
6031 * issue unreg_vpi.
6032 */
6033 list_for_each_entry_safe(np, next_np,
6034 &vport->fc_nodes, nlp_listp) {
6035 if (!NLP_CHK_NODE_ACT(ndlp) ||
6036 (np->nlp_state != NLP_STE_NPR_NODE) ||
6037 !(np->nlp_flag & NLP_NPR_ADISC))
6038 continue;
James Smart09372822008-01-11 01:52:54 -05006039 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006040 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05006041 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006042 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05006043 }
James Smartd7c255b2008-08-24 21:50:00 -04006044 lpfc_mbx_unreg_vpi(vport);
6045 spin_lock_irq(shost->host_lock);
6046 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6047 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006048 }
6049
James Smartd7c255b2008-08-24 21:50:00 -04006050 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
6051 lpfc_register_new_vport(phba, vport, ndlp);
6052 else
6053 lpfc_do_scr_ns_plogi(phba, vport);
6054 goto out;
6055fdisc_failed:
6056 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6057 /* Cancel discovery timer */
6058 lpfc_can_disctmo(vport);
6059 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006060out:
6061 lpfc_els_free_iocb(phba, cmdiocb);
6062}
6063
James Smarte59058c2008-08-24 21:49:00 -04006064/**
James Smart3621a712009-04-06 18:47:14 -04006065 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006066 * @vport: pointer to a virtual N_Port data structure.
6067 * @ndlp: pointer to a node-list data structure.
6068 * @retry: number of retries to the command IOCB.
6069 *
6070 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6071 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6072 * routine to issue the IOCB, which makes sure only one outstanding fabric
6073 * IOCB will be sent off HBA at any given time.
6074 *
6075 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6076 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6077 * will be stored into the context1 field of the IOCB for the completion
6078 * callback function to the FDISC ELS command.
6079 *
6080 * Return code
6081 * 0 - Successfully issued fdisc iocb command
6082 * 1 - Failed to issue fdisc iocb command
6083 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006084static int
James Smart92d7f7b2007-06-17 19:56:38 -05006085lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6086 uint8_t retry)
6087{
6088 struct lpfc_hba *phba = vport->phba;
6089 IOCB_t *icmd;
6090 struct lpfc_iocbq *elsiocb;
6091 struct serv_parm *sp;
6092 uint8_t *pcmd;
6093 uint16_t cmdsize;
6094 int did = ndlp->nlp_DID;
6095 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006096
6097 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6098 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6099 ELS_CMD_FDISC);
6100 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006101 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006102 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6103 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006104 return 1;
6105 }
6106
6107 icmd = &elsiocb->iocb;
6108 icmd->un.elsreq64.myID = 0;
6109 icmd->un.elsreq64.fl = 1;
6110
James Smartf1126682009-06-10 17:22:44 -04006111 if (phba->sli_rev == LPFC_SLI_REV4) {
6112 /* FDISC needs to be 1 for WQE VPI */
6113 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6114 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6115 /* Set the ulpContext to the vpi */
6116 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6117 } else {
6118 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6119 icmd->ulpCt_h = 1;
6120 icmd->ulpCt_l = 0;
6121 }
James Smart92d7f7b2007-06-17 19:56:38 -05006122
6123 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6124 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6125 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6126 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6127 sp = (struct serv_parm *) pcmd;
6128 /* Setup CSPs accordingly for Fabric */
6129 sp->cmn.e_d_tov = 0;
6130 sp->cmn.w2.r_a_tov = 0;
6131 sp->cls1.classValid = 0;
6132 sp->cls2.seqDelivery = 1;
6133 sp->cls3.seqDelivery = 1;
6134
6135 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6136 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6137 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6138 pcmd += sizeof(uint32_t); /* Port Name */
6139 memcpy(pcmd, &vport->fc_portname, 8);
6140 pcmd += sizeof(uint32_t); /* Node Name */
6141 pcmd += sizeof(uint32_t); /* Node Name */
6142 memcpy(pcmd, &vport->fc_nodename, 8);
6143
6144 lpfc_set_disctmo(vport);
6145
6146 phba->fc_stat.elsXmitFDISC++;
6147 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6148
James Smart858c9f62007-06-17 19:56:39 -05006149 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6150 "Issue FDISC: did:x%x",
6151 did, 0, 0);
6152
James Smart92d7f7b2007-06-17 19:56:38 -05006153 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6154 if (rc == IOCB_ERROR) {
6155 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006156 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006157 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6158 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006159 return 1;
6160 }
6161 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
6162 vport->port_state = LPFC_FDISC;
6163 return 0;
6164}
6165
James Smarte59058c2008-08-24 21:49:00 -04006166/**
James Smart3621a712009-04-06 18:47:14 -04006167 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04006168 * @phba: pointer to lpfc hba data structure.
6169 * @cmdiocb: pointer to lpfc command iocb data structure.
6170 * @rspiocb: pointer to lpfc response iocb data structure.
6171 *
6172 * This routine is the completion callback function to the issuing of a LOGO
6173 * ELS command off a vport. It frees the command IOCB and then decrement the
6174 * reference count held on ndlp for this completion function, indicating that
6175 * the reference to the ndlp is no long needed. Note that the
6176 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6177 * callback function and an additional explicit ndlp reference decrementation
6178 * will trigger the actual release of the ndlp.
6179 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006180static void
6181lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6182 struct lpfc_iocbq *rspiocb)
6183{
6184 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006185 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006186 struct lpfc_nodelist *ndlp;
6187 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006188
6189 irsp = &rspiocb->iocb;
6190 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6191 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6192 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006193
6194 lpfc_els_free_iocb(phba, cmdiocb);
6195 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006196
6197 /* Trigger the release of the ndlp after logo */
6198 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006199}
6200
James Smarte59058c2008-08-24 21:49:00 -04006201/**
James Smart3621a712009-04-06 18:47:14 -04006202 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04006203 * @vport: pointer to a virtual N_Port data structure.
6204 * @ndlp: pointer to a node-list data structure.
6205 *
6206 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6207 *
6208 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6209 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6210 * will be stored into the context1 field of the IOCB for the completion
6211 * callback function to the LOGO ELS command.
6212 *
6213 * Return codes
6214 * 0 - Successfully issued logo off the @vport
6215 * 1 - Failed to issue logo off the @vport
6216 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006217int
6218lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6219{
6220 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6221 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006222 IOCB_t *icmd;
6223 struct lpfc_iocbq *elsiocb;
6224 uint8_t *pcmd;
6225 uint16_t cmdsize;
6226
6227 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6228 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6229 ELS_CMD_LOGO);
6230 if (!elsiocb)
6231 return 1;
6232
6233 icmd = &elsiocb->iocb;
6234 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6235 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6236 pcmd += sizeof(uint32_t);
6237
6238 /* Fill in LOGO payload */
6239 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6240 pcmd += sizeof(uint32_t);
6241 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6242
James Smart858c9f62007-06-17 19:56:39 -05006243 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6244 "Issue LOGO npiv did:x%x flg:x%x",
6245 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6246
James Smart92d7f7b2007-06-17 19:56:38 -05006247 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6248 spin_lock_irq(shost->host_lock);
6249 ndlp->nlp_flag |= NLP_LOGO_SND;
6250 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04006251 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6252 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05006253 spin_lock_irq(shost->host_lock);
6254 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6255 spin_unlock_irq(shost->host_lock);
6256 lpfc_els_free_iocb(phba, elsiocb);
6257 return 1;
6258 }
6259 return 0;
6260}
6261
James Smarte59058c2008-08-24 21:49:00 -04006262/**
James Smart3621a712009-04-06 18:47:14 -04006263 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04006264 * @ptr: holder for the timer function associated data.
6265 *
6266 * This routine is invoked by the fabric iocb block timer after
6267 * timeout. It posts the fabric iocb block timeout event by setting the
6268 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6269 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6270 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6271 * posted event WORKER_FABRIC_BLOCK_TMO.
6272 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006273void
6274lpfc_fabric_block_timeout(unsigned long ptr)
6275{
6276 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6277 unsigned long iflags;
6278 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04006279
James Smart92d7f7b2007-06-17 19:56:38 -05006280 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6281 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6282 if (!tmo_posted)
6283 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6284 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6285
James Smart5e9d9b82008-06-14 22:52:53 -04006286 if (!tmo_posted)
6287 lpfc_worker_wake_up(phba);
6288 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006289}
6290
James Smarte59058c2008-08-24 21:49:00 -04006291/**
James Smart3621a712009-04-06 18:47:14 -04006292 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04006293 * @phba: pointer to lpfc hba data structure.
6294 *
6295 * This routine issues one fabric iocb from the driver internal list to
6296 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6297 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6298 * remove one pending fabric iocb from the driver internal list and invokes
6299 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6300 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006301static void
6302lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6303{
6304 struct lpfc_iocbq *iocb;
6305 unsigned long iflags;
6306 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05006307 IOCB_t *cmd;
6308
6309repeat:
6310 iocb = NULL;
6311 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05006312 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05006313 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6314 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6315 list);
6316 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05006317 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05006318 atomic_inc(&phba->fabric_iocb_count);
6319 }
6320 spin_unlock_irqrestore(&phba->hbalock, iflags);
6321 if (iocb) {
6322 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6323 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6324 iocb->iocb_flag |= LPFC_IO_FABRIC;
6325
James Smart858c9f62007-06-17 19:56:39 -05006326 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6327 "Fabric sched1: ste:x%x",
6328 iocb->vport->port_state, 0, 0);
6329
James Smart3772a992009-05-22 14:50:54 -04006330 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006331
6332 if (ret == IOCB_ERROR) {
6333 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6334 iocb->fabric_iocb_cmpl = NULL;
6335 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6336 cmd = &iocb->iocb;
6337 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6338 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6339 iocb->iocb_cmpl(phba, iocb, iocb);
6340
6341 atomic_dec(&phba->fabric_iocb_count);
6342 goto repeat;
6343 }
6344 }
6345
6346 return;
6347}
6348
James Smarte59058c2008-08-24 21:49:00 -04006349/**
James Smart3621a712009-04-06 18:47:14 -04006350 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006351 * @phba: pointer to lpfc hba data structure.
6352 *
6353 * This routine unblocks the issuing fabric iocb command. The function
6354 * will clear the fabric iocb block bit and then invoke the routine
6355 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6356 * from the driver internal fabric iocb list.
6357 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006358void
6359lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6360{
6361 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6362
6363 lpfc_resume_fabric_iocbs(phba);
6364 return;
6365}
6366
James Smarte59058c2008-08-24 21:49:00 -04006367/**
James Smart3621a712009-04-06 18:47:14 -04006368 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006369 * @phba: pointer to lpfc hba data structure.
6370 *
6371 * This routine blocks the issuing fabric iocb for a specified amount of
6372 * time (currently 100 ms). This is done by set the fabric iocb block bit
6373 * and set up a timeout timer for 100ms. When the block bit is set, no more
6374 * fabric iocb will be issued out of the HBA.
6375 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006376static void
6377lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6378{
6379 int blocked;
6380
6381 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05006382 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05006383 if (!blocked)
6384 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6385
6386 return;
6387}
6388
James Smarte59058c2008-08-24 21:49:00 -04006389/**
James Smart3621a712009-04-06 18:47:14 -04006390 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04006391 * @phba: pointer to lpfc hba data structure.
6392 * @cmdiocb: pointer to lpfc command iocb data structure.
6393 * @rspiocb: pointer to lpfc response iocb data structure.
6394 *
6395 * This routine is the callback function that is put to the fabric iocb's
6396 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6397 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6398 * function first restores and invokes the original iocb's callback function
6399 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6400 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6401 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006402static void
6403lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6404 struct lpfc_iocbq *rspiocb)
6405{
6406 struct ls_rjt stat;
6407
6408 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6409 BUG();
6410
6411 switch (rspiocb->iocb.ulpStatus) {
6412 case IOSTAT_NPORT_RJT:
6413 case IOSTAT_FABRIC_RJT:
6414 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6415 lpfc_block_fabric_iocbs(phba);
6416 }
6417 break;
6418
6419 case IOSTAT_NPORT_BSY:
6420 case IOSTAT_FABRIC_BSY:
6421 lpfc_block_fabric_iocbs(phba);
6422 break;
6423
6424 case IOSTAT_LS_RJT:
6425 stat.un.lsRjtError =
6426 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6427 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6428 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6429 lpfc_block_fabric_iocbs(phba);
6430 break;
6431 }
6432
6433 if (atomic_read(&phba->fabric_iocb_count) == 0)
6434 BUG();
6435
6436 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6437 cmdiocb->fabric_iocb_cmpl = NULL;
6438 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6439 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6440
6441 atomic_dec(&phba->fabric_iocb_count);
6442 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05006443 /* Post any pending iocbs to HBA */
6444 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05006445 }
6446}
6447
James Smarte59058c2008-08-24 21:49:00 -04006448/**
James Smart3621a712009-04-06 18:47:14 -04006449 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006450 * @phba: pointer to lpfc hba data structure.
6451 * @iocb: pointer to lpfc command iocb data structure.
6452 *
6453 * This routine is used as the top-level API for issuing a fabric iocb command
6454 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6455 * function makes sure that only one fabric bound iocb will be outstanding at
6456 * any given time. As such, this function will first check to see whether there
6457 * is already an outstanding fabric iocb on the wire. If so, it will put the
6458 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6459 * issued later. Otherwise, it will issue the iocb on the wire and update the
6460 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6461 *
6462 * Note, this implementation has a potential sending out fabric IOCBs out of
6463 * order. The problem is caused by the construction of the "ready" boolen does
6464 * not include the condition that the internal fabric IOCB list is empty. As
6465 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6466 * ahead of the fabric IOCBs in the internal list.
6467 *
6468 * Return code
6469 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6470 * IOCB_ERROR - failed to issue fabric iocb
6471 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006472static int
James Smart92d7f7b2007-06-17 19:56:38 -05006473lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6474{
6475 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05006476 int ready;
6477 int ret;
6478
6479 if (atomic_read(&phba->fabric_iocb_count) > 1)
6480 BUG();
6481
6482 spin_lock_irqsave(&phba->hbalock, iflags);
6483 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6484 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6485
James Smart7f5f3d02008-02-08 18:50:14 -05006486 if (ready)
6487 /* Increment fabric iocb count to hold the position */
6488 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05006489 spin_unlock_irqrestore(&phba->hbalock, iflags);
6490 if (ready) {
6491 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6492 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6493 iocb->iocb_flag |= LPFC_IO_FABRIC;
6494
James Smart858c9f62007-06-17 19:56:39 -05006495 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6496 "Fabric sched2: ste:x%x",
6497 iocb->vport->port_state, 0, 0);
6498
James Smart3772a992009-05-22 14:50:54 -04006499 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006500
6501 if (ret == IOCB_ERROR) {
6502 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6503 iocb->fabric_iocb_cmpl = NULL;
6504 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6505 atomic_dec(&phba->fabric_iocb_count);
6506 }
6507 } else {
6508 spin_lock_irqsave(&phba->hbalock, iflags);
6509 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6510 spin_unlock_irqrestore(&phba->hbalock, iflags);
6511 ret = IOCB_SUCCESS;
6512 }
6513 return ret;
6514}
6515
James Smarte59058c2008-08-24 21:49:00 -04006516/**
James Smart3621a712009-04-06 18:47:14 -04006517 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006518 * @vport: pointer to a virtual N_Port data structure.
6519 *
6520 * This routine aborts all the IOCBs associated with a @vport from the
6521 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6522 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6523 * list, removes each IOCB associated with the @vport off the list, set the
6524 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6525 * associated with the IOCB.
6526 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006527static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05006528{
6529 LIST_HEAD(completions);
6530 struct lpfc_hba *phba = vport->phba;
6531 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05006532
6533 spin_lock_irq(&phba->hbalock);
6534 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6535 list) {
6536
6537 if (piocb->vport != vport)
6538 continue;
6539
6540 list_move_tail(&piocb->list, &completions);
6541 }
6542 spin_unlock_irq(&phba->hbalock);
6543
James Smarta257bf92009-04-06 18:48:10 -04006544 /* Cancel all the IOCBs from the completions list */
6545 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6546 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006547}
6548
James Smarte59058c2008-08-24 21:49:00 -04006549/**
James Smart3621a712009-04-06 18:47:14 -04006550 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006551 * @ndlp: pointer to a node-list data structure.
6552 *
6553 * This routine aborts all the IOCBs associated with an @ndlp from the
6554 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6555 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6556 * list, removes each IOCB associated with the @ndlp off the list, set the
6557 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6558 * associated with the IOCB.
6559 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006560void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6561{
6562 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04006563 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006564 struct lpfc_iocbq *tmp_iocb, *piocb;
6565 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05006566
6567 spin_lock_irq(&phba->hbalock);
6568 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6569 list) {
6570 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6571
6572 list_move_tail(&piocb->list, &completions);
6573 }
6574 }
6575 spin_unlock_irq(&phba->hbalock);
6576
James Smarta257bf92009-04-06 18:48:10 -04006577 /* Cancel all the IOCBs from the completions list */
6578 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6579 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006580}
6581
James Smarte59058c2008-08-24 21:49:00 -04006582/**
James Smart3621a712009-04-06 18:47:14 -04006583 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006584 * @phba: pointer to lpfc hba data structure.
6585 *
6586 * This routine aborts all the IOCBs currently on the driver internal
6587 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6588 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6589 * list, removes IOCBs off the list, set the status feild to
6590 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6591 * the IOCB.
6592 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006593void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
6594{
6595 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05006596
6597 spin_lock_irq(&phba->hbalock);
6598 list_splice_init(&phba->fabric_iocb_list, &completions);
6599 spin_unlock_irq(&phba->hbalock);
6600
James Smarta257bf92009-04-06 18:48:10 -04006601 /* Cancel all the IOCBs from the completions list */
6602 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6603 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006604}
James Smart6fb120a2009-05-22 14:52:59 -04006605
6606/**
6607 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
6608 * @phba: pointer to lpfc hba data structure.
6609 * @axri: pointer to the els xri abort wcqe structure.
6610 *
6611 * This routine is invoked by the worker thread to process a SLI4 slow-path
6612 * ELS aborted xri.
6613 **/
6614void
6615lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
6616 struct sli4_wcqe_xri_aborted *axri)
6617{
6618 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
6619 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6620 unsigned long iflag = 0;
6621
6622 spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, iflag);
6623 list_for_each_entry_safe(sglq_entry, sglq_next,
6624 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
6625 if (sglq_entry->sli4_xritag == xri) {
6626 list_del(&sglq_entry->list);
6627 spin_unlock_irqrestore(
6628 &phba->sli4_hba.abts_sgl_list_lock,
6629 iflag);
6630 spin_lock_irqsave(&phba->hbalock, iflag);
6631
6632 list_add_tail(&sglq_entry->list,
6633 &phba->sli4_hba.lpfc_sgl_list);
6634 spin_unlock_irqrestore(&phba->hbalock, iflag);
6635 return;
6636 }
6637 }
6638 spin_unlock_irqrestore(&phba->sli4_hba.abts_sgl_list_lock, iflag);
6639}